How to use the antlr4ts.CommonTokenStream function in antlr4ts

To help you get started, we’ve selected a few antlr4ts 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 zenclabs / codetree / src / antlr.ts View on Github external
let lexer = new lexerConstructor(inputStream);
  lexer.removeErrorListeners();
  lexer.addErrorListener({
    syntaxError(
      // tslint:disable-next-line no-any
      recognizer: antlr.Recognizer,
      offendingSymbol: number | undefined,
      line: number,
      charPositionInLine: number,
      msg: string,
      e: antlr.RecognitionException | undefined
    ) {
      throw new Error(msg + " at " + line + ":" + charPositionInLine);
    }
  });
  let tokenStream = new antlr.CommonTokenStream(lexer);
  let parser = new parserConstructor(tokenStream);
  parser.removeErrorListeners();
  parser.addErrorListener({
    syntaxError(
      // tslint:disable-next-line no-any
      recognizer: antlr.Recognizer,
      offendingSymbol: antlr.Token | undefined,
      line: number,
      charPositionInLine: number,
      msg: string,
      e: antlr.RecognitionException | undefined
    ) {
      throw new Error(msg + " at " + line + ":" + charPositionInLine);
    }
  });
  let node = rootNode(parser);
github eirikpre / VSCode-SystemVerilog / src / compiling / ANTLRBackend.ts View on Github external
if (!isSystemVerilogDocument(document) && !isVerilogDocument(document)) {
                reject("The document is not a SystemVerilog/Verilog file.");
                return;
            }

            let visitedDocuments = new Map();
            let diagnosticCollection: Map = new Map();

            // Get document text
            let text = document.getText();
            // Perform macro replacements
            let new_text = this.macroReplace(text);
            // Create the lexer and parser
            let inputStream = new ANTLRInputStream(new_text);   
            let lexer = new SystemVerilogLexer(inputStream);
            let tokenStream = new CommonTokenStream(lexer);
            let parser = new SystemVerilogParser(tokenStream);

            //Use syntaxError to collect a list of errors found by the parser
            let syntaxError = new SyntaxErrorListener();
            parser.addErrorListener(syntaxError);

            // Parse the input
            let tree = parser.system_verilog_text();

            //place errors in the diagnostic list
            let diagnosticList = new Array();
            for (let i = 0; i < syntaxError.error_list.length; i++) {
                let range: Range = getLineRange(
                    syntaxError.error_list[i].line, 
                    syntaxError.error_list[i].offendingSymbol.text, 
                    syntaxError.error_list[i].charPositionInLine);
github eirikpre / VSCode-SystemVerilog / src / compiling / ANTLRCompiler.ts View on Github external
if (!isSystemVerilogDocument(document) && !isVerilogDocument(document)) {
                reject("The document is not a SystemVerilog/Verilog file.");
                return;
            }

            let visitedDocuments = new Map();
            let diagnosticCollection: Map = new Map();

            // Get document text
            let text = document.getText();
            // Perform macro replacements
            let new_text = this.macroReplace(text);
            // Create the lexer and parser
            let inputStream = new ANTLRInputStream(new_text);
            let lexer = new SystemVerilogLexer(inputStream);
            let tokenStream = new CommonTokenStream(lexer);
            let parser = new SystemVerilogParser(tokenStream);

            let syntaxError = new SyntaxErrorListener();
            parser.addErrorListener(syntaxError);

            // Parse the input, where `compilationUnit` is whatever entry point you defined
            let tree = parser.system_verilog_text();

            for (let i = 0; i < syntaxError.error_list.length; i++) {
                let diagnosticData: DiagnosticData = new DiagnosticData();

                diagnosticData.filePath = document.uri;
                diagnosticData.line = syntaxError.error_list[i].line;
                diagnosticData.diagnosticSeverity = DiagnosticSeverity.Error;
                diagnosticData.problem = this.getImprovedMessage(syntaxError.error_list[i],document.uri);
                diagnosticData.offendingSymbol = syntaxError.error_list[i].offendingSymbol.text;
github yifanwu / diel / src / compiler / compiler.ts View on Github external
export function ParsePlainDielAst(code: string) {
  // PrintCode(code);
  const inputStream = new ANTLRInputStream(code);
  const l = new lexer.DIELLexer(inputStream);
  const tokenStream = new CommonTokenStream(l);
  const p = new parser.DIELParser(tokenStream);
  const tree = p.queries();
  let visitor = new Visitor();
  let ast = visitor.visitQueries(tree);
  return ast;
}
github tsouza / yajs / src / main / lib / path / YAJSPath.ts View on Github external
export function parse(path: string): YAJSPath {

        const inputStream = new ANTLRInputStream(path);
        const lexer = new YAJSLexer(inputStream);
        const tokenStream = new CommonTokenStream(lexer);
        const parser = new YAJSParser(tokenStream);

        return new Visitor().
            visit(parser.path()).
            build();
    }
github mr-doc / mr-doc / src / tom / index.ts View on Github external
constructor(source: string) {
    this.parser = new Parser.TomParser(new CommonTokenStream(
      new Lexer.TomLexer(
        new ANTLRInputStream(source)
      )
    ));
  }
  parse() {
github yifanwu / diel / code / src / compiler / codegen / codeGenSql.ts View on Github external
function _parse(query: string) {
  const inputStream = new ANTLRInputStream(query);
  const l = new lexer.DIELLexer(inputStream);
  const tokenStream = new CommonTokenStream(l);
  return new parser.DIELParser(tokenStream);
}
github microsoft / botbuilder-js / libraries / botframework-expressions / src / parser / expressionEngine.ts View on Github external
protected static antlrParse(expression: string): ParseTree {
        const inputStream: ANTLRInputStream = new ANTLRInputStream(expression);
        const lexer: ExpressionLexer = new ExpressionLexer(inputStream);
        const tokenStream: CommonTokenStream = new CommonTokenStream(lexer);
        const parser: ExpressionParser = new ExpressionParser(tokenStream);
        parser.removeErrorListeners();
        parser.addErrorListener(ParseErrorListener.Instance);
        parser.buildParseTree = true;

        const file: ep.FileContext = parser.file();
        if (file !== undefined) {
            return file.expression();
        }

        return undefined;
    }
github yifanwu / diel / src / compiler / passes / generateViewConstraints.ts View on Github external
function checkValidView(query: string): DielAst {
  const inputStream = new ANTLRInputStream(query);
  const l = new lexer.DIELLexer(inputStream);
  const tokenStream = new CommonTokenStream(l);
  const p = new parser.DIELParser(tokenStream);
  const tree = p.queries();
  let visitor = new Visitor();
  let ast = visitor.visitQueries(tree);
  if (ast.relations.length > 0) {
    return ast;
  }
  return null;
}
github mr-doc / mr-doc / src / tom / index.js View on Github external
constructor(source) {
        this.parser = new Parser.TomParser(new antlr4ts_1.CommonTokenStream(new Lexer.TomLexer(new antlr4ts_1.ANTLRInputStream(source))));
    }
    parse() {