UNPKG

@stordata/grammars

Version:

A collection of ANTLR grammars used at Stordata. This project exists so that we can package the grammars (and various utilities) as a CommonJS module. The `antlr4` Javascript runtime is only available as an ES module at the time of writing.

739 lines (610 loc) 20.6 kB
// Generated from src/grammars/CustomMetric.g4 by ANTLR 4.13.1 // jshint ignore: start import antlr4 from 'antlr4'; import CustomMetricListener from './CustomMetricListener.js'; import CustomMetricVisitor from './CustomMetricVisitor.js'; const serializedATN = [4,1,23,47,2,0,7,0,2,1,7,1,1,0,1,0,1,0,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1,18,8,1,1,1,1,1,5,1,22,8,1,10,1,12,1,25,9, 1,1,1,3,1,28,8,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,1,42, 8,1,10,1,12,1,45,9,1,1,1,0,1,2,2,0,2,0,0,53,0,4,1,0,0,0,2,27,1,0,0,0,4,5, 3,2,1,0,5,6,5,0,0,1,6,1,1,0,0,0,7,8,6,1,-1,0,8,9,5,12,0,0,9,10,3,2,1,0,10, 11,5,13,0,0,11,28,1,0,0,0,12,28,5,2,0,0,13,28,5,3,0,0,14,15,5,4,0,0,15,17, 5,12,0,0,16,18,3,2,1,0,17,16,1,0,0,0,17,18,1,0,0,0,18,23,1,0,0,0,19,20,5, 1,0,0,20,22,3,2,1,0,21,19,1,0,0,0,22,25,1,0,0,0,23,21,1,0,0,0,23,24,1,0, 0,0,24,26,1,0,0,0,25,23,1,0,0,0,26,28,5,13,0,0,27,7,1,0,0,0,27,12,1,0,0, 0,27,13,1,0,0,0,27,14,1,0,0,0,28,43,1,0,0,0,29,30,10,8,0,0,30,31,5,6,0,0, 31,42,3,2,1,9,32,33,10,7,0,0,33,34,5,7,0,0,34,42,3,2,1,8,35,36,10,6,0,0, 36,37,5,8,0,0,37,42,3,2,1,7,38,39,10,5,0,0,39,40,5,9,0,0,40,42,3,2,1,6,41, 29,1,0,0,0,41,32,1,0,0,0,41,35,1,0,0,0,41,38,1,0,0,0,42,45,1,0,0,0,43,41, 1,0,0,0,43,44,1,0,0,0,44,3,1,0,0,0,45,43,1,0,0,0,5,17,23,27,41,43]; 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.atn.PredictionContextCache(); export default class CustomMetricParser extends antlr4.Parser { static grammarFileName = "CustomMetric.g4"; static literalNames = [ null, "','", null, null, null, null, null, null, null, null, null, "'.'", "'('", "')'", "'+'", "'-'", "'*'", "'/'", "'\"'", "' '" ]; static symbolicNames = [ null, null, "NUMBER", "STRING", "FN", "WHITESPACE", "ADD", "SUBTRACT", "MULTIPLY", "DIVIDE", "DIGIT", "DOT", "L_PARANT", "R_PARANT", "PLUS", "MINUS", "STAR", "SLASH", "DQUOTE", "SPACE", "TAB", "CR", "LF", "ANY" ]; static ruleNames = [ "all", "expression" ]; constructor(input) { super(input); this._interp = new antlr4.atn.ParserATNSimulator(this, atn, decisionsToDFA, sharedContextCache); this.ruleNames = CustomMetricParser.ruleNames; this.literalNames = CustomMetricParser.literalNames; this.symbolicNames = CustomMetricParser.symbolicNames; } sempred(localctx, ruleIndex, predIndex) { switch(ruleIndex) { case 1: return this.expression_sempred(localctx, predIndex); default: throw "No predicate with index:" + ruleIndex; } } expression_sempred(localctx, predIndex) { switch(predIndex) { case 0: return this.precpred(this._ctx, 8); case 1: return this.precpred(this._ctx, 7); case 2: return this.precpred(this._ctx, 6); case 3: return this.precpred(this._ctx, 5); default: throw "No predicate with index:" + predIndex; } }; all() { let localctx = new AllContext(this, this._ctx, this.state); this.enterRule(localctx, 0, CustomMetricParser.RULE_all); try { this.enterOuterAlt(localctx, 1); this.state = 4; this.expression(0); this.state = 5; this.match(CustomMetricParser.EOF); } catch (re) { if(re instanceof antlr4.error.RecognitionException) { localctx.exception = re; this._errHandler.reportError(this, re); this._errHandler.recover(this, re); } else { throw re; } } finally { this.exitRule(); } return localctx; } expression(_p) { if(_p===undefined) { _p = 0; } const _parentctx = this._ctx; const _parentState = this.state; let localctx = new ExpressionContext(this, this._ctx, _parentState); let _prevctx = localctx; const _startState = 2; this.enterRecursionRule(localctx, 2, CustomMetricParser.RULE_expression, _p); var _la = 0; try { this.enterOuterAlt(localctx, 1); this.state = 27; this._errHandler.sync(this); switch(this._input.LA(1)) { case 12: localctx = new WrappedExpressionContext(this, localctx); this._ctx = localctx; _prevctx = localctx; this.state = 8; this.match(CustomMetricParser.L_PARANT); this.state = 9; this.expression(0); this.state = 10; this.match(CustomMetricParser.R_PARANT); break; case 2: localctx = new NumberContext(this, localctx); this._ctx = localctx; _prevctx = localctx; this.state = 12; this.match(CustomMetricParser.NUMBER); break; case 3: localctx = new StringContext(this, localctx); this._ctx = localctx; _prevctx = localctx; this.state = 13; this.match(CustomMetricParser.STRING); break; case 4: localctx = new FunctionContext(this, localctx); this._ctx = localctx; _prevctx = localctx; this.state = 14; this.match(CustomMetricParser.FN); this.state = 15; this.match(CustomMetricParser.L_PARANT); this.state = 17; this._errHandler.sync(this); _la = this._input.LA(1); if((((_la) & ~0x1f) === 0 && ((1 << _la) & 4124) !== 0)) { this.state = 16; this.expression(0); } this.state = 23; this._errHandler.sync(this); _la = this._input.LA(1); while(_la===1) { this.state = 19; this.match(CustomMetricParser.T__0); this.state = 20; this.expression(0); this.state = 25; this._errHandler.sync(this); _la = this._input.LA(1); } this.state = 26; this.match(CustomMetricParser.R_PARANT); break; default: throw new antlr4.error.NoViableAltException(this); } this._ctx.stop = this._input.LT(-1); this.state = 43; this._errHandler.sync(this); var _alt = this._interp.adaptivePredict(this._input,4,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 = 41; this._errHandler.sync(this); var la_ = this._interp.adaptivePredict(this._input,3,this._ctx); switch(la_) { case 1: localctx = new AdditionContext(this, new ExpressionContext(this, _parentctx, _parentState)); localctx.left = _prevctx; this.pushNewRecursionContext(localctx, _startState, CustomMetricParser.RULE_expression); this.state = 29; if (!( this.precpred(this._ctx, 8))) { throw new antlr4.error.FailedPredicateException(this, "this.precpred(this._ctx, 8)"); } this.state = 30; this.match(CustomMetricParser.ADD); this.state = 31; localctx.right = this.expression(9); break; case 2: localctx = new SubtractionContext(this, new ExpressionContext(this, _parentctx, _parentState)); localctx.left = _prevctx; this.pushNewRecursionContext(localctx, _startState, CustomMetricParser.RULE_expression); this.state = 32; if (!( this.precpred(this._ctx, 7))) { throw new antlr4.error.FailedPredicateException(this, "this.precpred(this._ctx, 7)"); } this.state = 33; this.match(CustomMetricParser.SUBTRACT); this.state = 34; localctx.right = this.expression(8); break; case 3: localctx = new MultiplicationContext(this, new ExpressionContext(this, _parentctx, _parentState)); localctx.left = _prevctx; this.pushNewRecursionContext(localctx, _startState, CustomMetricParser.RULE_expression); this.state = 35; if (!( this.precpred(this._ctx, 6))) { throw new antlr4.error.FailedPredicateException(this, "this.precpred(this._ctx, 6)"); } this.state = 36; this.match(CustomMetricParser.MULTIPLY); this.state = 37; localctx.right = this.expression(7); break; case 4: localctx = new DivisionContext(this, new ExpressionContext(this, _parentctx, _parentState)); localctx.left = _prevctx; this.pushNewRecursionContext(localctx, _startState, CustomMetricParser.RULE_expression); this.state = 38; if (!( this.precpred(this._ctx, 5))) { throw new antlr4.error.FailedPredicateException(this, "this.precpred(this._ctx, 5)"); } this.state = 39; this.match(CustomMetricParser.DIVIDE); this.state = 40; localctx.right = this.expression(6); break; } } this.state = 45; this._errHandler.sync(this); _alt = this._interp.adaptivePredict(this._input,4,this._ctx); } } catch( error) { if(error instanceof antlr4.error.RecognitionException) { localctx.exception = error; this._errHandler.reportError(this, error); this._errHandler.recover(this, error); } else { throw error; } } finally { this.unrollRecursionContexts(_parentctx) } return localctx; } } CustomMetricParser.EOF = antlr4.Token.EOF; CustomMetricParser.T__0 = 1; CustomMetricParser.NUMBER = 2; CustomMetricParser.STRING = 3; CustomMetricParser.FN = 4; CustomMetricParser.WHITESPACE = 5; CustomMetricParser.ADD = 6; CustomMetricParser.SUBTRACT = 7; CustomMetricParser.MULTIPLY = 8; CustomMetricParser.DIVIDE = 9; CustomMetricParser.DIGIT = 10; CustomMetricParser.DOT = 11; CustomMetricParser.L_PARANT = 12; CustomMetricParser.R_PARANT = 13; CustomMetricParser.PLUS = 14; CustomMetricParser.MINUS = 15; CustomMetricParser.STAR = 16; CustomMetricParser.SLASH = 17; CustomMetricParser.DQUOTE = 18; CustomMetricParser.SPACE = 19; CustomMetricParser.TAB = 20; CustomMetricParser.CR = 21; CustomMetricParser.LF = 22; CustomMetricParser.ANY = 23; CustomMetricParser.RULE_all = 0; CustomMetricParser.RULE_expression = 1; class AllContext extends antlr4.ParserRuleContext { constructor(parser, parent, invokingState) { if(parent===undefined) { parent = null; } if(invokingState===undefined || invokingState===null) { invokingState = -1; } super(parent, invokingState); this.parser = parser; this.ruleIndex = CustomMetricParser.RULE_all; } expression() { return this.getTypedRuleContext(ExpressionContext,0); }; EOF() { return this.getToken(CustomMetricParser.EOF, 0); }; enterRule(listener) { if(listener instanceof CustomMetricListener ) { listener.enterAll(this); } } exitRule(listener) { if(listener instanceof CustomMetricListener ) { listener.exitAll(this); } } accept(visitor) { if ( visitor instanceof CustomMetricVisitor ) { return visitor.visitAll(this); } else { return visitor.visitChildren(this); } } } class ExpressionContext extends antlr4.ParserRuleContext { constructor(parser, parent, invokingState) { if(parent===undefined) { parent = null; } if(invokingState===undefined || invokingState===null) { invokingState = -1; } super(parent, invokingState); this.parser = parser; this.ruleIndex = CustomMetricParser.RULE_expression; } copyFrom(ctx) { super.copyFrom(ctx); } } class FunctionContext extends ExpressionContext { constructor(parser, ctx) { super(parser); super.copyFrom(ctx); } FN() { return this.getToken(CustomMetricParser.FN, 0); }; L_PARANT() { return this.getToken(CustomMetricParser.L_PARANT, 0); }; R_PARANT() { return this.getToken(CustomMetricParser.R_PARANT, 0); }; expression = function(i) { if(i===undefined) { i = null; } if(i===null) { return this.getTypedRuleContexts(ExpressionContext); } else { return this.getTypedRuleContext(ExpressionContext,i); } }; enterRule(listener) { if(listener instanceof CustomMetricListener ) { listener.enterFunction(this); } } exitRule(listener) { if(listener instanceof CustomMetricListener ) { listener.exitFunction(this); } } accept(visitor) { if ( visitor instanceof CustomMetricVisitor ) { return visitor.visitFunction(this); } else { return visitor.visitChildren(this); } } } CustomMetricParser.FunctionContext = FunctionContext; class AdditionContext extends ExpressionContext { constructor(parser, ctx) { super(parser); this.left = null;; this.right = null;; super.copyFrom(ctx); } ADD() { return this.getToken(CustomMetricParser.ADD, 0); }; expression = function(i) { if(i===undefined) { i = null; } if(i===null) { return this.getTypedRuleContexts(ExpressionContext); } else { return this.getTypedRuleContext(ExpressionContext,i); } }; enterRule(listener) { if(listener instanceof CustomMetricListener ) { listener.enterAddition(this); } } exitRule(listener) { if(listener instanceof CustomMetricListener ) { listener.exitAddition(this); } } accept(visitor) { if ( visitor instanceof CustomMetricVisitor ) { return visitor.visitAddition(this); } else { return visitor.visitChildren(this); } } } CustomMetricParser.AdditionContext = AdditionContext; class MultiplicationContext extends ExpressionContext { constructor(parser, ctx) { super(parser); this.left = null;; this.right = null;; super.copyFrom(ctx); } MULTIPLY() { return this.getToken(CustomMetricParser.MULTIPLY, 0); }; expression = function(i) { if(i===undefined) { i = null; } if(i===null) { return this.getTypedRuleContexts(ExpressionContext); } else { return this.getTypedRuleContext(ExpressionContext,i); } }; enterRule(listener) { if(listener instanceof CustomMetricListener ) { listener.enterMultiplication(this); } } exitRule(listener) { if(listener instanceof CustomMetricListener ) { listener.exitMultiplication(this); } } accept(visitor) { if ( visitor instanceof CustomMetricVisitor ) { return visitor.visitMultiplication(this); } else { return visitor.visitChildren(this); } } } CustomMetricParser.MultiplicationContext = MultiplicationContext; class SubtractionContext extends ExpressionContext { constructor(parser, ctx) { super(parser); this.left = null;; this.right = null;; super.copyFrom(ctx); } SUBTRACT() { return this.getToken(CustomMetricParser.SUBTRACT, 0); }; expression = function(i) { if(i===undefined) { i = null; } if(i===null) { return this.getTypedRuleContexts(ExpressionContext); } else { return this.getTypedRuleContext(ExpressionContext,i); } }; enterRule(listener) { if(listener instanceof CustomMetricListener ) { listener.enterSubtraction(this); } } exitRule(listener) { if(listener instanceof CustomMetricListener ) { listener.exitSubtraction(this); } } accept(visitor) { if ( visitor instanceof CustomMetricVisitor ) { return visitor.visitSubtraction(this); } else { return visitor.visitChildren(this); } } } CustomMetricParser.SubtractionContext = SubtractionContext; class NumberContext extends ExpressionContext { constructor(parser, ctx) { super(parser); super.copyFrom(ctx); } NUMBER() { return this.getToken(CustomMetricParser.NUMBER, 0); }; enterRule(listener) { if(listener instanceof CustomMetricListener ) { listener.enterNumber(this); } } exitRule(listener) { if(listener instanceof CustomMetricListener ) { listener.exitNumber(this); } } accept(visitor) { if ( visitor instanceof CustomMetricVisitor ) { return visitor.visitNumber(this); } else { return visitor.visitChildren(this); } } } CustomMetricParser.NumberContext = NumberContext; class WrappedExpressionContext extends ExpressionContext { constructor(parser, ctx) { super(parser); super.copyFrom(ctx); } L_PARANT() { return this.getToken(CustomMetricParser.L_PARANT, 0); }; expression() { return this.getTypedRuleContext(ExpressionContext,0); }; R_PARANT() { return this.getToken(CustomMetricParser.R_PARANT, 0); }; enterRule(listener) { if(listener instanceof CustomMetricListener ) { listener.enterWrappedExpression(this); } } exitRule(listener) { if(listener instanceof CustomMetricListener ) { listener.exitWrappedExpression(this); } } accept(visitor) { if ( visitor instanceof CustomMetricVisitor ) { return visitor.visitWrappedExpression(this); } else { return visitor.visitChildren(this); } } } CustomMetricParser.WrappedExpressionContext = WrappedExpressionContext; class DivisionContext extends ExpressionContext { constructor(parser, ctx) { super(parser); this.left = null;; this.right = null;; super.copyFrom(ctx); } DIVIDE() { return this.getToken(CustomMetricParser.DIVIDE, 0); }; expression = function(i) { if(i===undefined) { i = null; } if(i===null) { return this.getTypedRuleContexts(ExpressionContext); } else { return this.getTypedRuleContext(ExpressionContext,i); } }; enterRule(listener) { if(listener instanceof CustomMetricListener ) { listener.enterDivision(this); } } exitRule(listener) { if(listener instanceof CustomMetricListener ) { listener.exitDivision(this); } } accept(visitor) { if ( visitor instanceof CustomMetricVisitor ) { return visitor.visitDivision(this); } else { return visitor.visitChildren(this); } } } CustomMetricParser.DivisionContext = DivisionContext; class StringContext extends ExpressionContext { constructor(parser, ctx) { super(parser); super.copyFrom(ctx); } STRING() { return this.getToken(CustomMetricParser.STRING, 0); }; enterRule(listener) { if(listener instanceof CustomMetricListener ) { listener.enterString(this); } } exitRule(listener) { if(listener instanceof CustomMetricListener ) { listener.exitString(this); } } accept(visitor) { if ( visitor instanceof CustomMetricVisitor ) { return visitor.visitString(this); } else { return visitor.visitChildren(this); } } } CustomMetricParser.StringContext = StringContext; CustomMetricParser.AllContext = AllContext; CustomMetricParser.ExpressionContext = ExpressionContext;