Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
};
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]();
};
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();
}
/*
* 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);
})
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
}
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]),
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()
code.forEach(c => this.parseStream(new antlr4.InputStream(c, true)));
}