antlr-ng
Version:
Next generation ANTLR Tool
1,028 lines (1,027 loc) • 39.6 kB
JavaScript
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
import { RecognitionException } from "antlr4ng";
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 { ANTLRv4Lexer } from "../../generated/ANTLRv4Lexer.js";
class ATNBuilder extends TreeParser {
constructor(errorManager, input, factory) {
super(errorManager, input);
this.factory = factory;
}
static {
__name(this, "ATNBuilder");
}
ruleBlock(ebnfRoot) {
this.factory.currentOuterAlt = 1;
try {
const block = this.match(this.input, ANTLRv4Lexer.BLOCK);
this.match(this.input, Constants.Down);
if (this.input.lookahead(1) === ANTLRv4Lexer.OPTIONS) {
this.match(this.input, ANTLRv4Lexer.OPTIONS);
if (this.input.lookahead(1) === Constants.Down) {
this.match(this.input, Constants.Down);
while (true) {
const lookahead = this.input.lookahead(1);
if (lookahead >= ANTLRv4Lexer.ACTION && lookahead <= ANTLRv4Lexer.WILDCARD) {
this.matchAny();
} else {
if (lookahead === Constants.Up) {
break;
}
}
}
this.match(this.input, Constants.Up);
}
}
let altCount = 0;
const alts = new Array();
let currentAlt = 1;
while (true) {
const lookahead = this.input.lookahead(1);
if (lookahead === ANTLRv4Lexer.ALT || lookahead === ANTLRv4Lexer.LEXER_ALT_ACTION) {
const alt = this.alternative();
if (alt) {
alts.push(alt);
}
this.factory.currentOuterAlt = ++currentAlt;
} else {
if (altCount >= 1) {
break;
}
throw new EarlyExitException(3);
}
++altCount;
}
this.match(this.input, Constants.Up);
return this.factory.block(block, ebnfRoot, alts);
} catch (re) {
if (re instanceof RecognitionException) {
this.reportError(re);
return void 0;
} else {
throw re;
}
}
}
block(ebnfRoot) {
try {
const block = this.match(this.input, ANTLRv4Lexer.BLOCK);
this.match(this.input, Constants.Down);
if (this.input.lookahead(1) === ANTLRv4Lexer.OPTIONS) {
this.match(this.input, ANTLRv4Lexer.OPTIONS);
if (this.input.lookahead(1) === Constants.Down) {
this.match(this.input, Constants.Down);
while (true) {
const lookahead = this.input.lookahead(1);
if (lookahead >= ANTLRv4Lexer.ACTION && lookahead <= ANTLRv4Lexer.WILDCARD) {
this.matchAny();
} else {
if (lookahead === Constants.Up) {
break;
}
}
}
this.match(this.input, Constants.Up);
}
}
let altCount = 0;
const alts = new Array();
while (true) {
const lookahead = this.input.lookahead(1);
if (lookahead === ANTLRv4Lexer.ALT || lookahead === ANTLRv4Lexer.LEXER_ALT_ACTION) {
const alt = this.alternative();
if (alt) {
alts.push(alt);
}
} else {
if (altCount >= 1) {
break;
}
throw new EarlyExitException(6);
}
altCount++;
}
this.match(this.input, Constants.Up);
return this.factory.block(block, ebnfRoot, alts);
} catch (re) {
if (re instanceof RecognitionException) {
this.reportError(re);
return void 0;
} else {
throw re;
}
}
}
alternative() {
try {
if (this.input.lookahead(1) === ANTLRv4Lexer.LEXER_ALT_ACTION) {
this.match(this.input, ANTLRv4Lexer.LEXER_ALT_ACTION);
this.match(this.input, Constants.Down);
const a = this.alternative();
const commands = this.lexerCommands();
this.match(this.input, Constants.Up);
if (a && commands) {
return this.factory.lexerAltCommands(a, commands);
}
return void 0;
} else {
const current = this.input.lookaheadType(1);
if (current.children[0].getType() === ANTLRv4Lexer.EPSILON) {
this.match(this.input, ANTLRv4Lexer.ALT);
this.match(this.input, Constants.Down);
if (this.input.lookahead(1) === ANTLRv4Lexer.ELEMENT_OPTIONS) {
this.elementOptions();
}
const epsilon = this.match(this.input, ANTLRv4Lexer.EPSILON);
this.match(this.input, Constants.Up);
return this.factory.epsilon(epsilon);
} else {
this.match(this.input, ANTLRv4Lexer.ALT);
this.match(this.input, Constants.Down);
if (this.input.lookahead(1) === ANTLRv4Lexer.ELEMENT_OPTIONS) {
this.elementOptions();
}
let cnt9 = 0;
const els = new Array();
while (true) {
const lookahead = this.input.lookahead(1);
if (lookahead === ANTLRv4Lexer.ACTION || lookahead === ANTLRv4Lexer.ASSIGN || lookahead === ANTLRv4Lexer.DOT || lookahead === ANTLRv4Lexer.LEXER_CHAR_SET || lookahead === ANTLRv4Lexer.NOT || lookahead === ANTLRv4Lexer.PLUS_ASSIGN || lookahead === ANTLRv4Lexer.RANGE || lookahead === ANTLRv4Lexer.RULE_REF || lookahead === ANTLRv4Lexer.SEMPRED || lookahead === ANTLRv4Lexer.STRING_LITERAL || lookahead === ANTLRv4Lexer.TOKEN_REF || lookahead >= ANTLRv4Lexer.BLOCK && lookahead <= ANTLRv4Lexer.CLOSURE || lookahead >= ANTLRv4Lexer.OPTIONAL && lookahead <= ANTLRv4Lexer.POSITIVE_CLOSURE || lookahead >= ANTLRv4Lexer.SET && lookahead <= ANTLRv4Lexer.WILDCARD) {
const e = this.element();
if (e) {
els.push(e);
}
} else {
if (cnt9 >= 1) {
break;
}
throw new EarlyExitException(9);
}
cnt9++;
}
this.match(this.input, Constants.Up);
return this.factory.alt(els);
}
}
} catch (re) {
if (re instanceof RecognitionException) {
this.reportError(re);
return void 0;
} else {
throw re;
}
}
}
lexerCommands() {
try {
let commandCount = 0;
const commands = new Array();
while (true) {
const lookahead = this.input.lookahead(1);
if (lookahead === ANTLRv4Lexer.ID || lookahead === ANTLRv4Lexer.LEXER_ACTION_CALL) {
const c = this.lexerCommand();
if (c) {
commands.push(c);
}
} else {
if (commandCount >= 1) {
break;
}
throw new EarlyExitException(11);
}
++commandCount;
}
return this.factory.alt(commands);
} catch (re) {
if (re instanceof RecognitionException) {
this.reportError(re);
return void 0;
} else {
throw re;
}
}
}
lexerCommand() {
try {
const lookahead = this.input.lookahead(1);
if (lookahead === ANTLRv4Lexer.LEXER_ACTION_CALL) {
this.match(this.input, ANTLRv4Lexer.LEXER_ACTION_CALL);
this.match(this.input, Constants.Down);
const id = this.match(this.input, ANTLRv4Lexer.ID);
const expression = this.lexerCommandExpr();
this.match(this.input, Constants.Up);
if (!expression) {
return void 0;
}
return this.factory.lexerCallCommand(id, expression);
} else if (lookahead === ANTLRv4Lexer.ID) {
const id = this.match(this.input, ANTLRv4Lexer.ID);
return this.factory.lexerCommand(id);
} else {
throw new NoViableAltException(12, 0);
}
} catch (re) {
if (re instanceof RecognitionException) {
this.reportError(re);
return void 0;
} else {
throw re;
}
}
}
lexerCommandExpr() {
const result = this.input.lookaheadType(1) ?? void 0;
try {
if (this.input.lookahead(1) === ANTLRv4Lexer.ID || this.input.lookahead(1) === ANTLRv4Lexer.INT) {
this.input.consume();
this.errorRecovery = false;
} else {
throw new MismatchedSetException();
}
} catch (re) {
if (re instanceof RecognitionException) {
this.reportError(re);
} else {
throw re;
}
}
return result;
}
element() {
let result;
const start = this.input.lookaheadType(1);
try {
switch (this.input.lookahead(1)) {
case ANTLRv4Lexer.ASSIGN:
case ANTLRv4Lexer.PLUS_ASSIGN: {
result = this.labeledElement();
break;
}
case ANTLRv4Lexer.DOT:
case ANTLRv4Lexer.RANGE:
case ANTLRv4Lexer.RULE_REF:
case ANTLRv4Lexer.STRING_LITERAL:
case ANTLRv4Lexer.TOKEN_REF:
case ANTLRv4Lexer.SET:
case ANTLRv4Lexer.WILDCARD: {
result = this.atom();
break;
}
case ANTLRv4Lexer.BLOCK:
case ANTLRv4Lexer.CLOSURE:
case ANTLRv4Lexer.OPTIONAL:
case ANTLRv4Lexer.POSITIVE_CLOSURE: {
result = this.subrule();
break;
}
case ANTLRv4Lexer.ACTION: {
const lookahead = this.input.lookahead(2);
if (lookahead === Constants.Down) {
const action = this.match(this.input, ANTLRv4Lexer.ACTION);
this.match(this.input, Constants.Down);
this.matchAny();
this.match(this.input, Constants.Up);
result = this.factory.action(action);
} else if (lookahead >= Constants.Up && lookahead <= ANTLRv4Lexer.ACTION || lookahead === ANTLRv4Lexer.ASSIGN || lookahead === ANTLRv4Lexer.DOT || lookahead === ANTLRv4Lexer.LEXER_CHAR_SET || lookahead === ANTLRv4Lexer.NOT || lookahead === ANTLRv4Lexer.PLUS_ASSIGN || lookahead === ANTLRv4Lexer.RANGE || lookahead === ANTLRv4Lexer.RULE_REF || lookahead === ANTLRv4Lexer.SEMPRED || lookahead === ANTLRv4Lexer.STRING_LITERAL || lookahead === ANTLRv4Lexer.TOKEN_REF || lookahead >= ANTLRv4Lexer.BLOCK && lookahead <= ANTLRv4Lexer.CLOSURE || lookahead >= ANTLRv4Lexer.OPTIONAL && lookahead <= ANTLRv4Lexer.POSITIVE_CLOSURE || lookahead >= ANTLRv4Lexer.SET && lookahead <= ANTLRv4Lexer.WILDCARD) {
const action = this.match(this.input, ANTLRv4Lexer.ACTION);
result = this.factory.action(action);
} else {
const mark = this.input.mark();
const lastIndex = this.input.index;
try {
this.input.consume();
throw new NoViableAltException(13, 4);
} finally {
this.input.seek(lastIndex);
this.input.release(mark);
}
}
break;
}
case ANTLRv4Lexer.SEMPRED: {
const lookahead = this.input.lookahead(2);
if (lookahead === Constants.Down) {
const sempred = this.match(this.input, ANTLRv4Lexer.SEMPRED);
this.match(this.input, Constants.Down);
this.matchAny();
this.match(this.input, Constants.Up);
result = this.factory.sempred(sempred);
} else if (lookahead >= Constants.Up && lookahead <= ANTLRv4Lexer.ACTION || lookahead === ANTLRv4Lexer.ASSIGN || lookahead === ANTLRv4Lexer.DOT || lookahead === ANTLRv4Lexer.LEXER_CHAR_SET || lookahead === ANTLRv4Lexer.NOT || lookahead === ANTLRv4Lexer.PLUS_ASSIGN || lookahead === ANTLRv4Lexer.RANGE || lookahead === ANTLRv4Lexer.RULE_REF || lookahead === ANTLRv4Lexer.SEMPRED || lookahead === ANTLRv4Lexer.STRING_LITERAL || lookahead === ANTLRv4Lexer.TOKEN_REF || lookahead >= ANTLRv4Lexer.BLOCK && lookahead <= ANTLRv4Lexer.CLOSURE || lookahead >= ANTLRv4Lexer.OPTIONAL && lookahead <= ANTLRv4Lexer.POSITIVE_CLOSURE || lookahead >= ANTLRv4Lexer.SET && lookahead <= ANTLRv4Lexer.WILDCARD) {
const sempred = this.match(this.input, ANTLRv4Lexer.SEMPRED);
result = this.factory.sempred(sempred);
} else {
const mark = this.input.mark();
const lastIndex = this.input.index;
try {
this.input.consume();
throw new NoViableAltException(13, 5);
} finally {
this.input.seek(lastIndex);
this.input.release(mark);
}
}
break;
}
case ANTLRv4Lexer.NOT: {
this.match(this.input, ANTLRv4Lexer.NOT);
this.match(this.input, Constants.Down);
result = this.blockSet(true);
this.match(this.input, Constants.Up);
break;
}
case ANTLRv4Lexer.LEXER_CHAR_SET: {
this.match(this.input, ANTLRv4Lexer.LEXER_CHAR_SET);
result = this.factory.charSetLiteral(start);
break;
}
default: {
throw new NoViableAltException(13, 0);
}
}
} catch (re) {
if (re instanceof RecognitionException) {
this.reportError(re);
} else {
throw re;
}
}
return result;
}
labeledElement() {
try {
const lookahead = this.input.lookahead(1);
if (lookahead === ANTLRv4Lexer.ASSIGN) {
this.match(this.input, ANTLRv4Lexer.ASSIGN);
this.match(this.input, Constants.Down);
this.match(this.input, ANTLRv4Lexer.ID);
const element = this.element();
this.match(this.input, Constants.Up);
if (element) {
return this.factory.label(element);
}
return void 0;
} else {
if (lookahead === ANTLRv4Lexer.PLUS_ASSIGN) {
this.match(this.input, ANTLRv4Lexer.PLUS_ASSIGN);
this.match(this.input, Constants.Down);
this.match(this.input, ANTLRv4Lexer.ID);
const element = this.element();
this.match(this.input, Constants.Up);
if (element) {
return this.factory.listLabel(element);
}
return void 0;
} else {
throw new NoViableAltException(15, 0);
}
}
} catch (re) {
if (re instanceof RecognitionException) {
this.reportError(re);
return void 0;
} else {
throw re;
}
}
}
subrule() {
let result;
const start = this.input.lookaheadType(1);
try {
switch (this.input.lookahead(1)) {
case ANTLRv4Lexer.OPTIONAL: {
this.match(this.input, ANTLRv4Lexer.OPTIONAL);
this.match(this.input, Constants.Down);
result = this.block(start);
this.match(this.input, Constants.Up);
break;
}
case ANTLRv4Lexer.CLOSURE: {
this.match(this.input, ANTLRv4Lexer.CLOSURE);
this.match(this.input, Constants.Down);
result = this.block(start);
this.match(this.input, Constants.Up);
break;
}
case ANTLRv4Lexer.POSITIVE_CLOSURE: {
this.match(this.input, ANTLRv4Lexer.POSITIVE_CLOSURE);
this.match(this.input, Constants.Down);
result = this.block(start);
this.match(this.input, Constants.Up);
break;
}
case ANTLRv4Lexer.BLOCK: {
result = this.block(null);
break;
}
default: {
throw new NoViableAltException(16, 0);
}
}
} catch (re) {
if (re instanceof RecognitionException) {
this.reportError(re);
} else {
throw re;
}
}
return result;
}
blockSet(invert) {
try {
const start = this.input.lookaheadType(1);
this.match(this.input, ANTLRv4Lexer.SET);
this.match(this.input, Constants.Down);
let elementCount = 0;
const alts = new Array();
while (true) {
const lookahead = this.input.lookahead(1);
if (lookahead === ANTLRv4Lexer.LEXER_CHAR_SET || lookahead === ANTLRv4Lexer.RANGE || lookahead === ANTLRv4Lexer.STRING_LITERAL || lookahead === ANTLRv4Lexer.TOKEN_REF) {
const element = this.setElement();
if (element) {
alts.push(element);
}
} else {
if (elementCount >= 1) {
break;
}
throw new EarlyExitException(17);
}
++elementCount;
}
this.match(this.input, Constants.Up);
return this.factory.set(start, alts, invert);
} catch (re) {
if (re instanceof RecognitionException) {
this.reportError(re);
return void 0;
} else {
throw re;
}
}
}
setElement() {
const start = this.input.lookaheadType(1);
try {
switch (this.input.lookahead(1)) {
case ANTLRv4Lexer.STRING_LITERAL: {
const lookahead = this.input.lookahead(2);
if (lookahead === Constants.Down) {
this.match(this.input, ANTLRv4Lexer.STRING_LITERAL);
this.match(this.input, Constants.Down);
this.matchAny();
this.match(this.input, Constants.Up);
} else if (lookahead === Constants.Up || lookahead === ANTLRv4Lexer.LEXER_CHAR_SET || lookahead === ANTLRv4Lexer.RANGE || lookahead === ANTLRv4Lexer.STRING_LITERAL || lookahead === ANTLRv4Lexer.TOKEN_REF) {
this.match(this.input, ANTLRv4Lexer.STRING_LITERAL);
} else {
const mark = this.input.mark();
const lastIndex = this.input.index;
try {
this.input.consume();
throw new NoViableAltException(18, 1);
} finally {
this.input.seek(lastIndex);
this.input.release(mark);
}
}
break;
}
case ANTLRv4Lexer.TOKEN_REF: {
const lookahead = this.input.lookahead(2);
if (lookahead === Constants.Down) {
this.match(this.input, ANTLRv4Lexer.TOKEN_REF);
this.match(this.input, Constants.Down);
this.matchAny();
this.match(this.input, Constants.Up);
} else if (lookahead === Constants.Up || lookahead === ANTLRv4Lexer.LEXER_CHAR_SET || lookahead === ANTLRv4Lexer.RANGE || lookahead === ANTLRv4Lexer.STRING_LITERAL || lookahead === ANTLRv4Lexer.TOKEN_REF) {
this.match(this.input, ANTLRv4Lexer.TOKEN_REF);
} else {
const mark = this.input.mark();
const lastIndex = this.input.index;
try {
this.input.consume();
throw new NoViableAltException(18, 2);
} finally {
this.input.seek(lastIndex);
this.input.release(mark);
}
}
break;
}
case ANTLRv4Lexer.RANGE: {
this.match(this.input, ANTLRv4Lexer.RANGE);
this.match(this.input, Constants.Down);
this.match(this.input, ANTLRv4Lexer.STRING_LITERAL);
this.match(this.input, ANTLRv4Lexer.STRING_LITERAL);
this.match(this.input, Constants.Up);
break;
}
case ANTLRv4Lexer.LEXER_CHAR_SET: {
this.match(this.input, ANTLRv4Lexer.LEXER_CHAR_SET);
break;
}
default: {
throw new NoViableAltException(18, 0);
}
}
} catch (re) {
if (re instanceof RecognitionException) {
this.reportError(re);
} else {
throw re;
}
}
return start;
}
atom() {
try {
const start = this.input.lookaheadType(1);
switch (this.input.lookahead(1)) {
case ANTLRv4Lexer.RANGE: {
return this.range();
}
case ANTLRv4Lexer.DOT: {
const lookahead2 = this.input.lookahead(2);
if (lookahead2 === Constants.Down) {
const lookahead3 = this.input.lookahead(3);
if (lookahead3 === ANTLRv4Lexer.ID) {
const lookahead4 = this.input.lookahead(4);
if (lookahead4 === ANTLRv4Lexer.STRING_LITERAL || lookahead4 === ANTLRv4Lexer.TOKEN_REF) {
this.match(this.input, ANTLRv4Lexer.DOT);
this.match(this.input, Constants.Down);
this.match(this.input, ANTLRv4Lexer.ID);
const result = this.terminal();
this.match(this.input, Constants.Up);
return result;
} else if (lookahead4 === ANTLRv4Lexer.RULE_REF) {
this.match(this.input, ANTLRv4Lexer.DOT);
this.match(this.input, Constants.Down);
this.match(this.input, ANTLRv4Lexer.ID);
const result = this.ruleref();
this.match(this.input, Constants.Up);
return result;
} else {
const mark = this.input.mark();
const lastIndex = this.input.index;
try {
this.input.consume();
this.input.consume();
this.input.consume();
throw new NoViableAltException(19, 10);
} finally {
this.input.seek(lastIndex);
this.input.release(mark);
}
}
} else {
const mark = this.input.mark();
const lastIndex = this.input.index;
try {
this.input.consume();
this.input.consume();
throw new NoViableAltException(19, 7);
} finally {
this.input.seek(lastIndex);
this.input.release(mark);
}
}
} else {
const mark = this.input.mark();
const lastIndex = this.input.index;
try {
this.input.consume();
throw new NoViableAltException(19, 2);
} finally {
this.input.seek(lastIndex);
this.input.release(mark);
}
}
}
case ANTLRv4Lexer.WILDCARD: {
const lookahead2 = this.input.lookahead(2);
if (lookahead2 === Constants.Down) {
this.match(this.input, ANTLRv4Lexer.WILDCARD);
this.match(this.input, Constants.Down);
this.matchAny();
this.match(this.input, Constants.Up);
return this.factory.wildcard(start);
} else if (lookahead2 === ANTLRv4Lexer.EOF || lookahead2 >= Constants.Up && lookahead2 <= ANTLRv4Lexer.ACTION || lookahead2 === ANTLRv4Lexer.ASSIGN || lookahead2 === ANTLRv4Lexer.DOT || lookahead2 === ANTLRv4Lexer.LEXER_CHAR_SET || lookahead2 === ANTLRv4Lexer.NOT || lookahead2 === ANTLRv4Lexer.PLUS_ASSIGN || lookahead2 === ANTLRv4Lexer.RANGE || lookahead2 === ANTLRv4Lexer.RULE_REF || lookahead2 === ANTLRv4Lexer.SEMPRED || lookahead2 === ANTLRv4Lexer.STRING_LITERAL || lookahead2 === ANTLRv4Lexer.TOKEN_REF || lookahead2 >= ANTLRv4Lexer.BLOCK && lookahead2 <= ANTLRv4Lexer.CLOSURE || lookahead2 >= ANTLRv4Lexer.OPTIONAL && lookahead2 <= ANTLRv4Lexer.POSITIVE_CLOSURE || lookahead2 >= ANTLRv4Lexer.SET && lookahead2 <= ANTLRv4Lexer.WILDCARD) {
this.match(this.input, ANTLRv4Lexer.WILDCARD);
return this.factory.wildcard(start);
} else {
const mark = this.input.mark();
const lastIndex = this.input.index;
try {
this.input.consume();
throw new NoViableAltException(19, 3);
} finally {
this.input.seek(lastIndex);
this.input.release(mark);
}
}
}
case ANTLRv4Lexer.SET: {
return this.blockSet(false);
}
case ANTLRv4Lexer.STRING_LITERAL:
case ANTLRv4Lexer.TOKEN_REF: {
return this.terminal();
}
case ANTLRv4Lexer.RULE_REF: {
return this.ruleref() ?? void 0;
}
default: {
throw new NoViableAltException(19, 0);
}
}
} catch (re) {
if (re instanceof RecognitionException) {
this.reportError(re);
return void 0;
} else {
throw re;
}
}
}
ruleref() {
try {
let alt = -1;
const lookahead = this.input.lookahead(1);
if (lookahead === ANTLRv4Lexer.RULE_REF) {
const lookahead2 = this.input.lookahead(2);
if (lookahead2 === Constants.Down) {
switch (this.input.lookahead(3)) {
case ANTLRv4Lexer.ARG_ACTION: {
const lookahead4 = this.input.lookahead(4);
if (lookahead4 === ANTLRv4Lexer.ELEMENT_OPTIONS) {
alt = 1;
} else {
if (lookahead4 === Constants.Up) {
alt = 2;
} else {
const mark = this.input.mark();
const lastIndex = this.input.index;
try {
this.input.consume();
this.input.consume();
this.input.consume();
throw new NoViableAltException(23, 4);
} finally {
this.input.seek(lastIndex);
this.input.release(mark);
}
}
}
break;
}
case ANTLRv4Lexer.ELEMENT_OPTIONS: {
alt = 1;
break;
}
case Constants.Up: {
alt = 2;
break;
}
default: {
const mark = this.input.mark();
const lastIndex = this.input.index;
try {
this.input.consume();
this.input.consume();
throw new NoViableAltException(23, 2);
} finally {
this.input.seek(lastIndex);
this.input.release(mark);
}
}
}
} else if (lookahead2 === ANTLRv4Lexer.EOF || lookahead2 >= Constants.Up && lookahead2 <= ANTLRv4Lexer.ACTION || lookahead2 === ANTLRv4Lexer.ASSIGN || lookahead2 === ANTLRv4Lexer.DOT || lookahead2 === ANTLRv4Lexer.LEXER_CHAR_SET || lookahead2 === ANTLRv4Lexer.NOT || lookahead2 === ANTLRv4Lexer.PLUS_ASSIGN || lookahead2 === ANTLRv4Lexer.RANGE || lookahead2 === ANTLRv4Lexer.RULE_REF || lookahead2 === ANTLRv4Lexer.SEMPRED || lookahead2 === ANTLRv4Lexer.STRING_LITERAL || lookahead2 === ANTLRv4Lexer.TOKEN_REF || lookahead2 >= ANTLRv4Lexer.BLOCK && lookahead2 <= ANTLRv4Lexer.CLOSURE || lookahead2 >= ANTLRv4Lexer.OPTIONAL && lookahead2 <= ANTLRv4Lexer.POSITIVE_CLOSURE || lookahead2 >= ANTLRv4Lexer.SET && lookahead2 <= ANTLRv4Lexer.WILDCARD) {
const ruleRef = this.match(this.input, ANTLRv4Lexer.RULE_REF);
return this.factory.ruleRef(ruleRef) ?? void 0;
} else {
const mark = this.input.mark();
const lastIndex = this.input.index;
try {
this.input.consume();
throw new NoViableAltException(23, 1);
} finally {
this.input.seek(lastIndex);
this.input.release(mark);
}
}
} else {
throw new NoViableAltException(23, 0);
}
switch (alt) {
case 1: {
const ruleRef = this.match(this.input, ANTLRv4Lexer.RULE_REF);
this.match(this.input, Constants.Down);
const lookahead2 = this.input.lookahead(1);
if (lookahead2 === ANTLRv4Lexer.ARG_ACTION) {
this.match(this.input, ANTLRv4Lexer.ARG_ACTION);
}
this.match(this.input, ANTLRv4Lexer.ELEMENT_OPTIONS);
if (this.input.lookahead(1) === Constants.Down) {
this.match(this.input, Constants.Down);
while (true) {
const lookahead3 = this.input.lookahead(1);
if (lookahead3 >= ANTLRv4Lexer.ACTION && lookahead3 <= ANTLRv4Lexer.WILDCARD) {
this.matchAny();
} else if (lookahead3 === Constants.Up) {
break;
}
}
this.match(this.input, Constants.Up);
}
this.match(this.input, Constants.Up);
return this.factory.ruleRef(ruleRef) ?? void 0;
}
case 2: {
const ruleRef = this.match(this.input, ANTLRv4Lexer.RULE_REF);
if (this.input.lookahead(1) === Constants.Down) {
this.match(this.input, Constants.Down);
if (this.input.lookahead(1) === ANTLRv4Lexer.ARG_ACTION) {
this.match(this.input, ANTLRv4Lexer.ARG_ACTION);
}
this.match(this.input, Constants.Up);
}
return this.factory.ruleRef(ruleRef) ?? void 0;
}
default: {
return void 0;
}
}
} catch (re) {
if (re instanceof RecognitionException) {
this.reportError(re);
return void 0;
} else {
throw re;
}
}
}
range() {
try {
this.match(this.input, ANTLRv4Lexer.RANGE);
this.match(this.input, Constants.Down);
const a = this.match(this.input, ANTLRv4Lexer.STRING_LITERAL);
const b = this.match(this.input, ANTLRv4Lexer.STRING_LITERAL);
this.match(this.input, Constants.Up);
return this.factory.range(a, b) ?? void 0;
} catch (re) {
if (re instanceof RecognitionException) {
this.reportError(re);
return void 0;
} else {
throw re;
}
}
}
terminal() {
try {
const start = this.input.lookaheadType(1);
let alt24 = 5;
const lookahead = this.input.lookahead(1);
if (lookahead === ANTLRv4Lexer.STRING_LITERAL) {
const lookahead2 = this.input.lookahead(2);
if (lookahead2 === Constants.Down) {
alt24 = 1;
} else {
if (lookahead2 === ANTLRv4Lexer.EOF || lookahead2 >= Constants.Up && lookahead2 <= ANTLRv4Lexer.ACTION || lookahead2 === ANTLRv4Lexer.ASSIGN || lookahead2 === ANTLRv4Lexer.DOT || lookahead2 === ANTLRv4Lexer.LEXER_CHAR_SET || lookahead2 === ANTLRv4Lexer.NOT || lookahead2 === ANTLRv4Lexer.PLUS_ASSIGN || lookahead2 === ANTLRv4Lexer.RANGE || lookahead2 === ANTLRv4Lexer.RULE_REF || lookahead2 === ANTLRv4Lexer.SEMPRED || lookahead2 === ANTLRv4Lexer.STRING_LITERAL || lookahead2 === ANTLRv4Lexer.TOKEN_REF || lookahead2 >= ANTLRv4Lexer.BLOCK && lookahead2 <= ANTLRv4Lexer.CLOSURE || lookahead2 >= ANTLRv4Lexer.OPTIONAL && lookahead2 <= ANTLRv4Lexer.POSITIVE_CLOSURE || lookahead2 >= ANTLRv4Lexer.SET && lookahead2 <= ANTLRv4Lexer.WILDCARD) {
alt24 = 2;
} else {
const mark = this.input.mark();
const lastIndex = this.input.index;
try {
this.input.consume();
throw new NoViableAltException(24, 1);
} finally {
this.input.seek(lastIndex);
this.input.release(mark);
}
}
}
} else {
if (lookahead === ANTLRv4Lexer.TOKEN_REF) {
const lookahead2 = this.input.lookahead(2);
if (lookahead2 === Constants.Down) {
const lookahead3 = this.input.lookahead(3);
if (lookahead3 === ANTLRv4Lexer.ARG_ACTION) {
const lookahead4 = this.input.lookahead(4);
if (lookahead4 >= ANTLRv4Lexer.ACTION && lookahead4 <= ANTLRv4Lexer.WILDCARD) {
alt24 = 3;
} else {
if (lookahead4 >= Constants.Down && lookahead4 <= Constants.Up) {
alt24 = 4;
} else {
const mark = this.input.mark();
const lastIndex = this.input.index;
try {
this.input.consume();
this.input.consume();
this.input.consume();
throw new NoViableAltException(24, 7);
} finally {
this.input.seek(lastIndex);
this.input.release(mark);
}
}
}
} else if (lookahead3 >= ANTLRv4Lexer.ACTION || lookahead3 >= ANTLRv4Lexer.ARG_OR_CHARSET && lookahead3 <= ANTLRv4Lexer.WILDCARD) {
alt24 = 4;
} else {
const mark = this.input.mark();
const lastIndex = this.input.index;
try {
this.input.consume();
this.input.consume();
throw new NoViableAltException(24, 5);
} finally {
this.input.seek(lastIndex);
this.input.release(mark);
}
}
} else {
if (lookahead2 === ANTLRv4Lexer.EOF || lookahead2 >= Constants.Up && lookahead2 <= ANTLRv4Lexer.ACTION || lookahead2 === ANTLRv4Lexer.ASSIGN || lookahead2 === ANTLRv4Lexer.DOT || lookahead2 === ANTLRv4Lexer.LEXER_CHAR_SET || lookahead2 === ANTLRv4Lexer.NOT || lookahead2 === ANTLRv4Lexer.PLUS_ASSIGN || lookahead2 === ANTLRv4Lexer.RANGE || lookahead2 === ANTLRv4Lexer.RULE_REF || lookahead2 === ANTLRv4Lexer.SEMPRED || lookahead2 === ANTLRv4Lexer.STRING_LITERAL || lookahead2 === ANTLRv4Lexer.TOKEN_REF || lookahead2 >= ANTLRv4Lexer.BLOCK && lookahead2 <= ANTLRv4Lexer.CLOSURE || lookahead2 >= ANTLRv4Lexer.OPTIONAL && lookahead2 <= ANTLRv4Lexer.POSITIVE_CLOSURE || lookahead2 >= ANTLRv4Lexer.SET && lookahead2 <= ANTLRv4Lexer.WILDCARD) {
alt24 = 5;
} else {
const mark = this.input.mark();
const lastIndex = this.input.index;
try {
this.input.consume();
throw new NoViableAltException(24, 2);
} finally {
this.input.seek(lastIndex);
this.input.release(mark);
}
}
}
} else {
throw new NoViableAltException(24, 0);
}
}
switch (alt24) {
case 1: {
this.match(this.input, ANTLRv4Lexer.STRING_LITERAL);
this.match(this.input, Constants.Down);
this.matchAny();
this.match(this.input, Constants.Up);
return this.factory.stringLiteral(start);
}
case 2: {
this.match(this.input, ANTLRv4Lexer.STRING_LITERAL);
return this.factory.stringLiteral(start);
}
case 3: {
this.match(this.input, ANTLRv4Lexer.TOKEN_REF);
this.match(this.input, Constants.Down);
this.match(this.input, ANTLRv4Lexer.ARG_ACTION);
this.matchAny();
this.match(this.input, Constants.Up);
return this.factory.tokenRef(start);
}
case 4: {
this.match(this.input, ANTLRv4Lexer.TOKEN_REF);
this.match(this.input, Constants.Down);
this.matchAny();
this.match(this.input, Constants.Up);
return this.factory.tokenRef(start) ?? void 0;
}
case 5: {
this.match(this.input, ANTLRv4Lexer.TOKEN_REF);
return this.factory.tokenRef(start) ?? void 0;
}
default: {
return void 0;
}
}
} catch (re) {
if (re instanceof RecognitionException) {
this.reportError(re);
return void 0;
} else {
throw re;
}
}
}
elementOptions() {
try {
this.match(this.input, ANTLRv4Lexer.ELEMENT_OPTIONS);
if (this.input.lookahead(1) === Constants.Down) {
this.match(this.input, Constants.Down);
while (true) {
const lookahead = this.input.lookahead(1);
if (lookahead === ANTLRv4Lexer.ASSIGN || lookahead === ANTLRv4Lexer.ID) {
this.elementOption();
} else {
break;
}
}
this.match(this.input, Constants.Up);
}
} catch (re) {
if (re instanceof RecognitionException) {
this.reportError(re);
} else {
throw re;
}
}
}
elementOption() {
try {
const lookahead = this.input.lookahead(1);
if (lookahead === ANTLRv4Lexer.ID) {
this.match(this.input, ANTLRv4Lexer.ID);
} else {
if (lookahead === ANTLRv4Lexer.ASSIGN) {
if (this.input.lookahead(2) === Constants.Down) {
if (this.input.lookahead(3) === ANTLRv4Lexer.ID) {
switch (this.input.lookahead(4)) {
case ANTLRv4Lexer.ID: {
this.match(this.input, ANTLRv4Lexer.ASSIGN);
this.match(this.input, Constants.Down);
this.match(this.input, ANTLRv4Lexer.ID);
this.match(this.input, ANTLRv4Lexer.ID);
this.match(this.input, Constants.Up);
break;
}
case ANTLRv4Lexer.STRING_LITERAL: {
this.match(this.input, ANTLRv4Lexer.ASSIGN);
this.match(this.input, Constants.Down);
this.match(this.input, ANTLRv4Lexer.ID);
this.match(this.input, ANTLRv4Lexer.STRING_LITERAL);
this.match(this.input, Constants.Up);
break;
}
case ANTLRv4Lexer.ACTION: {
this.match(this.input, ANTLRv4Lexer.ASSIGN);
this.match(this.input, Constants.Down);
this.match(this.input, ANTLRv4Lexer.ID);
this.match(this.input, ANTLRv4Lexer.ACTION);
this.match(this.input, Constants.Up);
break;
}
case ANTLRv4Lexer.INT: {
this.match(this.input, ANTLRv4Lexer.ASSIGN);
this.match(this.input, Constants.Down);
this.match(this.input, ANTLRv4Lexer.ID);
this.match(this.input, ANTLRv4Lexer.INT);
this.match(this.input, Constants.Up);
break;
}
default: {
const mark = this.input.mark();
const lastIndex = this.input.index;
try {
this.input.consume();
this.input.consume();
this.input.consume();
throw new NoViableAltException(26, 4);
} finally {
this.input.seek(lastIndex);
this.input.release(mark);
}
}
}
} else {
const mark = this.input.mark();
const lastIndex = this.input.index;
try {
this.input.consume();
this.input.consume();
throw new NoViableAltException(26, 3);
} finally {
this.input.seek(lastIndex);
this.input.release(mark);
}
}
} else {
const mark = this.input.mark();
const lastIndex = this.input.index;
try {
this.input.consume();
throw new NoViableAltException(26, 2);
} finally {
this.input.seek(lastIndex);
this.input.release(mark);
}
}
} else {
throw new NoViableAltException(26, 0);
}
}
} catch (re) {
if (re instanceof RecognitionException) {
this.reportError(re);
} else {
throw re;
}
}
}
}
export {
ATNBuilder
};