How to use the antlr4ts.ANTLRInputStream 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 microsoft / botbuilder-js / libraries / botframework-expressions / src / commonRegex.ts View on Github external
private static antlrParse(pattern: string): ParseTree {
        const inputStream: ANTLRInputStream = new ANTLRInputStream(pattern);
        const lexer: CommonRegexLexer = new CommonRegexLexer(inputStream);
        const tokenStream: CommonTokenStream = new CommonTokenStream(lexer);
        const parser: CommonRegexParser = new CommonRegexParser(tokenStream);
        parser.removeErrorListeners();
        // tslint:disable-next-line: no-use-before-declare
        parser.addErrorListener(ErrorListener.Instance);
        parser.buildParseTree = true;

        return parser.parse();
    }
}
github zenclabs / codetree / src / antlr.ts View on Github external
export function parse(
  lexerConstructor: new (inputStream: antlr.ANTLRInputStream) => L,
  parserConstructor: new (tokenStream: antlr.TokenStream) => P,
  rootNode: (parser: P) => antlr.ParserRuleContext,
  code: string
): Node {
  let inputStream = new antlr.ANTLRInputStream(code);
  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);
github yifanwu / diel / src / compiler / compiler.ts View on Github external
export function ParsePlainSelectQueryAst(code: string) {
  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.selectQuery();
  let visitor = new Visitor();
  let ast = visitor.visit(tree) as RelationSelection;
  return ast;
}
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 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 / compiler.ts View on Github external
export function getVanillaSelectionUnitAst(code: string) {
  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.selectUnitQuery();
  let visitor = new Visitor();
  let selectionUnitAst = visitor.visitSelectUnitQuery(tree);
  return selectionUnitAst;
}
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 yifanwu / diel / code / src / compiler / compiler.ts View on Github external
export function parse(code: string) {
  const inputStream = new ANTLRInputStream(code);
  const l = new lexer.DIELLexer(inputStream);
  const tokenStream = new CommonTokenStream(l);
  return new parser.DIELParser(tokenStream);
}