How to use the antlr4.InputStream 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 mongodb-js / bson-transpilers / test / ECMAScriptTransformer.spec.js View on Github external
const generate = function(input) {
    const chars = new antlr4.InputStream(input);
    const lexer = new ECMAScriptLexer.ECMAScriptLexer(chars);
    const tokens = new antlr4.CommonTokenStream(lexer);
    const parser = new ECMAScriptParser.ECMAScriptParser(tokens);
    parser.buildParseTrees = true;

    const tree = parser.expressionSequence();
    const transformer = new ECMAScriptTransformer();
    transformer.visitExpressionSequence(tree);

    // Print
    const listener = new PrintListener();
    return listener.buildAST(tree, parser.ruleNames);
  };
github mongodb-js / bson-transpilers / index.js View on Github external
const loadJSTree = (input, start) => {
  const chars = new antlr4.InputStream(input);
  const lexer = new ECMAScriptLexer.ECMAScriptLexer(chars);
  lexer.strictMode = false;

  const tokens = new antlr4.CommonTokenStream(lexer);
  const parser = new ECMAScriptParser.ECMAScriptParser(tokens);
  parser.buildParseTrees = true;

  const listener = new ErrorListener();
  parser.removeErrorListeners(); // Remove the default ConsoleErrorListener
  parser.addErrorListener(listener); // Add back a custom error listener

  return parser[start]();
};
github anz-bank / sysl / unsorted / sysl_js / index.js View on Github external
function parse(input, listener) {
    var chars = new antlr4.InputStream(input);
    var lexer = new SyslLexer.SyslLexer(chars);
    var tokens  = new antlr4.CommonTokenStream(lexer);
    var parser = new SyslParser(tokens);

    parser._interp.predictionMode = 0; // SLL = 0
    parser.removeErrorListeners();
    parser.buildParseTrees = true;
    parser.addErrorListener(listener);
    return parser.sysl_file();
}
github hyperledger-labs / weaver-dlt-interoperability / common / policy-dsl / index.js View on Github external
/*
 * Copyright IBM Corp. All Rights Reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

import antlr4 from 'antlr4';
import PolicyLexer from "./parser/PolicyLexer.js"
import PolicyParser from "./parser/PolicyParser.js"

var input = 'org1 && org2'
var chars = new antlr4.InputStream(input);
var lexer = new PolicyLexer(chars);
var tokens  = new antlr4.CommonTokenStream(lexer);
tokens.fill()
tokens.tokens.forEach(tok => {
    console.log(tok.text);
})
github protofire / solhint / lib / index.js View on Github external
function processStr(inputStr, config = {}, fileName = '') {
  const chars = new antlr4.InputStream(inputStr)
  const lexer = new SolidityLexer(chars)
  const tokens = new antlr4.CommonTokenStream(lexer)
  const parser = new SolidityParser(tokens)
  parser.buildParseTrees = true

  const tree = parser.sourceUnit()
  const reporter = new Reporter(tokens, config)

  const listener = new TreeListener(checkers(reporter, config, inputStr, fileName))
  antlr4.tree.ParseTreeWalker.DEFAULT.walk(listener, tree)

  return reporter
}
github neo4j-contrib / cypher-editor / cypher-editor-support / src / util / parse.js View on Github external
export const parse = (input) => {
  const referencesListener = new ReferencesListener();
  const errorListener = new ErrorListener();
  const chars = new antlr4.InputStream(input);
  const lexer = new CypherLexer(chars);
  lexer.removeErrorListeners();
  lexer.addErrorListener(errorListener);
  const tokens = new antlr4.CommonTokenStream(lexer);
  const parser = new CypherParser(tokens);
  parser.buildParseTrees = true;
  parser.removeErrorListeners();
  parser.addErrorListener(errorListener);
  parser.addParseListener(referencesListener);
  const parseTree = parser.cypher();
  const { queries, indexes } = referencesListener;

  const referencesProviders = CypherTypes.SYMBOLIC_CONTEXTS.reduce(
    (acc, t) => ({
      ...acc,
      [t]: new ReferencesProvider(queries, indexes[t]),
github daud-io / daud / Game.Engine / wwwroot / src / parser / parseTheme.js View on Github external
function parseCssIntoRules(css) {
    const chars = new antlr4.InputStream(css);
    const lexer = new ScssLexer(chars);
    const tokens = new antlr4.CommonTokenStream(lexer);
    const parser = new ScssParser(tokens);
    const tree = parser.stylesheet();

    const ruleList = [];
    function addRulesFromStatement(statement, rules) {
        const selectors = statement.ruleset().selectors();
        const block = statement.ruleset().block();

        const blockProps = block.property().map((x, i) => {
            return [
                block.property(i).identifier().getText(),
                block
                    .property(i)
                    .values()
github solidity-ide / antlr-parser / src / SolidityParser.ts View on Github external
        code.forEach(c => this.parseStream(new antlr4.InputStream(c, true)));
    }