1 |
|
2 |
|
3 |
|
4 |
|
5 | import { ATN } from "./atn/ATN";
|
6 | import { ATNState } from "./atn/ATNState";
|
7 | import { BitSet } from "./misc/BitSet";
|
8 | import { DecisionState } from "./atn/DecisionState";
|
9 | import { InterpreterRuleContext } from "./InterpreterRuleContext";
|
10 | import { Parser } from "./Parser";
|
11 | import { ParserRuleContext } from "./ParserRuleContext";
|
12 | import { RecognitionException } from "./RecognitionException";
|
13 | import { Token } from "./Token";
|
14 | import { TokenStream } from "./TokenStream";
|
15 | import { Vocabulary } from "./Vocabulary";
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | export declare class ParserInterpreter extends Parser {
|
30 | protected _grammarFileName: string;
|
31 | protected _atn: ATN;
|
32 | |
33 |
|
34 |
|
35 | protected pushRecursionContextStates: BitSet;
|
36 | protected _ruleNames: string[];
|
37 | private _vocabulary;
|
38 | |
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | protected readonly _parentContextStack: Array<[ParserRuleContext, number]>;
|
52 | |
53 |
|
54 |
|
55 | protected overrideDecision: number;
|
56 | protected overrideDecisionInputIndex: number;
|
57 | protected overrideDecisionAlt: number;
|
58 | protected overrideDecisionReached: boolean;
|
59 | |
60 |
|
61 |
|
62 |
|
63 | protected _overrideDecisionRoot?: InterpreterRuleContext;
|
64 | protected _rootContext: InterpreterRuleContext;
|
65 | |
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | constructor( old: ParserInterpreter);
|
73 | constructor(grammarFileName: string, vocabulary: Vocabulary, ruleNames: string[], atn: ATN, input: TokenStream);
|
74 | reset(resetInput?: boolean): void;
|
75 | get atn(): ATN;
|
76 | get vocabulary(): Vocabulary;
|
77 | get ruleNames(): string[];
|
78 | get grammarFileName(): string;
|
79 | /** Begin parsing at startRuleIndex */
|
80 | parse(startRuleIndex: number): ParserRuleContext;
|
81 | enterRecursionRule(localctx: ParserRuleContext, state: number, ruleIndex: number, precedence: number): void;
|
82 | protected get atnState(): ATNState;
|
83 | protected visitState(p: ATNState): void;
|
84 | /** Method visitDecisionState() is called when the interpreter reaches
|
85 | * a decision state (instance of DecisionState). It gives an opportunity
|
86 | * for subclasses to track interesting things.
|
87 | */
|
88 | protected visitDecisionState(p: DecisionState): number;
|
89 | /** Provide simple "factory" for InterpreterRuleContext's.
|
90 | * @since 4.5.1
|
91 | */
|
92 | protected createInterpreterRuleContext(parent: ParserRuleContext | undefined, invokingStateNumber: number, ruleIndex: number): InterpreterRuleContext;
|
93 | protected visitRuleStopState(p: ATNState): void;
|
94 | /** Override this parser interpreters normal decision-making process
|
95 | * at a particular decision and input token index. Instead of
|
96 | * allowing the adaptive prediction mechanism to choose the
|
97 | * first alternative within a block that leads to a successful parse,
|
98 | * force it to take the alternative, 1..n for n alternatives.
|
99 | *
|
100 | * As an implementation limitation right now, you can only specify one
|
101 | * override. This is sufficient to allow construction of different
|
102 | * parse trees for ambiguous input. It means re-parsing the entire input
|
103 | * in general because you're never sure where an ambiguous sequence would
|
104 | * live in the various parse trees. For example, in one interpretation,
|
105 | * an ambiguous input sequence would be matched completely in expression
|
106 | * but in another it could match all the way back to the root.
|
107 | *
|
108 | * s : e '!'? ;
|
109 | * e : ID
|
110 | * | ID '!'
|
111 | * ;
|
112 | *
|
113 | * Here, x! can be matched as (s (e ID) !) or (s (e ID !)). In the first
|
114 | * case, the ambiguous sequence is fully contained only by the root.
|
115 | * In the second case, the ambiguous sequences fully contained within just
|
116 | * e, as in: (e ID !).
|
117 | *
|
118 | * Rather than trying to optimize this and make
|
119 | * some intelligent decisions for optimization purposes, I settled on
|
120 | * just re-parsing the whole input and then using
|
121 | * {link Trees#getRootOfSubtreeEnclosingRegion} to find the minimal
|
122 | * subtree that contains the ambiguous sequence. I originally tried to
|
123 | * record the call stack at the point the parser detected and ambiguity but
|
124 | * left recursive rules create a parse tree stack that does not reflect
|
125 | * the actual call stack. That impedance mismatch was enough to make
|
126 | * it it challenging to restart the parser at a deeply nested rule
|
127 | * invocation.
|
128 | *
|
129 | * Only parser interpreters can override decisions so as to avoid inserting
|
130 | * override checking code in the critical ALL(*) prediction execution path.
|
131 | *
|
132 | * @since 4.5
|
133 | */
|
134 | addDecisionOverride(decision: number, tokenIndex: number, forcedAlt: number): void;
|
135 | get overrideDecisionRoot(): InterpreterRuleContext | undefined;
|
136 | /** Rely on the error handler for this parser but, if no tokens are consumed
|
137 | * to recover, add an error node. Otherwise, nothing is seen in the parse
|
138 | * tree.
|
139 | */
|
140 | protected recover(e: RecognitionException): void;
|
141 | protected recoverInline(): Token;
|
142 | /** Return the root of the parse, which can be useful if the parser
|
143 | * bails out. You still can access the top node. Note that,
|
144 | * because of the way left recursive rules add children, it's possible
|
145 | * that the root will not have any children if the start rule immediately
|
146 | * called and left recursive rule that fails.
|
147 | *
|
148 | * @since 4.5.1
|
149 | */
|
150 | get rootContext(): InterpreterRuleContext;
|
151 | }
|