Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
// 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;
"01\u0007(\u0002\u000212\u0007(\u0002\u00022\n\u0003\u0002\u0002\u0002",
"34\u0007~\u0002\u000245\u0007~\u0002\u00025\f\u0003\u0002\u0002\u0002",
"67\u0007@\u0002\u00027\u000e\u0003\u0002\u0002\u000289\u0007>\u0002",
"\u00029\u0010\u0003\u0002\u0002\u0002:;\u0007?\u0002\u0002;<\u0007?",
"\u0002\u0002<\u0012\u0003\u0002\u0002\u0002=>\u0007@\u0002\u0002>?\u0007",
"?\u0002\u0002?\u0014\u0003\u0002\u0002\u0002@A\u0007>\u0002\u0002AB",
"\u0007?\u0002\u0002B\u0016\u0003\u0002\u0002\u0002CE\t\u0005\u0002\u0002",
"DC\u0003\u0002\u0002\u0002EH\u0003\u0002\u0002\u0002FD\u0003\u0002\u0002",
"\u0002FG\u0003\u0002\u0002\u0002GI\u0003\u0002\u0002\u0002HF\u0003\u0002",
"\u0002\u0002IM\t\u0006\u0002\u0002JL\t\u0007\u0002\u0002KJ\u0003\u0002",
"\u0002\u0002LO\u0003\u0002\u0002\u0002MK\u0003\u0002\u0002\u0002MN\u0003",
"\u0002\u0002\u0002N\u0018\u0003\u0002\u0002\u0002OM\u0003\u0002\u0002",
"\u0002\b\u0002\u001c+.FM\u0003\b\u0002\u0002"].join("");
const atn = new antlr4.atn.ATNDeserializer().deserialize(serializedATN);
const decisionsToDFA = atn.decisionToState.map( (ds, index) => new antlr4.dfa.DFA(ds, index) );
export default class PolicyLexer extends antlr4.Lexer {
static grammarFileName = "Policy.g4";
static channelNames = [ "DEFAULT_TOKEN_CHANNEL", "HIDDEN" ];
static modeNames = [ "DEFAULT_MODE" ];
static literalNames = [ null, null, "'count'", null, "'&&'", "'||'", "'>'",
"'<'", "'=='", "'>='", "'<='" ];
static symbolicNames = [ null, "WS", "COUNT", "INTLIT", "AND", "OR", "GREATER_THAN",
"LESS_THAN", "EQUAL", "GREATER_THAN_EQUAL", "LESS_THAN_EQUAL",
"ID" ];
static ruleNames = [ "WS", "COUNT", "INTLIT", "AND", "OR", "GREATER_THAN",
"LESS_THAN", "EQUAL", "GREATER_THAN_EQUAL", "LESS_THAN_EQUAL",
"ID" ];
case PolicyParser.COUNT:
case PolicyParser.INTLIT:
localctx = new CountExpressionContext(this, localctx);
this._ctx = localctx;
_prevctx = localctx;
this.state = 11;
this.count_expression();
break;
default:
throw new antlr4.error.NoViableAltException(this);
}
this._ctx.stop = this._input.LT(-1);
this.state = 22;
this._errHandler.sync(this);
let _alt = this._interp.adaptivePredict(this._input,2,this._ctx)
while(_alt!=2 && _alt!=antlr4.atn.ATN.INVALID_ALT_NUMBER) {
if(_alt===1) {
if(this._parseListeners!==null) {
this.triggerExitRuleEvent();
}
_prevctx = localctx;
this.state = 20;
this._errHandler.sync(this);
var la_ = this._interp.adaptivePredict(this._input,1,this._ctx);
switch(la_) {
case 1:
localctx = new BooleanAndExpressionContext(this, new ExpressionContext(this, _parentctx, _parentState));
this.pushNewRecursionContext(localctx, _startState, PolicyParser.RULE_expression);
this.state = 14;
if (!( this.precpred(this._ctx, 4))) {
throw new antlr4.error.FailedPredicateException(this, "this.precpred(this._ctx, 4)");
}
"\u0004\u0002\u000e\u000b\u0003\u0002\u0002\u0002\u000e\r\u0003\u0002",
"\u0002\u0002\u000f\u0018\u0003\u0002\u0002\u0002\u0010\u0011\f\u0006",
"\u0002\u0002\u0011\u0012\u0007\u0006\u0002\u0002\u0012\u0017\u0005\u0004",
"\u0003\u0007\u0013\u0014\f\u0005\u0002\u0002\u0014\u0015\u0007\u0007",
"\u0002\u0002\u0015\u0017\u0005\u0004\u0003\u0006\u0016\u0010\u0003\u0002",
"\u0002\u0002\u0016\u0013\u0003\u0002\u0002\u0002\u0017\u001a\u0003\u0002",
"\u0002\u0002\u0018\u0016\u0003\u0002\u0002\u0002\u0018\u0019\u0003\u0002",
"\u0002\u0002\u0019\u0005\u0003\u0002\u0002\u0002\u001a\u0018\u0003\u0002",
"\u0002\u0002\u001b\u001c\u0007\u0004\u0002\u0002\u001c\u001d\t\u0002",
"\u0002\u0002\u001d\"\u0007\u0005\u0002\u0002\u001e\u001f\u0007\u0005",
"\u0002\u0002\u001f \t\u0002\u0002\u0002 \"\u0007\u0004\u0002\u0002!",
"\u001b\u0003\u0002\u0002\u0002!\u001e\u0003\u0002\u0002\u0002\"\u0007",
"\u0003\u0002\u0002\u0002\u0006\u000e\u0016\u0018!"].join("");
const atn = new antlr4.atn.ATNDeserializer().deserialize(serializedATN);
const decisionsToDFA = atn.decisionToState.map( (ds, index) => new antlr4.dfa.DFA(ds, index) );
const sharedContextCache = new antlr4.PredictionContextCache();
export default class PolicyParser extends antlr4.Parser {
static grammarFileName = "Policy.g4";
static literalNames = [ null, null, "'count'", null, "'&&'", "'||'",
"'>'", "'<'", "'=='", "'>='", "'<='" ];
static symbolicNames = [ null, "WS", "COUNT", "INTLIT", "AND", "OR",
"GREATER_THAN", "LESS_THAN", "EQUAL", "GREATER_THAN_EQUAL",
"LESS_THAN_EQUAL", "ID" ];
static ruleNames = [ "root", "expression", "count_expression" ];
constructor(input) {
constructor(input) {
super(input);
this._interp = new antlr4.atn.ParserATNSimulator(this, atn, decisionsToDFA, sharedContextCache);
this.ruleNames = PolicyParser.ruleNames;
this.literalNames = PolicyParser.literalNames;
this.symbolicNames = PolicyParser.symbolicNames;
}