UNPKG

antlr-ng

Version:

Next generation ANTLR Tool

1,589 lines 63.5 kB
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); import { RecognitionException } from "antlr4ng"; import { CommonTreeNodeStream } from "../CommonTreeNodeStream.js"; import { EarlyExitException } from "../exceptions/EarlyExitException.js"; import { MismatchedSetException } from "../exceptions/MismatchedSetException.js"; import { NoViableAltException } from "../exceptions/NoViableAltException.js"; import { TreeParser } from "../TreeParser.js"; import { Constants } from "../../Constants.js"; import { ANTLRv4Parser } from "../../generated/ANTLRv4Parser.js"; import { ANTLRv4Lexer } from "../../generated/ANTLRv4Lexer.js"; class GrammarTreeVisitor extends TreeParser { static { __name(this, "GrammarTreeVisitor"); } currentRuleName; currentOuterAltNumber = 1; // 1..n currentModeName = Constants.DefaultNodeName; constructor(errorManager, input) { super(errorManager, input); } visitGrammar(t) { this.visit(t, ANTLRv4Parser.RULE_grammarSpec); } visit(t, ruleIndex) { const nodes = new CommonTreeNodeStream(t); this.input = nodes; switch (ruleIndex) { case ANTLRv4Parser.RULE_grammarSpec: { this.grammarSpec(); break; } case ANTLRv4Parser.RULE_ruleSpec: { this.ruleSpec(); break; } default: { throw new Error("No rule with the index " + ruleIndex); } } } outerAlternative() { const start = this.input.lookaheadType(1); this.discoverOuterAlt(start); try { this.alternative(); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } discoverGrammar(root, id) { } finishPrequels(firstPrequel) { } finishGrammar(root, id) { } grammarOption(id, valueAST) { } ruleOption(id, valueAST) { } blockOption(id, valueAST) { } defineToken(id) { } defineChannel(id) { } globalNamedAction(scope, id, action) { } importGrammar(label, id) { } modeDef(m, id) { } discoverRules(rules) { } discoverRule(rule, id, modifiers, arg, returns, throws, options, locals, actions, block) { } finishRule(rule, id, block) { } discoverLexerRule(rule, id, modifiers, options, block) { } ruleCatch(arg, action) { } finallyAction(action) { } discoverOuterAlt(alt) { } ruleRef(ref, arg) { } tokenRef(ref) { } elementOption(t, id, valueAST) { } stringRef(ref) { } actionInAlt(action) { } sempredInAlt(pred) { } label(op, id, element) { } lexerCommand(outerAltNumber, id) { } enterChannelsSpec(tree) { } enterMode(tree) { } exitMode(tree) { } enterLexerRule(tree) { } exitLexerRule(tree) { } enterLexerAlternative(tree) { } exitLexerAlternative(tree) { } enterLexerElement(tree) { } exitLexerElement(tree) { } enterAlternative(tree) { } exitAlternative(tree) { } enterLexerCommand(tree) { } enterElement(tree) { } exitElement(tree) { } exitSubrule(tree) { } exitLexerSubrule(tree) { } enterBlockSet(tree) { } exitBlockSet(tree) { } enterTerminal(tree) { } grammarSpec() { try { const grammar = this.match(this.input, ANTLRv4Parser.GRAMMAR); this.match(this.input, Constants.Down); const id = this.match(this.input, ANTLRv4Parser.ID); this.discoverGrammar(grammar, id); const prequelConstructs = this.prequelConstructs(); this.finishPrequels(prequelConstructs ?? null); this.rules(); while (true) { const lookahead = this.input.lookahead(1); if (lookahead === ANTLRv4Parser.MODE) { this.mode(); } else { break; } } this.finishGrammar(grammar, id); this.match(this.input, Constants.Up); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } prequelConstructs() { let firstOne; const start = this.input.lookaheadType(1); try { const lookahead = this.input.lookahead(1); if (lookahead === ANTLRv4Parser.AT || lookahead === ANTLRv4Parser.CHANNELS || lookahead === ANTLRv4Parser.IMPORT || lookahead === ANTLRv4Parser.OPTIONS || lookahead === ANTLRv4Parser.TOKENS) { firstOne = start; let prequelCounter = 0; while (true) { const lookahead2 = this.input.lookahead(1); if (lookahead2 === ANTLRv4Parser.AT || lookahead2 === ANTLRv4Parser.CHANNELS || lookahead2 === ANTLRv4Parser.IMPORT || lookahead2 === ANTLRv4Parser.OPTIONS || lookahead2 === ANTLRv4Parser.TOKENS) { this.prequelConstruct(); } else { if (prequelCounter >= 1) { break; } throw new EarlyExitException(2); } ++prequelCounter; } } else if (lookahead !== ANTLRv4Parser.RULES) { throw new NoViableAltException(3, 0); } } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } return firstOne; } prequelConstruct() { try { switch (this.input.lookahead(1)) { case ANTLRv4Parser.OPTIONS: { this.optionsSpec(); break; } case ANTLRv4Parser.IMPORT: { this.delegateGrammars(); break; } case ANTLRv4Parser.TOKENS: { this.tokensSpec(); break; } case ANTLRv4Parser.CHANNELS: { this.channelsSpec(); break; } case ANTLRv4Parser.AT: { this.action(); break; } default: { throw new NoViableAltException(4, 0); } } } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } optionsSpec() { const start = this.input.lookaheadType(1); try { this.match(this.input, ANTLRv4Parser.OPTIONS); if (this.input.lookahead(1) === Constants.Down) { this.match(this.input, Constants.Down); while (true) { if (this.input.lookahead(1) === ANTLRv4Parser.ASSIGN) { this.option(); } else { break; } } this.match(this.input, Constants.Up); } } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } return start; } option() { const rule = this.inContext([ANTLRv4Lexer.RULE, Constants.Up]); const block = this.inContext([ANTLRv4Lexer.BLOCK, Constants.Up]); try { this.match(this.input, ANTLRv4Parser.ASSIGN); this.match(this.input, Constants.Down); const id = this.match(this.input, ANTLRv4Parser.ID); const v = this.optionValue(); this.match(this.input, Constants.Up); if (block) { this.blockOption(id, v); } else { if (rule) { this.ruleOption(id, v); } else { this.grammarOption(id, v); } } } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } optionValue() { const start = this.input.lookaheadType(1); try { const lookahead = this.input.lookahead(1); if (lookahead === ANTLRv4Parser.ID || lookahead === ANTLRv4Parser.INT || lookahead === ANTLRv4Parser.STRING_LITERAL) { this.input.consume(); this.errorRecovery = false; } else { throw new MismatchedSetException(); } } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } return start; } delegateGrammars() { try { this.match(this.input, ANTLRv4Parser.IMPORT); this.match(this.input, Constants.Down); let grammarCount = 0; while (true) { const lookahead = this.input.lookahead(1); if (lookahead === ANTLRv4Parser.ASSIGN || lookahead === ANTLRv4Parser.ID) { this.delegateGrammar(); } else { if (grammarCount >= 1) { break; } throw new EarlyExitException(6); } ++grammarCount; } this.match(this.input, Constants.Up); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } delegateGrammar() { try { const lookahead = this.input.lookahead(1); if (lookahead === ANTLRv4Parser.ASSIGN) { this.match(this.input, ANTLRv4Parser.ASSIGN); this.match(this.input, Constants.Down); const label = this.match(this.input, ANTLRv4Parser.ID); const id = this.match(this.input, ANTLRv4Parser.ID); this.match(this.input, Constants.Up); this.importGrammar(label, id); } else if (lookahead === ANTLRv4Parser.ID) { const id = this.match(this.input, ANTLRv4Parser.ID); this.importGrammar(null, id); } else { throw new NoViableAltException(7, 0); } } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } tokensSpec() { try { this.match(this.input, ANTLRv4Parser.TOKENS); this.match(this.input, Constants.Down); let specCount = 0; while (true) { if (this.input.lookahead(1) === ANTLRv4Parser.ID) { this.tokenSpec(); } else { if (specCount >= 1) { break; } throw new EarlyExitException(8); } ++specCount; } this.match(this.input, Constants.Up); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } tokenSpec() { try { const id = this.match(this.input, ANTLRv4Parser.ID); this.defineToken(id); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } channelsSpec() { const start = this.input.lookaheadType(1); this.enterChannelsSpec(start); try { this.match(this.input, ANTLRv4Parser.CHANNELS); this.match(this.input, Constants.Down); let specCount = 0; while (true) { if (this.input.lookahead(1) === ANTLRv4Parser.ID) { this.channelSpec(); } else { if (specCount > 0) { break; } throw new EarlyExitException(9); } ++specCount; } this.match(this.input, Constants.Up); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } channelSpec() { try { const id = this.match(this.input, ANTLRv4Parser.ID); this.defineChannel(id); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } action() { try { this.match(this.input, ANTLRv4Parser.AT); this.match(this.input, Constants.Down); let sc; if (this.input.lookahead(1) === ANTLRv4Parser.ID) { if (this.input.lookahead(2) === ANTLRv4Parser.ID) { sc = this.match(this.input, ANTLRv4Parser.ID); } } const name = this.match(this.input, ANTLRv4Parser.ID); const action = this.match(this.input, ANTLRv4Parser.ACTION); this.match(this.input, Constants.Up); this.globalNamedAction(sc ?? null, name, action); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } rules() { try { const rules = this.match(this.input, ANTLRv4Parser.RULES); this.discoverRules(rules); if (this.input.lookahead(1) === Constants.Down) { this.match(this.input, Constants.Down); while (true) { if (this.input.lookahead(1) === ANTLRv4Parser.RULE) { if (this.input.lookahead(2) === Constants.Down) { const lookahead3 = this.input.lookahead(3); if (lookahead3 === ANTLRv4Parser.RULE_REF) { this.ruleSpec(); } else if (lookahead3 === ANTLRv4Parser.TOKEN_REF) { this.lexerRule(); } else { break; } } else { break; } } else { break; } } this.match(this.input, Constants.Up); } } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } mode() { const start = this.input.lookaheadType(1); this.enterMode(start); try { const mode = this.match(this.input, ANTLRv4Parser.MODE); this.match(this.input, Constants.Down); const id = this.match(this.input, ANTLRv4Parser.ID); this.currentModeName = id?.getText() ?? Constants.DefaultNodeName; this.modeDef(mode, id); while (true) { if (this.input.lookahead(1) === ANTLRv4Parser.RULE) { this.lexerRule(); } else { break; } } this.match(this.input, Constants.Up); this.exitMode(start); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } lexerRule() { const start = this.input.lookaheadType(1); this.enterLexerRule(start); const mods = new Array(); this.currentOuterAltNumber = 0; try { let m; let opts; const rule = this.match(this.input, ANTLRv4Parser.RULE); this.match(this.input, Constants.Down); const tokenRef = this.match(this.input, ANTLRv4Parser.TOKEN_REF); this.currentRuleName = tokenRef?.getText(); if (this.input.lookahead(1) === ANTLRv4Parser.RULEMODIFIERS) { this.match(this.input, ANTLRv4Parser.RULEMODIFIERS); this.match(this.input, Constants.Down); m = this.match(this.input, ANTLRv4Parser.FRAGMENT); mods.push(m); this.match(this.input, Constants.Up); } while (true) { if (this.input.lookahead(1) === ANTLRv4Parser.OPTIONS) { opts = this.optionsSpec(); } else { break; } } this.discoverLexerRule( rule, tokenRef, mods, opts ?? null, this.input.lookaheadType(1) ); this.lexerRuleBlock(); this.currentRuleName = void 0; this.match(this.input, Constants.Up); this.exitLexerRule(start); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } ruleSpec() { const mods = new Array(); const actions = new Array(); this.currentOuterAltNumber = 0; try { const rule = this.match(this.input, ANTLRv4Parser.RULE) ?? void 0; this.match(this.input, Constants.Down); const ruleRef = this.match(this.input, ANTLRv4Parser.RULE_REF) ?? void 0; this.currentRuleName = ruleRef?.getText(); let argAction; let ret; let thr; let loc; let opts; if (this.input.lookahead(1) === ANTLRv4Parser.RULEMODIFIERS) { this.match(this.input, ANTLRv4Parser.RULEMODIFIERS); this.match(this.input, Constants.Down); let modifierCount = 0; while (true) { const lookahead = this.input.lookahead(1); if (lookahead === ANTLRv4Parser.FRAGMENT || lookahead >= ANTLRv4Parser.PRIVATE && lookahead <= ANTLRv4Parser.PUBLIC) { const modifier = this.ruleModifier(); mods.push(modifier); } else { if (modifierCount >= 1) { break; } throw new EarlyExitException(15); } ++modifierCount; } this.match(this.input, Constants.Up); } if (this.input.lookahead(1) === ANTLRv4Parser.ARG_ACTION) { argAction = this.match(this.input, ANTLRv4Parser.ARG_ACTION); } if (this.input.lookahead(1) === ANTLRv4Parser.RETURNS) { ret = this.ruleReturns(); } if (this.input.lookahead(1) === ANTLRv4Parser.THROWS) { thr = this.throwsSpec(); } if (this.input.lookahead(1) === ANTLRv4Parser.LOCALS) { loc = this.locals(); } while (true) { const lookahead = this.input.lookahead(1); if (lookahead === ANTLRv4Parser.OPTIONS) { opts = this.optionsSpec(); } else if (lookahead === ANTLRv4Parser.AT) { const a = this.ruleAction(); actions.push(a); } else { break; } } this.discoverRule( rule, ruleRef, mods, argAction, ret?.children[0], thr, opts ?? void 0, loc?.children[0] ?? void 0, actions, this.input.lookaheadType(1) ); const ruleBlock17 = this.ruleBlock(); this.exceptionGroup(); this.finishRule(rule, ruleRef ?? null, ruleBlock17); this.currentRuleName = void 0; this.match(this.input, Constants.Up); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } exceptionGroup() { try { while (true) { if (this.input.lookahead(1) === ANTLRv4Parser.CATCH) { this.exceptionHandler(); } else { break; } } if (this.input.lookahead(1) === ANTLRv4Parser.FINALLY) { this.finallyClause(); } } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } exceptionHandler() { try { this.match(this.input, ANTLRv4Parser.CATCH); this.match(this.input, Constants.Down); const argAction = this.match(this.input, ANTLRv4Parser.ARG_ACTION); const action = this.match(this.input, ANTLRv4Parser.ACTION); this.match(this.input, Constants.Up); this.ruleCatch(argAction, action); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } finallyClause() { try { this.match(this.input, ANTLRv4Parser.FINALLY); this.match(this.input, Constants.Down); const action = this.match(this.input, ANTLRv4Parser.ACTION); this.match(this.input, Constants.Up); this.finallyAction(action); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } locals() { const start = this.input.lookaheadType(1); try { this.match(this.input, ANTLRv4Parser.LOCALS); this.match(this.input, Constants.Down); this.match(this.input, ANTLRv4Parser.ARG_ACTION); this.match(this.input, Constants.Up); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } return start; } ruleReturns() { const start = this.input.lookaheadType(1); try { this.match(this.input, ANTLRv4Parser.RETURNS); this.match(this.input, Constants.Down); this.match(this.input, ANTLRv4Parser.ARG_ACTION); this.match(this.input, Constants.Up); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } return start; } throwsSpec() { const start = this.input.lookaheadType(1); try { this.match(this.input, ANTLRv4Parser.THROWS); this.match(this.input, Constants.Down); let idCount = 0; while (true) { if (this.input.lookahead(1) === ANTLRv4Parser.ID) { this.match(this.input, ANTLRv4Parser.ID); } else { if (idCount > 0) { break; } throw new EarlyExitException(24); } ++idCount; } this.match(this.input, Constants.Up); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } return start; } ruleAction() { const start = this.input.lookaheadType(1); try { this.match(this.input, ANTLRv4Parser.AT); this.match(this.input, Constants.Down); this.match(this.input, ANTLRv4Parser.ID); this.match(this.input, ANTLRv4Parser.ACTION); this.match(this.input, Constants.Up); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } return start; } ruleModifier() { const start = this.input.lookaheadType(1); try { const lookahead = this.input.lookahead(1); if (lookahead === ANTLRv4Parser.FRAGMENT || lookahead >= ANTLRv4Parser.PRIVATE && lookahead <= ANTLRv4Parser.PUBLIC) { this.input.consume(); this.errorRecovery = false; } else { throw new MismatchedSetException(); } } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } return start; } lexerRuleBlock() { try { this.match(this.input, ANTLRv4Parser.BLOCK); this.match(this.input, Constants.Down); let altCount = 0; while (true) { const lookahead = this.input.lookahead(1); if (lookahead === ANTLRv4Parser.ALT || lookahead === ANTLRv4Parser.LEXER_ALT_ACTION) { ++this.currentOuterAltNumber; this.lexerOuterAlternative(); } else { if (altCount > 0) { break; } throw new EarlyExitException(25); } ++altCount; } this.match(this.input, Constants.Up); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } ruleBlock() { const start = this.input.lookaheadType(1); try { this.match(this.input, ANTLRv4Parser.BLOCK); this.match(this.input, Constants.Down); let altCount = 0; while (true) { if (this.input.lookahead(1) === ANTLRv4Parser.ALT) { ++this.currentOuterAltNumber; this.outerAlternative(); } else { if (altCount > 0) { break; } throw new EarlyExitException(26); } ++altCount; } this.match(this.input, Constants.Up); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } return start; } lexerOuterAlternative() { const start = this.input.lookaheadType(1); this.discoverOuterAlt(start); try { this.lexerAlternative(); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } lexerAlternative() { const start = this.input.lookaheadType(1); this.enterLexerAlternative(start); try { let lookahead = this.input.lookahead(1); if (lookahead === ANTLRv4Parser.LEXER_ALT_ACTION) { this.match(this.input, ANTLRv4Parser.LEXER_ALT_ACTION); this.match(this.input, Constants.Down); this.lexerElements(); let commandCount = 0; while (true) { lookahead = this.input.lookahead(1); if (lookahead === ANTLRv4Parser.ID || lookahead === ANTLRv4Parser.LEXER_ACTION_CALL) { this.handleLexerCommand(); } else { if (commandCount > 0) { break; } throw new EarlyExitException(27); } ++commandCount; } this.match(this.input, Constants.Up); } else if (lookahead === ANTLRv4Parser.ALT) { this.lexerElements(); } else { throw new NoViableAltException(28, 0); } this.exitLexerAlternative(start); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } lexerElements() { try { this.match(this.input, ANTLRv4Parser.ALT); this.match(this.input, Constants.Down); let elementCount = 0; while (true) { const lookahead = this.input.lookahead(1); if (lookahead === ANTLRv4Parser.ACTION || lookahead === ANTLRv4Parser.LEXER_CHAR_SET || lookahead === ANTLRv4Parser.NOT || lookahead === ANTLRv4Parser.RANGE || lookahead === ANTLRv4Parser.RULE_REF || lookahead === ANTLRv4Parser.SEMPRED || lookahead === ANTLRv4Parser.STRING_LITERAL || lookahead === ANTLRv4Parser.TOKEN_REF || lookahead >= ANTLRv4Parser.BLOCK && lookahead <= ANTLRv4Parser.CLOSURE || lookahead === ANTLRv4Parser.EPSILON || lookahead >= ANTLRv4Parser.OPTIONAL && lookahead <= ANTLRv4Parser.POSITIVE_CLOSURE || lookahead >= ANTLRv4Parser.SET && lookahead <= ANTLRv4Parser.WILDCARD) { this.lexerElement(); } else { if (elementCount >= 1) { break; } throw new EarlyExitException(29); } ++elementCount; } this.match(this.input, Constants.Up); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } lexerElement() { const start = this.input.lookaheadType(1); this.enterLexerElement(start); try { switch (this.input.lookahead(1)) { case ANTLRv4Parser.LEXER_CHAR_SET: case ANTLRv4Parser.NOT: case ANTLRv4Parser.RANGE: case ANTLRv4Parser.RULE_REF: case ANTLRv4Parser.STRING_LITERAL: case ANTLRv4Parser.TOKEN_REF: case ANTLRv4Parser.SET: case ANTLRv4Parser.WILDCARD: { this.lexerAtom(); break; } case ANTLRv4Parser.BLOCK: case ANTLRv4Parser.CLOSURE: case ANTLRv4Parser.OPTIONAL: case ANTLRv4Parser.POSITIVE_CLOSURE: { this.lexerSubrule(); break; } case ANTLRv4Parser.ACTION: { const lookahead2 = this.input.lookahead(2); if (lookahead2 === Constants.Down) { const action = this.match(this.input, ANTLRv4Parser.ACTION); this.match(this.input, Constants.Down); this.elementOptions(); this.match(this.input, Constants.Up); this.actionInAlt(action); } else if (lookahead2 >= Constants.Up && lookahead2 <= ANTLRv4Parser.ACTION || lookahead2 === ANTLRv4Parser.LEXER_CHAR_SET || lookahead2 === ANTLRv4Parser.NOT || lookahead2 === ANTLRv4Parser.RANGE || lookahead2 === ANTLRv4Parser.RULE_REF || lookahead2 === ANTLRv4Parser.SEMPRED || lookahead2 === ANTLRv4Parser.STRING_LITERAL || lookahead2 === ANTLRv4Parser.TOKEN_REF || lookahead2 >= ANTLRv4Parser.BLOCK && lookahead2 <= ANTLRv4Parser.CLOSURE || lookahead2 === ANTLRv4Parser.EPSILON || lookahead2 >= ANTLRv4Parser.OPTIONAL && lookahead2 <= ANTLRv4Parser.POSITIVE_CLOSURE || lookahead2 >= ANTLRv4Parser.SET && lookahead2 <= ANTLRv4Parser.WILDCARD) { const action = this.match(this.input, ANTLRv4Parser.ACTION); this.actionInAlt(action); } else { const mark = this.input.mark(); try { this.input.consume(); throw new NoViableAltException(30, 3); } finally { this.input.release(mark); } } break; } case ANTLRv4Parser.SEMPRED: { const lookahead2 = this.input.lookahead(2); if (lookahead2 === Constants.Down) { const sempred = this.match(this.input, ANTLRv4Parser.SEMPRED); this.match(this.input, Constants.Down); this.elementOptions(); this.match(this.input, Constants.Up); this.sempredInAlt(sempred); } else if (lookahead2 >= Constants.Up && lookahead2 <= ANTLRv4Parser.ACTION || lookahead2 === ANTLRv4Parser.LEXER_CHAR_SET || lookahead2 === ANTLRv4Parser.NOT || lookahead2 === ANTLRv4Parser.RANGE || lookahead2 === ANTLRv4Parser.RULE_REF || lookahead2 === ANTLRv4Parser.SEMPRED || lookahead2 === ANTLRv4Parser.STRING_LITERAL || lookahead2 === ANTLRv4Parser.TOKEN_REF || lookahead2 >= ANTLRv4Parser.BLOCK && lookahead2 <= ANTLRv4Parser.CLOSURE || lookahead2 === ANTLRv4Parser.EPSILON || lookahead2 >= ANTLRv4Parser.OPTIONAL && lookahead2 <= ANTLRv4Parser.POSITIVE_CLOSURE || lookahead2 >= ANTLRv4Parser.SET && lookahead2 <= ANTLRv4Parser.WILDCARD) { const sempred = this.match(this.input, ANTLRv4Parser.SEMPRED); this.sempredInAlt(sempred); } else { const mark = this.input.mark(); try { this.input.consume(); throw new NoViableAltException(30, 4); } finally { this.input.release(mark); } } break; } case ANTLRv4Parser.EPSILON: { this.match(this.input, ANTLRv4Parser.EPSILON); break; } default: { throw new NoViableAltException(30, 0); } } this.exitLexerElement(start); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } lexerBlock() { try { this.match(this.input, ANTLRv4Parser.BLOCK); this.match(this.input, Constants.Down); if (this.input.lookahead(1) === ANTLRv4Parser.OPTIONS) { this.optionsSpec(); } let altCount = 0; while (true) { const lookahead = this.input.lookahead(1); if (lookahead === ANTLRv4Parser.ALT || lookahead === ANTLRv4Parser.LEXER_ALT_ACTION) { this.lexerAlternative(); } else { if (altCount >= 1) { break; } throw new EarlyExitException(32); } ++altCount; } this.match(this.input, Constants.Up); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } lexerAtom() { try { switch (this.input.lookahead(1)) { case ANTLRv4Parser.STRING_LITERAL: case ANTLRv4Parser.TOKEN_REF: { this.terminal(); break; } case ANTLRv4Parser.NOT: { this.match(this.input, ANTLRv4Parser.NOT); this.match(this.input, Constants.Down); this.blockSet(); this.match(this.input, Constants.Up); break; } case ANTLRv4Parser.SET: { this.blockSet(); break; } case ANTLRv4Parser.WILDCARD: { const lookahed2 = this.input.lookahead(2); if (lookahed2 === Constants.Down) { this.match(this.input, ANTLRv4Parser.WILDCARD); this.match(this.input, Constants.Down); this.elementOptions(); this.match(this.input, Constants.Up); } else if (lookahed2 >= Constants.Up && lookahed2 <= ANTLRv4Parser.ACTION || lookahed2 === ANTLRv4Parser.LEXER_CHAR_SET || lookahed2 === ANTLRv4Parser.NOT || lookahed2 === ANTLRv4Parser.RANGE || lookahed2 === ANTLRv4Parser.RULE_REF || lookahed2 === ANTLRv4Parser.SEMPRED || lookahed2 === ANTLRv4Parser.STRING_LITERAL || lookahed2 === ANTLRv4Parser.TOKEN_REF || lookahed2 >= ANTLRv4Parser.BLOCK && lookahed2 <= ANTLRv4Parser.CLOSURE || lookahed2 === ANTLRv4Parser.EPSILON || lookahed2 >= ANTLRv4Parser.OPTIONAL && lookahed2 <= ANTLRv4Parser.POSITIVE_CLOSURE || lookahed2 >= ANTLRv4Parser.SET && lookahed2 <= ANTLRv4Parser.WILDCARD) { this.match(this.input, ANTLRv4Parser.WILDCARD); } else { const mark = this.input.mark(); try { this.input.consume(); throw new NoViableAltException(33, 4); } finally { this.input.release(mark); } } break; } case ANTLRv4Parser.LEXER_CHAR_SET: { this.match(this.input, ANTLRv4Parser.LEXER_CHAR_SET); break; } case ANTLRv4Parser.RANGE: { this.range(); break; } case ANTLRv4Parser.RULE_REF: { this.ruleref(); break; } default: { throw new NoViableAltException(33, 0); } } } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } alternative() { const start = this.input.lookaheadType(1); this.enterAlternative(start); try { if (start.children[0]?.getType() === ANTLRv4Parser.EPSILON) { this.match(this.input, ANTLRv4Parser.ALT); this.match(this.input, Constants.Down); if (this.input.lookahead(1) === ANTLRv4Parser.ELEMENT_OPTIONS) { this.elementOptions(); } this.match(this.input, ANTLRv4Parser.EPSILON); this.match(this.input, Constants.Up); } else { this.match(this.input, ANTLRv4Parser.ALT); this.match(this.input, Constants.Down); if (this.input.lookahead(1) === ANTLRv4Parser.ELEMENT_OPTIONS) { this.elementOptions(); } let elementCount = 0; while (true) { const lookahead = this.input.lookahead(1); if (lookahead === ANTLRv4Parser.ACTION || lookahead === ANTLRv4Parser.ASSIGN || lookahead === ANTLRv4Parser.DOT || lookahead === ANTLRv4Parser.NOT || lookahead === ANTLRv4Parser.PLUS_ASSIGN || lookahead === ANTLRv4Parser.RANGE || lookahead === ANTLRv4Parser.RULE_REF || lookahead === ANTLRv4Parser.SEMPRED || lookahead === ANTLRv4Parser.STRING_LITERAL || lookahead === ANTLRv4Parser.TOKEN_REF || lookahead >= ANTLRv4Parser.BLOCK && lookahead <= ANTLRv4Parser.CLOSURE || lookahead >= ANTLRv4Parser.OPTIONAL && lookahead <= ANTLRv4Parser.POSITIVE_CLOSURE || lookahead >= ANTLRv4Parser.SET && lookahead <= ANTLRv4Parser.WILDCARD) { this.element(); } else { if (elementCount > 0) { break; } throw new EarlyExitException(36); } ++elementCount; } this.match(this.input, Constants.Up); } this.exitAlternative(start); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } lexerCommandExpr() { try { const lookahead = this.input.lookahead(1); if (lookahead === ANTLRv4Parser.ID || lookahead === ANTLRv4Parser.INT) { this.input.consume(); this.errorRecovery = false; } else { throw new MismatchedSetException(); } } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } element() { const start = this.input.lookaheadType(1); this.enterElement(start); try { let alt = 10; switch (this.input.lookahead(1)) { case ANTLRv4Parser.ASSIGN: case ANTLRv4Parser.PLUS_ASSIGN: { alt = 1; break; } case ANTLRv4Parser.DOT: case ANTLRv4Parser.RULE_REF: case ANTLRv4Parser.STRING_LITERAL: case ANTLRv4Parser.TOKEN_REF: case ANTLRv4Parser.SET: case ANTLRv4Parser.WILDCARD: { alt = 2; break; } case ANTLRv4Parser.BLOCK: case ANTLRv4Parser.CLOSURE: case ANTLRv4Parser.OPTIONAL: case ANTLRv4Parser.POSITIVE_CLOSURE: { alt = 3; break; } case ANTLRv4Parser.ACTION: { const lookahead2 = this.input.lookahead(2); if (lookahead2 === Constants.Down) { alt = 6; } else { if (lookahead2 >= Constants.Up && lookahead2 <= ANTLRv4Parser.ACTION || lookahead2 === ANTLRv4Parser.ASSIGN || lookahead2 === ANTLRv4Parser.DOT || lookahead2 === ANTLRv4Parser.NOT || lookahead2 === ANTLRv4Parser.PLUS_ASSIGN || lookahead2 === ANTLRv4Parser.RANGE || lookahead2 === ANTLRv4Parser.RULE_REF || lookahead2 === ANTLRv4Parser.SEMPRED || lookahead2 === ANTLRv4Parser.STRING_LITERAL || lookahead2 === ANTLRv4Parser.TOKEN_REF || lookahead2 >= ANTLRv4Parser.BLOCK && lookahead2 <= ANTLRv4Parser.CLOSURE || lookahead2 >= ANTLRv4Parser.OPTIONAL && lookahead2 <= ANTLRv4Parser.POSITIVE_CLOSURE || lookahead2 >= ANTLRv4Parser.SET && lookahead2 <= ANTLRv4Parser.WILDCARD) { alt = 4; } else { const mark = this.input.mark(); try { this.input.consume(); throw new NoViableAltException(40, 4); } finally { this.input.release(mark); } } } break; } case ANTLRv4Parser.SEMPRED: { const lookahead2 = this.input.lookahead(2); if (lookahead2 === Constants.Down) { alt = 7; } else { if (lookahead2 >= Constants.Up && lookahead2 <= ANTLRv4Parser.ACTION || lookahead2 === ANTLRv4Parser.ASSIGN || lookahead2 === ANTLRv4Parser.DOT || lookahead2 === ANTLRv4Parser.NOT || lookahead2 === ANTLRv4Parser.PLUS_ASSIGN || lookahead2 === ANTLRv4Parser.RANGE || lookahead2 === ANTLRv4Parser.RULE_REF || lookahead2 === ANTLRv4Parser.SEMPRED || lookahead2 === ANTLRv4Parser.STRING_LITERAL || lookahead2 === ANTLRv4Parser.TOKEN_REF || lookahead2 >= ANTLRv4Parser.BLOCK && lookahead2 <= ANTLRv4Parser.CLOSURE || lookahead2 >= ANTLRv4Parser.OPTIONAL && lookahead2 <= ANTLRv4Parser.POSITIVE_CLOSURE || lookahead2 >= ANTLRv4Parser.SET && lookahead2 <= ANTLRv4Parser.WILDCARD) { alt = 5; } else { const mark = this.input.mark(); try { this.input.consume(); throw new NoViableAltException(40, 5); } finally { this.input.release(mark); } } } break; } case ANTLRv4Parser.RANGE: { alt = 8; break; } case ANTLRv4Parser.NOT: { const lookahead2 = this.input.lookahead(2); if (lookahead2 === Constants.Down) { const lookahead3 = this.input.lookahead(3); if (lookahead3 === ANTLRv4Parser.SET) { alt = 9; } else if (lookahead3 === ANTLRv4Parser.BLOCK) { alt = 10; } else { const mark = this.input.mark(); try { this.input.consume(); this.input.consume(); throw new NoViableAltException(40, 12); } finally { this.input.release(mark); } } } else { const mark = this.input.mark(); try { this.input.consume(); throw new NoViableAltException(40, 7); } finally { this.input.release(mark); } } break; } default: { throw new NoViableAltException(40, 0); } } switch (alt) { case 1: { this.labeledElement(); break; } case 2: { this.atom(); break; } case 3: { this.subrule(); break; } case 4: { const action = this.match(this.input, ANTLRv4Parser.ACTION); this.actionInAlt(action); break; } case 5: { const sempred = this.match(this.input, ANTLRv4Parser.SEMPRED); this.sempredInAlt(sempred); break; } case 6: { const action = this.match(this.input, ANTLRv4Parser.ACTION); this.match(this.input, Constants.Down); this.elementOptions(); this.match(this.input, Constants.Up); this.actionInAlt(action); break; } case 7: { const sempred = this.match(this.input, ANTLRv4Parser.SEMPRED); this.match(this.input, Constants.Down); this.elementOptions(); this.match(this.input, Constants.Up); this.sempredInAlt(sempred); break; } case 8: { this.range(); break; } case 9: { this.match(this.input, ANTLRv4Parser.NOT); this.match(this.input, Constants.Down); this.blockSet(); this.match(this.input, Constants.Up); break; } case 10: { this.match(this.input, ANTLRv4Parser.NOT); this.match(this.input, Constants.Down); this.block(); this.match(this.input, Constants.Up); break; } default: } this.exitElement(start); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } return start; } labeledElement() { const start = this.input.lookaheadType(1); try { if (this.input.lookahead(1) === ANTLRv4Parser.ASSIGN || this.input.lookahead(1) === ANTLRv4Parser.PLUS_ASSIGN) { this.input.consume(); this.errorRecovery = false; } else { throw new MismatchedSetException(); } this.match(this.input, Constants.Down); const id = this.match(this.input, ANTLRv4Parser.ID); const element = this.element(); this.match(this.input, Constants.Up); this.label(start, id, element); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } subrule() { const start = this.input.lookaheadType(1); try { const lookahead = this.input.lookahead(1); if (lookahead === ANTLRv4Parser.CLOSURE || lookahead >= ANTLRv4Parser.OPTIONAL && lookahead <= ANTLRv4Parser.POSITIVE_CLOSURE) { this.blockSuffix(); this.match(this.input, Constants.Down); this.block(); this.match(this.input, Constants.Up); } else if (lookahead === ANTLRv4Parser.BLOCK) { this.block(); } else { throw new NoViableAltException(42, 0); } this.exitSubrule(start); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } lexerSubrule() { const start = this.input.lookaheadType(1); try { const lookahead = this.input.lookahead(1); if (lookahead === ANTLRv4Parser.CLOSURE || lookahead >= ANTLRv4Parser.OPTIONAL && lookahead <= ANTLRv4Parser.POSITIVE_CLOSURE) { this.blockSuffix(); this.match(this.input, Constants.Down); this.lexerBlock(); this.match(this.input, Constants.Up); } else if (lookahead === ANTLRv4Parser.BLOCK) { this.lexerBlock(); } else { throw new NoViableAltException(43, 0); } this.exitLexerSubrule(start); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } blockSuffix() { try { this.ebnfSuffix(); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } ebnfSuffix() { try { const lookahead = this.input.lookahead(1); if (lookahead === ANTLRv4Parser.CLOSURE || lookahead >= ANTLRv4Parser.OPTIONAL && lookahead <= ANTLRv4Parser.POSITIVE_CLOSURE) { this.input.consume(); this.errorRecovery = false; } else { throw new MismatchedSetException(); } } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } atom() { try { let alt = 7; switch (this.input.lookahead(1)) { case ANTLRv4Parser.DOT: { const lookahead2 = this.input.lookahead(2); if (lookahead2 === Constants.Down) { const lookahead3 = this.input.lookahead(3); if (lookahead3 === ANTLRv4Parser.ID) { const lookahead4 = this.input.lookahead(4); if (lookahead4 === ANTLRv4Parser.STRING_LITERAL || lookahead4 === ANTLRv4Parser.TOKEN_REF) { alt = 1; } else if (lookahead4 === ANTLRv4Parser.RULE_REF) { alt = 2; } else { const mark = this.input.mark(); try { this.input.consume(); this.input.consume(); this.input.consume(); throw new NoViableAltException(44, 9); } finally { this.input.release(mark); } } } else { const mark = this.input.mark(); try { this.input.consume(); this.input.consume(); throw new NoViableAltException(44, 6); } finally { this.input.release(mark); } } } else { const mark = this.input.mark(); try { this.input.consume(); throw new NoViableAltException(44, 1); } finally { this.input.release(mark); } } break; } case ANTLRv4Parser.WILDCARD: { const lookahead2 = this.input.lookahead(2); if (lookahead2 === Constants.Down) { alt = 3; } else { if (lookahead2 === ANTLRv4Parser.EOF || lookahead2 >= Constants.Up && lookahead2 <= ANTLRv4Parser.ACTION || lookahead2 === ANTLRv4Parser.ASSIGN || lookahead2 === ANTLRv4Parser.DOT || lookahead2 === ANTLRv4Parser.NOT || lookahead2 === ANTLRv4Parser.PLUS_ASSIGN || lookahead2 === ANTLRv4Parser.RANGE || lookahead2 === ANTLRv4Parser.RULE_REF || lookahead2 === ANTLRv4Parser.SEMPRED || lookahead2 === ANTLRv4Parser.STRING_LITERAL || lookahead2 === ANTLRv4Parser.TOKEN_REF || lookahead2 >= ANTLRv4Parser.BLOCK && lookahead2 <= ANTLRv4Parser.CLOSURE || lookahead2 >= ANTLRv4Parser.OPTIONAL && lookahead2 <= ANTLRv4Parser.POSITIVE_CLOSURE || lookahead2 >= ANTLRv4Parser.SET && lookahead2 <= ANTLRv4Parser.WILDCARD) { alt = 4; } else { const mark = this.input.mark(); try { this.input.consume(); throw new NoViableAltException(44, 2); } finally { this.input.release(mark); } } } break; } case ANTLRv4Parser.STRING_LITERAL: case ANTLRv4Parser.TOKEN_REF: { alt = 5; break; } case ANTLRv4Parser.SET: { alt = 6; break; } case ANTLRv4Parser.RULE_REF: { alt = 7; break; } default: { throw new NoViableAltException(44, 0); } } switch (alt) { case 1: { this.match(this.input, ANTLRv4Parser.DOT); this.match(this.input, Constants.Down); this.match(this.input, ANTLRv4Parser.ID); this.terminal(); this.match(this.input, Constants.Up); break; } case 2: { this.match(this.input, ANTLRv4Parser.DOT); this.match(this.input, Constants.Down); this.match(this.input, ANTLRv4Parser.ID); this.ruleref(); this.match(this.input, Constants.Up); break; } case 3: { this.match(this.input, ANTLRv4Parser.WILDCARD); this.match(this.input, Constants.Down); this.elementOptions(); this.match(this.input, Constants.Up); break; } case 4: { this.match(this.input, ANTLRv4Parser.WILDCARD); break; } case 5: { this.terminal(); break; } case 6: { this.blockSet(); break; } case 7: { this.ruleref(); break; } default: } } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } blockSet() { const start = this.input.lookaheadType(1); this.enterBlockSet(start); try { this.match(this.input, ANTLRv4Parser.SET); this.match(this.input, Constants.Down); let setElementCount = 0; while (true) { const lookahead = this.input.lookahead(1); if (lookahead === ANTLRv4Parser.LEXER_CHAR_SET || lookahead === ANTLRv4Parser.RANGE || lookahead === ANTLRv4Parser.STRING_LITERAL || lookahead === ANTLRv4Parser.TOKEN_REF) { this.setElement(); } else { if (setElementCount >= 1) { break; } throw new EarlyExitException(45); } ++setElementCount; } this.match(this.input, Constants.Up); this.exitBlockSet(start); } catch (re) { if (re instanceof RecognitionException) { this.reportError(re); } else { throw re; } } } setElement() { try { switch (this.input.lookahead(1)) { case ANTLRv4Parser.STRING_LITERAL: { const lookahead2 = this.input.lookahead(2); if (lookahead2 === Constants.Down) { const