How to use the antlr4.tree 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 Thomaash / me / src / importScript / index.js View on Github external
} catch (error) {
        Object.assign(error, { varName, funcName, args, code })
        console.warn(error)
        log.push({
          severity: 'warning',
          msg: `Can't process function call: “${code}”.`
        })
      }
    }
  })

  // Process the tree
  const tree = parse(input)
  const walker = new antlr4.tree.ParseTreeWalker()
  walker.walk(printer, tree)
  antlr4.tree.ParseTreeWalker.DEFAULT.walk(printer, tree)

  // Prepare ports without IPs
  const hostDevs = new Set()
  links.forEach(link => hostDevs.add(link.from).add(link.to))
  links.forEach(edge => {
    edge.from = fixNextHostDev(hostDevs, edge.from)
    edge.to = fixNextHostDev(hostDevs, edge.to)
  })
  links.forEach(edge => {
    ;[edge.from, edge.to].forEach(hostDev => {
      const [nodename, portname] = hostDev.split('-')

      ips.$push(nodename, portname, hostIPs[nodename] || [])
      delete hostIPs[nodename]
    })
  })
github wix / quix / quix-frontend / client / src / lib / language-parsers / presto-grammar / lang / presto / SqlBaseListener.js View on Github external
// Generated from ./lang/presto/SqlBase.g4 by ANTLR 4.7
// jshint ignore: start
var antlr4 = require('antlr4');

// This class defines a complete listener for a parse tree produced by SqlBaseParser.
function SqlBaseListener() {
	antlr4.tree.ParseTreeListener.call(this);
	return this;
}

SqlBaseListener.prototype = Object.create(antlr4.tree.ParseTreeListener.prototype);
SqlBaseListener.prototype.constructor = SqlBaseListener;

// Enter a parse tree produced by SqlBaseParser#multiStatement.
SqlBaseListener.prototype.enterMultiStatement = function(ctx) {
};

// Exit a parse tree produced by SqlBaseParser#multiStatement.
SqlBaseListener.prototype.exitMultiStatement = function(ctx) {
};


// Enter a parse tree produced by SqlBaseParser#singleStatement.
SqlBaseListener.prototype.enterSingleStatement = function(ctx) {
};

// Exit a parse tree produced by SqlBaseParser#singleStatement.
github kitspace / electro-grammar / js / lib / index.js View on Github external
const tokens = new antlr4.CommonTokenStream(lexer);
    const parser = new ElectroGrammarParser(tokens);

    // enable grammar ambiguity diagnostic output
    // see Antlr book ch 9.2, page 156
    // https://github.com/antlr/antlr4/issues/2206
    parser.removeErrorListeners();
    parser.addErrorListener(new antlr4.error.DiagnosticErrorListener());
    parser._interp.PredictionMode =
      antlr4.atn.PredictionMode.LL_EXACT_AMBIG_DETECTION;

    parser.buildParseTrees = true;

    const tree = parser[start_rule]();
    const listener = new ElectroGrammarToObjectListener();
    const walker = antlr4.tree.ParseTreeWalker.DEFAULT.walk(listener, tree);
    return listener.obj;
  }
  return parse;
github wix / quix / quix-frontend / client / src / lib / language-parsers / presto-grammar / lang / presto / SqlBaseVisitor.js View on Github external
// Generated from ./lang/presto/SqlBase.g4 by ANTLR 4.7
// jshint ignore: start
var antlr4 = require('antlr4');

// This class defines a complete generic visitor for a parse tree produced by SqlBaseParser.

function SqlBaseVisitor() {
	antlr4.tree.ParseTreeVisitor.call(this);
	return this;
}

SqlBaseVisitor.prototype = Object.create(antlr4.tree.ParseTreeVisitor.prototype);
SqlBaseVisitor.prototype.constructor = SqlBaseVisitor;

// Visit a parse tree produced by SqlBaseParser#multiStatement.
SqlBaseVisitor.prototype.visitMultiStatement = function(ctx) {
  return this.visitChildren(ctx);
};


// Visit a parse tree produced by SqlBaseParser#singleStatement.
SqlBaseVisitor.prototype.visitSingleStatement = function(ctx) {
  return this.visitChildren(ctx);
};


// Visit a parse tree produced by SqlBaseParser#singleExpression.
SqlBaseVisitor.prototype.visitSingleExpression = function(ctx) {
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 solidity-ide / antlr-parser / src / SolidityParser.ts View on Github external
private parseStream (stream: any): void {

        if (this.isComplete) {
            throw new EvalError("The Observable has been completed.");
        }

        const lexer = new Lexer(stream);
        const tokens = new antlr4.CommonTokenStream(lexer);
        const parser = new Parser(tokens);
        parser.buildParseTrees = true;

        parser.removeErrorListeners();
        parser.addErrorListener(this.errorListener);

        const tree = parser.sourceUnit();
        antlr4.tree.ParseTreeWalker.DEFAULT.walk(this.ruleListener, tree);
        parser.removeErrorListeners();

        if (this.fireComplete) {
            this.complete();
        }
    }
}
github wix / quix / quix-frontend / client / src / lib / language-parsers / sql-parser / parser / index.ts View on Github external
export const parsePrestoSql = (input: string) => {
  const parser = createParser(input);
  const prestoListener = new PrestoListener();
  parser.removeErrorListeners();
  const tree = parser.multiStatement();
  antlr4.tree.ParseTreeWalker.DEFAULT.walk(prestoListener, tree);
  return prestoListener.parseResults();
};
github mongodb-js / bson-transpilers / printers / ECMAScriptListener.js View on Github external
Listener.prototype.buildAST = function(tree, ruleNames) {
  ruleNames = ruleNames || null;

  let s = antlr4.tree.Trees.getNodeText(tree, ruleNames);

  s = antlr4.Utils.escapeWhitespace(s, false);

  const c = tree.getChildCount();

  if (c === 0) {
    return s;
  }

  const res = {type: s, node: tree.constructor.name};

  if (c > 0) {
    s = this.buildAST(tree.getChild(0), ruleNames);
    res.children = [...(res.children || []), s];
  }
github kitspace / electro-grammar / js / lib / lax_parser.js View on Github external
function parse(input) {
    const chars = new antlr4.InputStream(input);
    const lexer = new ElectroGrammarLexer(chars);
    const tokens = new antlr4.CommonTokenStream(lexer);
    const parser = new ElectroGrammarParser(tokens);
    parser.buildParseTrees = true;

    const tree = parser[start_rule]();
    antlr4.tree.ParseTreeWalker.DEFAULT.walk(listener, tree);
    return listener.obj;
  }
  return parse;
github indeedeng / iql / iql2 / src / js / Parsers.js View on Github external
function walkIt(tree, walker) {
    antlr4.tree.ParseTreeWalker.DEFAULT.walk(walker, tree);
}