How to use the antlr4/index.CommonTokenStream function in antlr4

To help you get started, we’ve selected a few antlr4 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Talend / daikon / daikon-tql / daikon-tql-core / src / main / resources / tql / index.js View on Github external
var parse = function(
    tql,
    onExactFilter,
    onContainsFilter,
    onContainsIgnoreCaseFilter,
    onCompliesFilter,
    onBetweenFilter,
    onEmptyFilter,
    onValidFilter,
    onInvalidFilter,
    onWordCompliesFilter
) {
    var chars = new antlr4.InputStream(tql);
    var lexer = new TqlLexer(chars);
    var tokens = new antlr4.CommonTokenStream(lexer);
    var listener = new TqlListener();
    var parser = new TqlParser(tokens);
    var noop = function() {};

    parser.buildParseTrees = true;

    // Define listeners
    listener.enterFieldIsEmpty = onEmptyFilter || noop;
    listener.enterFieldIsValid = onValidFilter || noop;
    listener.enterFieldIsInvalid = onInvalidFilter || noop;
    listener.enterFieldContains = onContainsFilter || noop;
    listener.enterFieldContainsIgnoreCase = onContainsIgnoreCaseFilter || noop;
    listener.enterFieldCompliesPattern = onCompliesFilter || noop;
    listener.enterFieldWordCompliesPattern = onWordCompliesFilter || noop;
    listener.enterFieldBetween = onBetweenFilter || noop;
    listener.enterLiteralComparison = function(ctx) {
github coveooss / vsforce / src / symbols / apexObjectTreeCache.ts View on Github external
private handleParseFile(err: NodeJS.ErrnoException, data: string) {
    var chars = new antlr4.InputStream(data);
    var lexer = new ApexLexer(chars);
    var tokens = new antlr4.CommonTokenStream(lexer);
    var parser = new ApexParser(tokens);
    parser.buildParseTrees = true;
    parser.removeErrorListeners();
    parser.addErrorListener(this);
    var tree = parser.compilationUnit();
    this.file = data;
    this.parseNode(tree);
    this.ds.set(this.uri, this.diag);
  }
github KvanTTT / DAGE / AntlrGrammarEditor / AntlrRuntimes / JavaScript / main.js View on Github external
var fs = require("fs");
var antlr4 = require('antlr4/index');
var __TemplateGrammarName__Lexer = require('./__TemplateGrammarName__Lexer').__TemplateGrammarName__Lexer;
/*$ParserInclude*/var __TemplateGrammarName__Parser = require('./__TemplateGrammarName__Parser').__TemplateGrammarName__Parser;/*ParserInclude$*/
/*AntlrCaseInsensitive*/

var fileName = "../../Text"

if (process.argv.length >= 2) {
    fileName = process.argv[2];
}

var input = fs.readFileSync(fileName).toString();
var chars = new antlr4.InputStream(input);
var lexer = new __TemplateGrammarName__Lexer(chars);
var tokensStream = new antlr4.CommonTokenStream(lexer);

/*$ParserPart*/
var rootRule;
if (process.argv.length >= 3) {
    rootRule = process.argv[3];
}
var parser = new __TemplateGrammarName__Parser(tokensStream);
var ruleName = rootRule === undefined ? parser.ruleNames[0] : rootRule;
var ast = parser[ruleName]();
console.log("Tree " + ast.toStringTree(null, parser));
/*ParserPart$*/
github quantastica / quantum-circuit / lib / qasm_import / QASMImport.js View on Github external
var QASMImport = function(circuit, input, errorCallback) {
	var chars = new antlr4.InputStream(input);
	var lexer = new QASMLexer.QASMLexer(chars);
	var tokens  = new antlr4.CommonTokenStream(lexer);
	var parser = new QASMParser.QASMParser(tokens);
	parser.buildParseTrees = true;

	parser.removeErrorListeners();
	var errors = [];
	var errorListener = new ErrorListener(errors);
	parser.addErrorListener(errorListener);

	var tree = parser.mainprog();   
	var QASM = new QCQASMListener(circuit);
	antlr4.tree.ParseTreeWalker.DEFAULT.walk(QASM, tree);
	if(errorCallback) {
		errorCallback(errors);
	}
};
github nextbreakpoint / nextfractal / com.nextbreakpoint.nextfractal.verticle / web / Mandelbrot.js View on Github external
Mandelbrot.prototype.parse = function(script) {
    var inputStream = new antlr4.InputStream(script)
    var lexer = new MandelbrotLexer(inputStream)
    var tokenStream = new antlr4.CommonTokenStream(lexer)
    var parser = new MandelbrotParser(tokenStream)
    var fractal = parser.fractal()
    return fractal
};