@cparra/apex-reflection 0.1.0-alpha.0 → 0.1.1-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/end-to-end.test.ts +256 -0
- package/coverage/clover.xml +12857 -0
- package/coverage/coverage-final.json +3 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +79 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +126 -0
- package/coverage/lcov-report/index.js.html +104 -0
- package/coverage/lcov-report/out.js.html +41126 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +170 -0
- package/coverage/lcov.info +24801 -0
- package/index.d.ts +118 -0
- package/index.js +8 -0
- package/index.ts +141 -0
- package/jest.config.js +11 -0
- package/out.js +13708 -0
- package/package.json +22 -17
- package/tsconfig.json +5 -3
- package/.idea/apexdocs-dart.iml +0 -18
- package/.idea/jsLibraryMappings.xml +0 -6
- package/.idea/libraries/Dart_Packages.xml +0 -556
- package/.idea/libraries/Dart_SDK.xml +0 -28
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/runConfigurations/_template__of_Dart_Test.xml +0 -6
- package/.idea/vcs.xml +0 -6
- package/CHANGELOG.md +0 -3
- package/README.md +0 -26
- package/TODO.md +0 -5
- package/analysis_options.yaml +0 -30
- package/antlr4-4.9.2/CHANGELOG.md +0 -4
- package/antlr4-4.9.2/LICENSE +0 -52
- package/antlr4-4.9.2/README.md +0 -11
- package/antlr4-4.9.2/analysis_options.yaml +0 -1
- package/antlr4-4.9.2/lib/antlr4.dart +0 -21
- package/antlr4-4.9.2/lib/src/atn/atn.dart +0 -18
- package/antlr4-4.9.2/lib/src/atn/src/atn.dart +0 -170
- package/antlr4-4.9.2/lib/src/atn/src/atn_config.dart +0 -242
- package/antlr4-4.9.2/lib/src/atn/src/atn_config_set.dart +0 -283
- package/antlr4-4.9.2/lib/src/atn/src/atn_deserializer.dart +0 -809
- package/antlr4-4.9.2/lib/src/atn/src/atn_simulator.dart +0 -95
- package/antlr4-4.9.2/lib/src/atn/src/atn_state.dart +0 -296
- package/antlr4-4.9.2/lib/src/atn/src/atn_type.dart +0 -14
- package/antlr4-4.9.2/lib/src/atn/src/info.dart +0 -553
- package/antlr4-4.9.2/lib/src/atn/src/lexer_action.dart +0 -601
- package/antlr4-4.9.2/lib/src/atn/src/lexer_action_executor.dart +0 -167
- package/antlr4-4.9.2/lib/src/atn/src/lexer_atn_simulator.dart +0 -731
- package/antlr4-4.9.2/lib/src/atn/src/parser_atn_simulator.dart +0 -2630
- package/antlr4-4.9.2/lib/src/atn/src/profiling_atn_simulator.dart +0 -229
- package/antlr4-4.9.2/lib/src/atn/src/semantic_context.dart +0 -404
- package/antlr4-4.9.2/lib/src/atn/src/transition.dart +0 -305
- package/antlr4-4.9.2/lib/src/dfa/dfa.dart +0 -8
- package/antlr4-4.9.2/lib/src/dfa/src/dfa.dart +0 -138
- package/antlr4-4.9.2/lib/src/dfa/src/dfa_serializer.dart +0 -76
- package/antlr4-4.9.2/lib/src/dfa/src/dfa_state.dart +0 -151
- package/antlr4-4.9.2/lib/src/error/error.dart +0 -10
- package/antlr4-4.9.2/lib/src/error/src/diagnostic_error_listener.dart +0 -116
- package/antlr4-4.9.2/lib/src/error/src/error_listener.dart +0 -241
- package/antlr4-4.9.2/lib/src/error/src/error_strategy.dart +0 -902
- package/antlr4-4.9.2/lib/src/error/src/errors.dart +0 -204
- package/antlr4-4.9.2/lib/src/input_stream.dart +0 -335
- package/antlr4-4.9.2/lib/src/interval_set.dart +0 -735
- package/antlr4-4.9.2/lib/src/lexer.dart +0 -343
- package/antlr4-4.9.2/lib/src/ll1_analyzer.dart +0 -204
- package/antlr4-4.9.2/lib/src/misc/multi_map.dart +0 -32
- package/antlr4-4.9.2/lib/src/misc/pair.dart +0 -34
- package/antlr4-4.9.2/lib/src/parser.dart +0 -777
- package/antlr4-4.9.2/lib/src/parser_interpreter.dart +0 -393
- package/antlr4-4.9.2/lib/src/parser_rule_context.dart +0 -275
- package/antlr4-4.9.2/lib/src/prediction_context.dart +0 -877
- package/antlr4-4.9.2/lib/src/recognizer.dart +0 -182
- package/antlr4-4.9.2/lib/src/rule_context.dart +0 -192
- package/antlr4-4.9.2/lib/src/runtime_meta_data.dart +0 -188
- package/antlr4-4.9.2/lib/src/token.dart +0 -431
- package/antlr4-4.9.2/lib/src/token_factory.dart +0 -88
- package/antlr4-4.9.2/lib/src/token_source.dart +0 -241
- package/antlr4-4.9.2/lib/src/token_stream.dart +0 -627
- package/antlr4-4.9.2/lib/src/tree/src/pattern/chunk.dart +0 -90
- package/antlr4-4.9.2/lib/src/tree/src/pattern/parse_tree_match.dart +0 -635
- package/antlr4-4.9.2/lib/src/tree/src/tree.dart +0 -370
- package/antlr4-4.9.2/lib/src/tree/src/trees.dart +0 -226
- package/antlr4-4.9.2/lib/src/tree/tree.dart +0 -10
- package/antlr4-4.9.2/lib/src/util/bit_set.dart +0 -308
- package/antlr4-4.9.2/lib/src/util/murmur_hash.dart +0 -77
- package/antlr4-4.9.2/lib/src/util/utils.dart +0 -31
- package/antlr4-4.9.2/lib/src/vocabulary.dart +0 -254
- package/antlr4-4.9.2/pubspec.yaml +0 -13
- package/example/node_example/index.js +0 -8
- package/example/node_example/package.json +0 -12
- package/example/node_example_ts/package-lock.json +0 -70
- package/example/node_example_ts/package.json +0 -19
- package/example/node_example_ts/src/index.js +0 -5
- package/example/node_example_ts/src/index.ts +0 -9
- package/example/node_example_ts/tsconfig.json +0 -79
- package/js/dart2jsout.js +0 -25898
- package/js/dart2jsout.js.map +0 -16
- package/js/index.d.ts +0 -1
- package/js/index.js +0 -4
- package/js/out.js +0 -26023
- package/js/out.js.map +0 -16
- package/js/package-lock.json +0 -57
- package/js/preamble.js +0 -125
- package/lib/apexdocs_dart.dart +0 -28
- package/lib/src/antlr/grammars/Apexdoc/ApexdocLexer.g4 +0 -120
- package/lib/src/antlr/grammars/Apexdoc/ApexdocParser.g4 +0 -158
- package/lib/src/antlr/grammars/Apexdoc/gen/ApexdocLexer.interp +0 -95
- package/lib/src/antlr/grammars/Apexdoc/gen/ApexdocLexer.java +0 -238
- package/lib/src/antlr/grammars/Apexdoc/gen/ApexdocLexer.tokens +0 -23
- package/lib/src/antlr/grammars/apex/ApexLexer.g4 +0 -255
- package/lib/src/antlr/grammars/apex/ApexParser.g4 +0 -567
- package/lib/src/antlr/grammars/apex/examples/ApexClass.cls +0 -6
- package/lib/src/antlr/lib/apex/ApexLexer.dart +0 -1223
- package/lib/src/antlr/lib/apex/ApexLexer.interp +0 -393
- package/lib/src/antlr/lib/apex/ApexLexer.tokens +0 -212
- package/lib/src/antlr/lib/apex/ApexParser.dart +0 -9349
- package/lib/src/antlr/lib/apex/ApexParser.interp +0 -326
- package/lib/src/antlr/lib/apex/ApexParser.tokens +0 -212
- package/lib/src/antlr/lib/apex/ApexParserBaseListener.dart +0 -1036
- package/lib/src/antlr/lib/apex/ApexParserListener.dart +0 -975
- package/lib/src/antlr/lib/apexdoc/ApexdocLexer.dart +0 -373
- package/lib/src/antlr/lib/apexdoc/ApexdocLexer.interp +0 -95
- package/lib/src/antlr/lib/apexdoc/ApexdocLexer.tokens +0 -23
- package/lib/src/antlr/lib/apexdoc/ApexdocParser.dart +0 -2471
- package/lib/src/antlr/lib/apexdoc/ApexdocParser.interp +0 -69
- package/lib/src/antlr/lib/apexdoc/ApexdocParser.tokens +0 -23
- package/lib/src/antlr/lib/apexdoc/ApexdocParserBaseListener.dart +0 -252
- package/lib/src/antlr/lib/apexdoc/ApexdocParserListener.dart +0 -215
- package/lib/src/builders/builders.dart +0 -32
- package/lib/src/model/apex_file_manifest.dart +0 -37
- package/lib/src/model/apex_file_manifest.g.dart +0 -18
- package/lib/src/model/declaration.dart +0 -50
- package/lib/src/model/doc_comment.dart +0 -117
- package/lib/src/model/doc_comment.g.dart +0 -118
- package/lib/src/model/members.dart +0 -143
- package/lib/src/model/members.g.dart +0 -105
- package/lib/src/model/types.dart +0 -159
- package/lib/src/model/types.g.dart +0 -111
- package/lib/src/service/apex_listener.dart +0 -226
- package/lib/src/service/apexdoc_listener.dart +0 -82
- package/lib/src/service/parsers.dart +0 -33
- package/lib/src/service/utils/parsing/access_modifiers_parser.dart +0 -33
- package/lib/src/service/utils/parsing/parameters_parser.dart +0 -18
- package/lib/src/service/utils/parsing/parsing_utils.dart +0 -2
- package/lib/src/service/walker.dart +0 -82
- package/pubspec.yaml +0 -19
- package/test/apex_file_manifest_test.dart +0 -16
- package/test/apex_listener_test.dart +0 -703
- package/test/apexdoc_parser_test.dart +0 -179
- package/test/doc_comment_test.dart +0 -89
- package/test/members_serialization_test.dart +0 -158
- package/test/members_test.dart +0 -178
- package/test/types_serialization_test.dart +0 -191
- package/test/types_test.dart +0 -311
- package/test/walker_test.dart +0 -58
- package/tool/grind.dart +0 -20
|
@@ -1,393 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
|
|
3
|
-
* Use of this file is governed by the BSD 3-clause license that
|
|
4
|
-
* can be found in the LICENSE.txt file in the project root.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import 'dart:collection';
|
|
8
|
-
|
|
9
|
-
import 'atn/atn.dart';
|
|
10
|
-
import 'dfa/dfa.dart';
|
|
11
|
-
import 'error/error.dart';
|
|
12
|
-
import 'misc/pair.dart';
|
|
13
|
-
import 'parser.dart';
|
|
14
|
-
import 'parser_rule_context.dart';
|
|
15
|
-
import 'token.dart';
|
|
16
|
-
import 'token_stream.dart';
|
|
17
|
-
import 'vocabulary.dart';
|
|
18
|
-
|
|
19
|
-
/// A parser simulator that mimics what ANTLR's generated
|
|
20
|
-
/// parser code does. A ParserATNSimulator is used to make
|
|
21
|
-
/// predictions via adaptivePredict but this class moves a pointer through the
|
|
22
|
-
/// ATN to simulate parsing. ParserATNSimulator just
|
|
23
|
-
/// makes us efficient rather than having to backtrack, for example.
|
|
24
|
-
///
|
|
25
|
-
/// This properly creates parse trees even for left recursive rules.
|
|
26
|
-
///
|
|
27
|
-
/// We rely on the left recursive rule invocation and special predicate
|
|
28
|
-
/// transitions to make left recursive rules work.
|
|
29
|
-
///
|
|
30
|
-
/// See TestParserInterpreter for examples.
|
|
31
|
-
class ParserInterpreter extends Parser {
|
|
32
|
-
@override
|
|
33
|
-
final String grammarFileName;
|
|
34
|
-
final ATN atn;
|
|
35
|
-
|
|
36
|
-
List<DFA> decisionToDFA; // not shared like it is for generated parsers
|
|
37
|
-
final PredictionContextCache sharedContextCache =
|
|
38
|
-
PredictionContextCache();
|
|
39
|
-
|
|
40
|
-
@override
|
|
41
|
-
final List<String> ruleNames;
|
|
42
|
-
|
|
43
|
-
@override
|
|
44
|
-
final Vocabulary vocabulary;
|
|
45
|
-
|
|
46
|
-
/// This stack corresponds to the _parentctx, _parentState pair of locals
|
|
47
|
-
/// that would exist on call stack frames with a recursive descent parser;
|
|
48
|
-
/// in the generated function for a left-recursive rule you'd see:
|
|
49
|
-
///
|
|
50
|
-
/// EContext e(int _p) throws RecognitionException {
|
|
51
|
-
/// ParserRuleContext _parentctx = context; // Pair.a
|
|
52
|
-
/// int _parentState = state; // Pair.b
|
|
53
|
-
/// ...
|
|
54
|
-
/// }
|
|
55
|
-
///
|
|
56
|
-
/// Those values are used to create new recursive rule invocation contexts
|
|
57
|
-
/// associated with left operand of an alt like "expr '*' expr".
|
|
58
|
-
final DoubleLinkedQueue<Pair<ParserRuleContext, int>> _parentContextStack =
|
|
59
|
-
DoubleLinkedQueue();
|
|
60
|
-
|
|
61
|
-
/// We need a map from (decision,inputIndex)->forced alt for computing ambiguous
|
|
62
|
-
/// parse trees. For now, we allow exactly one override.
|
|
63
|
-
int overrideDecision = -1;
|
|
64
|
-
int overrideDecisionInputIndex = -1;
|
|
65
|
-
int overrideDecisionAlt = -1;
|
|
66
|
-
bool overrideDecisionReached =
|
|
67
|
-
false; // latch and only override once; error might trigger infinite loop
|
|
68
|
-
|
|
69
|
-
/// What is the current context when we override a decisions? This tells
|
|
70
|
-
/// us what the root of the parse tree is when using override
|
|
71
|
-
/// for an ambiguity/lookahead check.
|
|
72
|
-
InterpreterRuleContext overrideDecisionRoot;
|
|
73
|
-
|
|
74
|
-
/// Return the root of the parse, which can be useful if the parser
|
|
75
|
-
/// bails out. You still can access the top node. Note that,
|
|
76
|
-
/// because of the way left recursive rules add children, it's possible
|
|
77
|
-
/// that the root will not have any children if the start rule immediately
|
|
78
|
-
/// called and left recursive rule that fails.
|
|
79
|
-
///
|
|
80
|
-
/// @since 4.5.1
|
|
81
|
-
InterpreterRuleContext rootContext;
|
|
82
|
-
|
|
83
|
-
ParserInterpreter(this.grammarFileName, this.vocabulary, this.ruleNames,
|
|
84
|
-
this.atn, TokenStream input)
|
|
85
|
-
: super(input) {
|
|
86
|
-
// init decision DFA
|
|
87
|
-
final numberOfDecisions = atn.numberOfDecisions;
|
|
88
|
-
decisionToDFA = List<DFA>(numberOfDecisions);
|
|
89
|
-
for (var i = 0; i < numberOfDecisions; i++) {
|
|
90
|
-
final decisionState = atn.getDecisionState(i);
|
|
91
|
-
decisionToDFA[i] = DFA(decisionState, i);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// get atn simulator that knows how to do predictions
|
|
95
|
-
interpreter =
|
|
96
|
-
ParserATNSimulator(this, atn, decisionToDFA, sharedContextCache);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
@override
|
|
100
|
-
void reset() {
|
|
101
|
-
super.reset();
|
|
102
|
-
overrideDecisionReached = false;
|
|
103
|
-
overrideDecisionRoot = null;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
@override
|
|
107
|
-
ATN getATN() {
|
|
108
|
-
return atn;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/// Begin parsing at startRuleIndex */
|
|
112
|
-
ParserRuleContext parse(int startRuleIndex) {
|
|
113
|
-
final startRuleStartState = atn.ruleToStartState[startRuleIndex];
|
|
114
|
-
|
|
115
|
-
rootContext = createInterpreterRuleContext(
|
|
116
|
-
null, ATNState.INVALID_STATE_NUMBER, startRuleIndex);
|
|
117
|
-
if (startRuleStartState.isLeftRecursiveRule) {
|
|
118
|
-
enterRecursionRule(
|
|
119
|
-
rootContext, startRuleStartState.stateNumber, startRuleIndex, 0);
|
|
120
|
-
} else {
|
|
121
|
-
enterRule(rootContext, startRuleStartState.stateNumber, startRuleIndex);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
while (true) {
|
|
125
|
-
final p = atnState;
|
|
126
|
-
switch (p.stateType) {
|
|
127
|
-
case StateType.RULE_STOP:
|
|
128
|
-
// pop; return from rule
|
|
129
|
-
if (context.isEmpty) {
|
|
130
|
-
if (startRuleStartState.isLeftRecursiveRule) {
|
|
131
|
-
final result = context;
|
|
132
|
-
final parentContext =
|
|
133
|
-
_parentContextStack.removeLast();
|
|
134
|
-
unrollRecursionContexts(parentContext.a);
|
|
135
|
-
return result;
|
|
136
|
-
} else {
|
|
137
|
-
exitRule();
|
|
138
|
-
return rootContext;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
visitRuleStopState(p);
|
|
143
|
-
break;
|
|
144
|
-
|
|
145
|
-
default:
|
|
146
|
-
try {
|
|
147
|
-
visitState(p);
|
|
148
|
-
} on RecognitionException catch (e) {
|
|
149
|
-
state = atn.ruleToStopState[p.ruleIndex].stateNumber;
|
|
150
|
-
context.exception = e;
|
|
151
|
-
errorHandler.reportError(this, e);
|
|
152
|
-
recover(e);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
break;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
@override
|
|
161
|
-
void enterRecursionRule(
|
|
162
|
-
ParserRuleContext localctx, int state, int ruleIndex, int precedence) {
|
|
163
|
-
final pair =
|
|
164
|
-
Pair<ParserRuleContext, int>(context, localctx.invokingState);
|
|
165
|
-
_parentContextStack.add(pair);
|
|
166
|
-
super.enterRecursionRule(localctx, state, ruleIndex, precedence);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
ATNState get atnState {
|
|
170
|
-
return atn.states[state];
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
void visitState(ATNState p) {
|
|
174
|
-
// System.out.println("visitState "+p.stateNumber);
|
|
175
|
-
var predictedAlt = 1;
|
|
176
|
-
if (p is DecisionState) {
|
|
177
|
-
predictedAlt = visitDecisionState(p);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
final transition = p.transition(predictedAlt - 1);
|
|
181
|
-
switch (transition.type) {
|
|
182
|
-
case TransitionType.EPSILON:
|
|
183
|
-
if (p.stateType == StateType.STAR_LOOP_ENTRY &&
|
|
184
|
-
(p as StarLoopEntryState).isPrecedenceDecision &&
|
|
185
|
-
!(transition.target is LoopEndState)) {
|
|
186
|
-
// We are at the start of a left recursive rule's (...)* loop
|
|
187
|
-
// and we're not taking the exit branch of loop.
|
|
188
|
-
final localctx = createInterpreterRuleContext(
|
|
189
|
-
_parentContextStack.last.a,
|
|
190
|
-
_parentContextStack.last.b,
|
|
191
|
-
context.ruleIndex);
|
|
192
|
-
pushNewRecursionContext(localctx,
|
|
193
|
-
atn.ruleToStartState[p.ruleIndex].stateNumber, context.ruleIndex);
|
|
194
|
-
}
|
|
195
|
-
break;
|
|
196
|
-
|
|
197
|
-
case TransitionType.ATOM:
|
|
198
|
-
match((transition as AtomTransition).atomLabel);
|
|
199
|
-
break;
|
|
200
|
-
|
|
201
|
-
case TransitionType.RANGE:
|
|
202
|
-
case TransitionType.SET:
|
|
203
|
-
case TransitionType.NOT_SET:
|
|
204
|
-
if (!transition.matches(
|
|
205
|
-
inputStream.LA(1), Token.MIN_USER_TOKEN_TYPE, 65535)) {
|
|
206
|
-
recoverInline();
|
|
207
|
-
}
|
|
208
|
-
matchWildcard();
|
|
209
|
-
break;
|
|
210
|
-
|
|
211
|
-
case TransitionType.WILDCARD:
|
|
212
|
-
matchWildcard();
|
|
213
|
-
break;
|
|
214
|
-
|
|
215
|
-
case TransitionType.RULE:
|
|
216
|
-
RuleStartState ruleStartState = transition.target;
|
|
217
|
-
final ruleIndex = ruleStartState.ruleIndex;
|
|
218
|
-
final newctx =
|
|
219
|
-
createInterpreterRuleContext(context, p.stateNumber, ruleIndex);
|
|
220
|
-
if (ruleStartState.isLeftRecursiveRule) {
|
|
221
|
-
enterRecursionRule(newctx, ruleStartState.stateNumber, ruleIndex,
|
|
222
|
-
(transition as RuleTransition).precedence);
|
|
223
|
-
} else {
|
|
224
|
-
enterRule(newctx, transition.target.stateNumber, ruleIndex);
|
|
225
|
-
}
|
|
226
|
-
break;
|
|
227
|
-
|
|
228
|
-
case TransitionType.PREDICATE:
|
|
229
|
-
PredicateTransition predicateTransition = transition;
|
|
230
|
-
if (!sempred(context, predicateTransition.ruleIndex,
|
|
231
|
-
predicateTransition.predIndex)) {
|
|
232
|
-
throw FailedPredicateException(this);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
break;
|
|
236
|
-
|
|
237
|
-
case TransitionType.ACTION:
|
|
238
|
-
ActionTransition actionTransition = transition;
|
|
239
|
-
action(
|
|
240
|
-
context, actionTransition.ruleIndex, actionTransition.actionIndex);
|
|
241
|
-
break;
|
|
242
|
-
|
|
243
|
-
case TransitionType.PRECEDENCE:
|
|
244
|
-
if (!precpred(context,
|
|
245
|
-
(transition as PrecedencePredicateTransition).precedence)) {
|
|
246
|
-
throw FailedPredicateException(this,
|
|
247
|
-
'precpred(context, ${(transition as PrecedencePredicateTransition).precedence})');
|
|
248
|
-
}
|
|
249
|
-
break;
|
|
250
|
-
|
|
251
|
-
default:
|
|
252
|
-
throw UnsupportedError('Unrecognized ATN transition type.');
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
state = transition.target.stateNumber;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/// Method visitDecisionState() is called when the interpreter reaches
|
|
259
|
-
/// a decision state (instance of DecisionState). It gives an opportunity
|
|
260
|
-
/// for subclasses to track interesting things.
|
|
261
|
-
int visitDecisionState(DecisionState p) {
|
|
262
|
-
var predictedAlt = 1;
|
|
263
|
-
if (p.numberOfTransitions > 1) {
|
|
264
|
-
errorHandler.sync(this);
|
|
265
|
-
final decision = p.decision;
|
|
266
|
-
if (decision == overrideDecision &&
|
|
267
|
-
inputStream.index == overrideDecisionInputIndex &&
|
|
268
|
-
!overrideDecisionReached) {
|
|
269
|
-
predictedAlt = overrideDecisionAlt;
|
|
270
|
-
overrideDecisionReached = true;
|
|
271
|
-
} else {
|
|
272
|
-
predictedAlt =
|
|
273
|
-
interpreter.adaptivePredict(inputStream, decision, context);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
return predictedAlt;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/// Provide simple "factory" for InterpreterRuleContext's.
|
|
280
|
-
/// @since 4.5.1
|
|
281
|
-
InterpreterRuleContext createInterpreterRuleContext(
|
|
282
|
-
ParserRuleContext parent, int invokingStateNumber, int ruleIndex) {
|
|
283
|
-
return InterpreterRuleContext(parent, invokingStateNumber, ruleIndex);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
void visitRuleStopState(ATNState p) {
|
|
287
|
-
final ruleStartState = atn.ruleToStartState[p.ruleIndex];
|
|
288
|
-
if (ruleStartState.isLeftRecursiveRule) {
|
|
289
|
-
final parentContext =
|
|
290
|
-
_parentContextStack.removeLast();
|
|
291
|
-
unrollRecursionContexts(parentContext.a);
|
|
292
|
-
state = parentContext.b;
|
|
293
|
-
} else {
|
|
294
|
-
exitRule();
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
RuleTransition ruleTransition = atn.states[state].transition(0);
|
|
298
|
-
state = ruleTransition.followState.stateNumber;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
/// Override this parser interpreters normal decision-making process
|
|
302
|
-
/// at a particular decision and input token index. Instead of
|
|
303
|
-
/// allowing the adaptive prediction mechanism to choose the
|
|
304
|
-
/// first alternative within a block that leads to a successful parse,
|
|
305
|
-
/// force it to take the alternative, 1..n for n alternatives.
|
|
306
|
-
///
|
|
307
|
-
/// As an implementation limitation right now, you can only specify one
|
|
308
|
-
/// override. This is sufficient to allow construction of different
|
|
309
|
-
/// parse trees for ambiguous input. It means re-parsing the entire input
|
|
310
|
-
/// in general because you're never sure where an ambiguous sequence would
|
|
311
|
-
/// live in the various parse trees. For example, in one interpretation,
|
|
312
|
-
/// an ambiguous input sequence would be matched completely in expression
|
|
313
|
-
/// but in another it could match all the way back to the root.
|
|
314
|
-
///
|
|
315
|
-
/// s : e '!'? ;
|
|
316
|
-
/// e : ID
|
|
317
|
-
/// | ID '!'
|
|
318
|
-
/// ;
|
|
319
|
-
///
|
|
320
|
-
/// Here, x! can be matched as (s (e ID) !) or (s (e ID !)). In the first
|
|
321
|
-
/// case, the ambiguous sequence is fully contained only by the root.
|
|
322
|
-
/// In the second case, the ambiguous sequences fully contained within just
|
|
323
|
-
/// e, as in: (e ID !).
|
|
324
|
-
///
|
|
325
|
-
/// Rather than trying to optimize this and make
|
|
326
|
-
/// some intelligent decisions for optimization purposes, I settled on
|
|
327
|
-
/// just re-parsing the whole input and then using
|
|
328
|
-
/// {link Trees#getRootOfSubtreeEnclosingRegion} to find the minimal
|
|
329
|
-
/// subtree that contains the ambiguous sequence. I originally tried to
|
|
330
|
-
/// record the call stack at the point the parser detected and ambiguity but
|
|
331
|
-
/// left recursive rules create a parse tree stack that does not reflect
|
|
332
|
-
/// the actual call stack. That impedance mismatch was enough to make
|
|
333
|
-
/// it it challenging to restart the parser at a deeply nested rule
|
|
334
|
-
/// invocation.
|
|
335
|
-
///
|
|
336
|
-
/// Only parser interpreters can override decisions so as to avoid inserting
|
|
337
|
-
/// override checking code in the critical ALL(*) prediction execution path.
|
|
338
|
-
///
|
|
339
|
-
/// @since 4.5.1
|
|
340
|
-
void addDecisionOverride(int decision, int tokenIndex, int forcedAlt) {
|
|
341
|
-
overrideDecision = decision;
|
|
342
|
-
overrideDecisionInputIndex = tokenIndex;
|
|
343
|
-
overrideDecisionAlt = forcedAlt;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/// Rely on the error handler for this parser but, if no tokens are consumed
|
|
347
|
-
/// to recover, add an error node. Otherwise, nothing is seen in the parse
|
|
348
|
-
/// tree.
|
|
349
|
-
void recover(RecognitionException e) {
|
|
350
|
-
final i = inputStream.index;
|
|
351
|
-
errorHandler.recover(this, e);
|
|
352
|
-
if (inputStream.index == i) {
|
|
353
|
-
// no input consumed, better add an error node
|
|
354
|
-
if (e is InputMismatchException) {
|
|
355
|
-
final ime = e;
|
|
356
|
-
final tok = e.offendingToken;
|
|
357
|
-
var expectedTokenType = Token.INVALID_TYPE;
|
|
358
|
-
if (!ime.expectedTokens.isNil) {
|
|
359
|
-
expectedTokenType = ime.expectedTokens.minElement; // get any element
|
|
360
|
-
}
|
|
361
|
-
final errToken = tokenFactory.create(
|
|
362
|
-
expectedTokenType,
|
|
363
|
-
tok.text,
|
|
364
|
-
Pair(tok.tokenSource, tok.tokenSource.inputStream),
|
|
365
|
-
Token.DEFAULT_CHANNEL,
|
|
366
|
-
-1,
|
|
367
|
-
-1,
|
|
368
|
-
// invalid start/stop
|
|
369
|
-
tok.line,
|
|
370
|
-
tok.charPositionInLine);
|
|
371
|
-
context.addErrorNode(createErrorNode(context, errToken));
|
|
372
|
-
} else {
|
|
373
|
-
// NoViableAlt
|
|
374
|
-
final tok = e.offendingToken;
|
|
375
|
-
final errToken = tokenFactory.create(
|
|
376
|
-
Token.INVALID_TYPE,
|
|
377
|
-
tok.text,
|
|
378
|
-
Pair(tok.tokenSource, tok.tokenSource.inputStream),
|
|
379
|
-
Token.DEFAULT_CHANNEL,
|
|
380
|
-
-1,
|
|
381
|
-
-1,
|
|
382
|
-
// invalid start/stop
|
|
383
|
-
tok.line,
|
|
384
|
-
tok.charPositionInLine);
|
|
385
|
-
context.addErrorNode(createErrorNode(context, errToken));
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
Token recoverInline() {
|
|
391
|
-
return errorHandler.recoverInline(this);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
|
|
3
|
-
* Use of this file is governed by the BSD 3-clause license that
|
|
4
|
-
* can be found in the LICENSE.txt file in the project root.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import 'error/error.dart';
|
|
8
|
-
import 'interval_set.dart';
|
|
9
|
-
import 'parser.dart';
|
|
10
|
-
import 'rule_context.dart';
|
|
11
|
-
import 'token.dart';
|
|
12
|
-
import 'tree/tree.dart';
|
|
13
|
-
|
|
14
|
-
/// A rule invocation record for parsing.
|
|
15
|
-
///
|
|
16
|
-
/// Contains all of the information about the current rule not stored in the
|
|
17
|
-
/// RuleContext. It handles parse tree children list, Any ATN state
|
|
18
|
-
/// tracing, and the default values available for rule invocations:
|
|
19
|
-
/// start, stop, rule index, current alt number.
|
|
20
|
-
///
|
|
21
|
-
/// Subclasses made for each rule and grammar track the parameters,
|
|
22
|
-
/// return values, locals, and labels specific to that rule. These
|
|
23
|
-
/// are the objects that are returned from rules.
|
|
24
|
-
///
|
|
25
|
-
/// Note text is not an actual field of a rule return value; it is computed
|
|
26
|
-
/// from start and stop using the input stream's toString() method. I
|
|
27
|
-
/// could add a ctor to this so that we can pass in and store the input
|
|
28
|
-
/// stream, but I'm not sure we want to do that. It would seem to be undefined
|
|
29
|
-
/// to get the .text property anyway if the rule matches tokens from multiple
|
|
30
|
-
/// input streams.
|
|
31
|
-
///
|
|
32
|
-
/// I do not use getters for fields of objects that are used simply to
|
|
33
|
-
/// group values such as this aggregate. The getters/setters are there to
|
|
34
|
-
/// satisfy the superclass interface.
|
|
35
|
-
class ParserRuleContext extends RuleContext {
|
|
36
|
-
/// If we are debugging or building a parse tree for a visitor,
|
|
37
|
-
/// we need to track all of the tokens and rule invocations associated
|
|
38
|
-
/// with this rule's context. This is empty for parsing w/o tree constr.
|
|
39
|
-
/// operation because we don't the need to track the details about
|
|
40
|
-
/// how we parse this rule.
|
|
41
|
-
List<ParseTree> children;
|
|
42
|
-
|
|
43
|
-
/// Get the initial/final token in this context.
|
|
44
|
-
/// Note that the range from start to stop is inclusive, so for rules that do not consume anything
|
|
45
|
-
/// (for example, zero length or error productions) this token may exceed stop.
|
|
46
|
-
Token start, stop;
|
|
47
|
-
|
|
48
|
-
/// The exception that forced this rule to return. If the rule successfully
|
|
49
|
-
/// completed, this is null.
|
|
50
|
-
RecognitionException exception;
|
|
51
|
-
|
|
52
|
-
ParserRuleContext([RuleContext parent, int invokingStateNumber])
|
|
53
|
-
: super(parent: parent, invokingState: invokingStateNumber);
|
|
54
|
-
|
|
55
|
-
/// COPY a ctx (I'm deliberately not using copy constructor) to avoid
|
|
56
|
-
/// confusion with creating node with parent. Does not copy children
|
|
57
|
-
/// (except error leaves).
|
|
58
|
-
///
|
|
59
|
-
/// This is used in the generated parser code to flip a generic XContext
|
|
60
|
-
/// node for rule X to a YContext for alt label Y. In that sense, it is
|
|
61
|
-
/// not really a generic copy function.
|
|
62
|
-
///
|
|
63
|
-
/// If we do an error sync() at start of a rule, we might add error nodes
|
|
64
|
-
/// to the generic XContext so this function must copy those nodes to
|
|
65
|
-
/// the YContext as well else they are lost!
|
|
66
|
-
void copyFrom(ParserRuleContext ctx) {
|
|
67
|
-
parent = ctx.parent;
|
|
68
|
-
invokingState = ctx.invokingState;
|
|
69
|
-
|
|
70
|
-
start = ctx.start;
|
|
71
|
-
stop = ctx.stop;
|
|
72
|
-
|
|
73
|
-
// copy any error nodes to alt label node
|
|
74
|
-
if (ctx.children != null) {
|
|
75
|
-
children = [];
|
|
76
|
-
// reset parent pointer for any error nodes
|
|
77
|
-
for (var child in ctx.children) {
|
|
78
|
-
if (child is ErrorNode) {
|
|
79
|
-
addChild(child);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Double dispatch methods for listeners
|
|
86
|
-
|
|
87
|
-
void enterRule(ParseTreeListener listener) {}
|
|
88
|
-
|
|
89
|
-
void exitRule(ParseTreeListener listener) {}
|
|
90
|
-
|
|
91
|
-
/// Add a parse tree node to this as a child. Works for
|
|
92
|
-
/// internal and leaf nodes. Does not set parent link;
|
|
93
|
-
/// other add methods must do that. Other addChild methods
|
|
94
|
-
/// call this.
|
|
95
|
-
///
|
|
96
|
-
/// We cannot set the parent pointer of the incoming node
|
|
97
|
-
/// because the existing interfaces do not have a setParent()
|
|
98
|
-
/// method and I don't want to break backward compatibility for this.
|
|
99
|
-
///
|
|
100
|
-
/// @since 4.7
|
|
101
|
-
T addAnyChild<T extends ParseTree>(T t) {
|
|
102
|
-
children ??= [];
|
|
103
|
-
children.add(t);
|
|
104
|
-
return t;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/// Add a token leaf node child and force its parent to be this node. */
|
|
108
|
-
TerminalNode addChild(TerminalNode t) {
|
|
109
|
-
t.parent = this;
|
|
110
|
-
return addAnyChild(t);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/// Add an error node child and force its parent to be this node.
|
|
114
|
-
///
|
|
115
|
-
/// @since 4.7
|
|
116
|
-
ErrorNode addErrorNode(ErrorNode errorNode) {
|
|
117
|
-
errorNode.parent=this;
|
|
118
|
-
return addAnyChild(errorNode);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/// Used by enterOuterAlt to toss out a RuleContext previously added as
|
|
122
|
-
/// we entered a rule. If we have # label, we will need to remove
|
|
123
|
-
/// generic ruleContext object.
|
|
124
|
-
void removeLastChild() {
|
|
125
|
-
if (children != null) {
|
|
126
|
-
children.removeLast();
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// Override to make type more specific
|
|
131
|
-
@override
|
|
132
|
-
ParserRuleContext get parent {
|
|
133
|
-
return super.parent;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
@override
|
|
137
|
-
ParseTree getChild<T>(int i) {
|
|
138
|
-
if (children == null || i < 0 || i >= children.length) {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (T == null) {
|
|
143
|
-
return children[i];
|
|
144
|
-
}
|
|
145
|
-
var j = -1; // what element have we found with ctxType?
|
|
146
|
-
for (var o in children) {
|
|
147
|
-
if (o is T) {
|
|
148
|
-
j++;
|
|
149
|
-
if (j == i) {
|
|
150
|
-
return o;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return null;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
TerminalNode getToken(int ttype, int i) {
|
|
158
|
-
if (children == null || i < 0 || i >= children.length) {
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
var j = -1; // what token with ttype have we found?
|
|
163
|
-
for (var o in children) {
|
|
164
|
-
if (o is TerminalNode) {
|
|
165
|
-
final tnode = o;
|
|
166
|
-
final symbol = tnode.symbol;
|
|
167
|
-
if (symbol.type == ttype) {
|
|
168
|
-
j++;
|
|
169
|
-
if (j == i) {
|
|
170
|
-
return tnode;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return null;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
List<TerminalNode> getTokens(int ttype) {
|
|
180
|
-
if (children == null) {
|
|
181
|
-
return [];
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
List<TerminalNode> tokens;
|
|
185
|
-
for (var o in children) {
|
|
186
|
-
if (o is TerminalNode) {
|
|
187
|
-
final tnode = o;
|
|
188
|
-
final symbol = tnode.symbol;
|
|
189
|
-
if (symbol.type == ttype) {
|
|
190
|
-
tokens ??= [];
|
|
191
|
-
tokens.add(tnode);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (tokens == null) {
|
|
197
|
-
return [];
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return tokens;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
T getRuleContext<T extends ParserRuleContext>(int i) {
|
|
204
|
-
return getChild<T>(i);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
List<T> getRuleContexts<T extends ParserRuleContext>() {
|
|
208
|
-
if (children == null) {
|
|
209
|
-
return [];
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
List<T> contexts;
|
|
213
|
-
for (var o in children) {
|
|
214
|
-
if (o is T) {
|
|
215
|
-
contexts ??= [];
|
|
216
|
-
|
|
217
|
-
contexts.add(o);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
if (contexts == null) {
|
|
222
|
-
return [];
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
return contexts;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
@override
|
|
229
|
-
int get childCount => children?.length ?? 0;
|
|
230
|
-
|
|
231
|
-
@override
|
|
232
|
-
Interval get sourceInterval {
|
|
233
|
-
if (start == null) {
|
|
234
|
-
return Interval.INVALID;
|
|
235
|
-
}
|
|
236
|
-
if (stop == null || stop.tokenIndex < start.tokenIndex) {
|
|
237
|
-
return Interval(start.tokenIndex, start.tokenIndex - 1); // empty
|
|
238
|
-
}
|
|
239
|
-
return Interval(start.tokenIndex, stop.tokenIndex);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/// Used for rule context info debugging during parse-time, not so much for ATN debugging */
|
|
243
|
-
String toInfoString(Parser recognizer) {
|
|
244
|
-
final rules = recognizer.getRuleInvocationStack(this);
|
|
245
|
-
|
|
246
|
-
return "ParserRuleContext${rules.reversed}{start=$start, stop=$stop}'";
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
static final EMPTY = ParserRuleContext();
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/// This class extends [ParserRuleContext] by allowing the value of
|
|
253
|
-
/// {@link #getRuleIndex} to be explicitly set for the context.
|
|
254
|
-
///
|
|
255
|
-
/// <p>
|
|
256
|
-
/// [ParserRuleContext] does not include field storage for the rule index
|
|
257
|
-
/// since the context classes created by the code generator override the
|
|
258
|
-
/// {@link #getRuleIndex} method to return the correct value for that context.
|
|
259
|
-
/// Since the parser interpreter does not use the context classes generated for a
|
|
260
|
-
/// parser, this class (with slightly more memory overhead per node) is used to
|
|
261
|
-
/// provide equivalent functionality.</p>
|
|
262
|
-
class InterpreterRuleContext extends ParserRuleContext {
|
|
263
|
-
@override
|
|
264
|
-
int ruleIndex = -1;
|
|
265
|
-
|
|
266
|
-
/// Constructs a new [InterpreterRuleContext] with the specified
|
|
267
|
-
/// parent, invoking state, and rule index.
|
|
268
|
-
///
|
|
269
|
-
/// @param parent The parent context.
|
|
270
|
-
/// @param invokingStateNumber The invoking state number.
|
|
271
|
-
/// @param ruleIndex The rule index for the current context.
|
|
272
|
-
InterpreterRuleContext(
|
|
273
|
-
ParserRuleContext parent, int invokingStateNumber, this.ruleIndex)
|
|
274
|
-
: super(parent, invokingStateNumber);
|
|
275
|
-
}
|