@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.
Files changed (158) hide show
  1. package/__tests__/end-to-end.test.ts +256 -0
  2. package/coverage/clover.xml +12857 -0
  3. package/coverage/coverage-final.json +3 -0
  4. package/coverage/lcov-report/base.css +224 -0
  5. package/coverage/lcov-report/block-navigation.js +79 -0
  6. package/coverage/lcov-report/favicon.png +0 -0
  7. package/coverage/lcov-report/index.html +126 -0
  8. package/coverage/lcov-report/index.js.html +104 -0
  9. package/coverage/lcov-report/out.js.html +41126 -0
  10. package/coverage/lcov-report/prettify.css +1 -0
  11. package/coverage/lcov-report/prettify.js +2 -0
  12. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  13. package/coverage/lcov-report/sorter.js +170 -0
  14. package/coverage/lcov.info +24801 -0
  15. package/index.d.ts +118 -0
  16. package/index.js +8 -0
  17. package/index.ts +141 -0
  18. package/jest.config.js +11 -0
  19. package/out.js +13708 -0
  20. package/package.json +22 -17
  21. package/tsconfig.json +5 -3
  22. package/.idea/apexdocs-dart.iml +0 -18
  23. package/.idea/jsLibraryMappings.xml +0 -6
  24. package/.idea/libraries/Dart_Packages.xml +0 -556
  25. package/.idea/libraries/Dart_SDK.xml +0 -28
  26. package/.idea/misc.xml +0 -6
  27. package/.idea/modules.xml +0 -8
  28. package/.idea/runConfigurations/_template__of_Dart_Test.xml +0 -6
  29. package/.idea/vcs.xml +0 -6
  30. package/CHANGELOG.md +0 -3
  31. package/README.md +0 -26
  32. package/TODO.md +0 -5
  33. package/analysis_options.yaml +0 -30
  34. package/antlr4-4.9.2/CHANGELOG.md +0 -4
  35. package/antlr4-4.9.2/LICENSE +0 -52
  36. package/antlr4-4.9.2/README.md +0 -11
  37. package/antlr4-4.9.2/analysis_options.yaml +0 -1
  38. package/antlr4-4.9.2/lib/antlr4.dart +0 -21
  39. package/antlr4-4.9.2/lib/src/atn/atn.dart +0 -18
  40. package/antlr4-4.9.2/lib/src/atn/src/atn.dart +0 -170
  41. package/antlr4-4.9.2/lib/src/atn/src/atn_config.dart +0 -242
  42. package/antlr4-4.9.2/lib/src/atn/src/atn_config_set.dart +0 -283
  43. package/antlr4-4.9.2/lib/src/atn/src/atn_deserializer.dart +0 -809
  44. package/antlr4-4.9.2/lib/src/atn/src/atn_simulator.dart +0 -95
  45. package/antlr4-4.9.2/lib/src/atn/src/atn_state.dart +0 -296
  46. package/antlr4-4.9.2/lib/src/atn/src/atn_type.dart +0 -14
  47. package/antlr4-4.9.2/lib/src/atn/src/info.dart +0 -553
  48. package/antlr4-4.9.2/lib/src/atn/src/lexer_action.dart +0 -601
  49. package/antlr4-4.9.2/lib/src/atn/src/lexer_action_executor.dart +0 -167
  50. package/antlr4-4.9.2/lib/src/atn/src/lexer_atn_simulator.dart +0 -731
  51. package/antlr4-4.9.2/lib/src/atn/src/parser_atn_simulator.dart +0 -2630
  52. package/antlr4-4.9.2/lib/src/atn/src/profiling_atn_simulator.dart +0 -229
  53. package/antlr4-4.9.2/lib/src/atn/src/semantic_context.dart +0 -404
  54. package/antlr4-4.9.2/lib/src/atn/src/transition.dart +0 -305
  55. package/antlr4-4.9.2/lib/src/dfa/dfa.dart +0 -8
  56. package/antlr4-4.9.2/lib/src/dfa/src/dfa.dart +0 -138
  57. package/antlr4-4.9.2/lib/src/dfa/src/dfa_serializer.dart +0 -76
  58. package/antlr4-4.9.2/lib/src/dfa/src/dfa_state.dart +0 -151
  59. package/antlr4-4.9.2/lib/src/error/error.dart +0 -10
  60. package/antlr4-4.9.2/lib/src/error/src/diagnostic_error_listener.dart +0 -116
  61. package/antlr4-4.9.2/lib/src/error/src/error_listener.dart +0 -241
  62. package/antlr4-4.9.2/lib/src/error/src/error_strategy.dart +0 -902
  63. package/antlr4-4.9.2/lib/src/error/src/errors.dart +0 -204
  64. package/antlr4-4.9.2/lib/src/input_stream.dart +0 -335
  65. package/antlr4-4.9.2/lib/src/interval_set.dart +0 -735
  66. package/antlr4-4.9.2/lib/src/lexer.dart +0 -343
  67. package/antlr4-4.9.2/lib/src/ll1_analyzer.dart +0 -204
  68. package/antlr4-4.9.2/lib/src/misc/multi_map.dart +0 -32
  69. package/antlr4-4.9.2/lib/src/misc/pair.dart +0 -34
  70. package/antlr4-4.9.2/lib/src/parser.dart +0 -777
  71. package/antlr4-4.9.2/lib/src/parser_interpreter.dart +0 -393
  72. package/antlr4-4.9.2/lib/src/parser_rule_context.dart +0 -275
  73. package/antlr4-4.9.2/lib/src/prediction_context.dart +0 -877
  74. package/antlr4-4.9.2/lib/src/recognizer.dart +0 -182
  75. package/antlr4-4.9.2/lib/src/rule_context.dart +0 -192
  76. package/antlr4-4.9.2/lib/src/runtime_meta_data.dart +0 -188
  77. package/antlr4-4.9.2/lib/src/token.dart +0 -431
  78. package/antlr4-4.9.2/lib/src/token_factory.dart +0 -88
  79. package/antlr4-4.9.2/lib/src/token_source.dart +0 -241
  80. package/antlr4-4.9.2/lib/src/token_stream.dart +0 -627
  81. package/antlr4-4.9.2/lib/src/tree/src/pattern/chunk.dart +0 -90
  82. package/antlr4-4.9.2/lib/src/tree/src/pattern/parse_tree_match.dart +0 -635
  83. package/antlr4-4.9.2/lib/src/tree/src/tree.dart +0 -370
  84. package/antlr4-4.9.2/lib/src/tree/src/trees.dart +0 -226
  85. package/antlr4-4.9.2/lib/src/tree/tree.dart +0 -10
  86. package/antlr4-4.9.2/lib/src/util/bit_set.dart +0 -308
  87. package/antlr4-4.9.2/lib/src/util/murmur_hash.dart +0 -77
  88. package/antlr4-4.9.2/lib/src/util/utils.dart +0 -31
  89. package/antlr4-4.9.2/lib/src/vocabulary.dart +0 -254
  90. package/antlr4-4.9.2/pubspec.yaml +0 -13
  91. package/example/node_example/index.js +0 -8
  92. package/example/node_example/package.json +0 -12
  93. package/example/node_example_ts/package-lock.json +0 -70
  94. package/example/node_example_ts/package.json +0 -19
  95. package/example/node_example_ts/src/index.js +0 -5
  96. package/example/node_example_ts/src/index.ts +0 -9
  97. package/example/node_example_ts/tsconfig.json +0 -79
  98. package/js/dart2jsout.js +0 -25898
  99. package/js/dart2jsout.js.map +0 -16
  100. package/js/index.d.ts +0 -1
  101. package/js/index.js +0 -4
  102. package/js/out.js +0 -26023
  103. package/js/out.js.map +0 -16
  104. package/js/package-lock.json +0 -57
  105. package/js/preamble.js +0 -125
  106. package/lib/apexdocs_dart.dart +0 -28
  107. package/lib/src/antlr/grammars/Apexdoc/ApexdocLexer.g4 +0 -120
  108. package/lib/src/antlr/grammars/Apexdoc/ApexdocParser.g4 +0 -158
  109. package/lib/src/antlr/grammars/Apexdoc/gen/ApexdocLexer.interp +0 -95
  110. package/lib/src/antlr/grammars/Apexdoc/gen/ApexdocLexer.java +0 -238
  111. package/lib/src/antlr/grammars/Apexdoc/gen/ApexdocLexer.tokens +0 -23
  112. package/lib/src/antlr/grammars/apex/ApexLexer.g4 +0 -255
  113. package/lib/src/antlr/grammars/apex/ApexParser.g4 +0 -567
  114. package/lib/src/antlr/grammars/apex/examples/ApexClass.cls +0 -6
  115. package/lib/src/antlr/lib/apex/ApexLexer.dart +0 -1223
  116. package/lib/src/antlr/lib/apex/ApexLexer.interp +0 -393
  117. package/lib/src/antlr/lib/apex/ApexLexer.tokens +0 -212
  118. package/lib/src/antlr/lib/apex/ApexParser.dart +0 -9349
  119. package/lib/src/antlr/lib/apex/ApexParser.interp +0 -326
  120. package/lib/src/antlr/lib/apex/ApexParser.tokens +0 -212
  121. package/lib/src/antlr/lib/apex/ApexParserBaseListener.dart +0 -1036
  122. package/lib/src/antlr/lib/apex/ApexParserListener.dart +0 -975
  123. package/lib/src/antlr/lib/apexdoc/ApexdocLexer.dart +0 -373
  124. package/lib/src/antlr/lib/apexdoc/ApexdocLexer.interp +0 -95
  125. package/lib/src/antlr/lib/apexdoc/ApexdocLexer.tokens +0 -23
  126. package/lib/src/antlr/lib/apexdoc/ApexdocParser.dart +0 -2471
  127. package/lib/src/antlr/lib/apexdoc/ApexdocParser.interp +0 -69
  128. package/lib/src/antlr/lib/apexdoc/ApexdocParser.tokens +0 -23
  129. package/lib/src/antlr/lib/apexdoc/ApexdocParserBaseListener.dart +0 -252
  130. package/lib/src/antlr/lib/apexdoc/ApexdocParserListener.dart +0 -215
  131. package/lib/src/builders/builders.dart +0 -32
  132. package/lib/src/model/apex_file_manifest.dart +0 -37
  133. package/lib/src/model/apex_file_manifest.g.dart +0 -18
  134. package/lib/src/model/declaration.dart +0 -50
  135. package/lib/src/model/doc_comment.dart +0 -117
  136. package/lib/src/model/doc_comment.g.dart +0 -118
  137. package/lib/src/model/members.dart +0 -143
  138. package/lib/src/model/members.g.dart +0 -105
  139. package/lib/src/model/types.dart +0 -159
  140. package/lib/src/model/types.g.dart +0 -111
  141. package/lib/src/service/apex_listener.dart +0 -226
  142. package/lib/src/service/apexdoc_listener.dart +0 -82
  143. package/lib/src/service/parsers.dart +0 -33
  144. package/lib/src/service/utils/parsing/access_modifiers_parser.dart +0 -33
  145. package/lib/src/service/utils/parsing/parameters_parser.dart +0 -18
  146. package/lib/src/service/utils/parsing/parsing_utils.dart +0 -2
  147. package/lib/src/service/walker.dart +0 -82
  148. package/pubspec.yaml +0 -19
  149. package/test/apex_file_manifest_test.dart +0 -16
  150. package/test/apex_listener_test.dart +0 -703
  151. package/test/apexdoc_parser_test.dart +0 -179
  152. package/test/doc_comment_test.dart +0 -89
  153. package/test/members_serialization_test.dart +0 -158
  154. package/test/members_test.dart +0 -178
  155. package/test/types_serialization_test.dart +0 -191
  156. package/test/types_test.dart +0 -311
  157. package/test/walker_test.dart +0 -58
  158. package/tool/grind.dart +0 -20
@@ -1,777 +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:io';
8
-
9
- import 'atn/atn.dart';
10
- import 'error/error.dart';
11
- import 'input_stream.dart';
12
- import 'interval_set.dart';
13
- import 'lexer.dart';
14
- import 'parser_rule_context.dart';
15
- import 'recognizer.dart';
16
- import 'rule_context.dart';
17
- import 'token.dart';
18
- import 'token_factory.dart';
19
- import 'token_stream.dart';
20
- import 'tree/tree.dart';
21
-
22
- /// This is all the parsing support code essentially; most of it is error recovery stuff. */
23
- abstract class Parser extends Recognizer<ParserATNSimulator> {
24
- /// This field maps from the serialized ATN string to the deserialized [ATN] with
25
- /// bypass alternatives.
26
- ///
27
- /// @see ATNDeserializationOptions#isGenerateRuleBypassTransitions()
28
- static final Map<String, ATN> bypassAltsAtnCache = {};
29
-
30
- /// The error handling strategy for the parser. The default value is a new
31
- /// instance of [DefaultErrorStrategy].
32
- ///
33
- /// @see #getErrorHandler
34
- /// @see #setErrorHandler
35
-
36
- ErrorStrategy errorHandler = DefaultErrorStrategy();
37
-
38
- /// The input stream.
39
- ///
40
- /// @see #getInputStream
41
- /// @see #setInputStream
42
- TokenStream _input;
43
-
44
- final List<int> _precedenceStack = [0];
45
-
46
- /// The [ParserRuleContext] object for the currently executing rule.
47
- /// This is always non-null during the parsing process.
48
- ParserRuleContext _ctx;
49
-
50
- /// Specifies whether or not the parser should construct a parse tree during
51
- /// the parsing process. The default value is [true].
52
- ///
53
- /// @see #getBuildParseTree
54
- /// @see #setBuildParseTree
55
- bool _buildParseTrees = true;
56
-
57
- /// When {@link #setTrace}{@code (true)} is called, a reference to the
58
- /// [TraceListener] is stored here so it can be easily removed in a
59
- /// later call to {@link #setTrace}{@code (false)}. The listener itself is
60
- /// implemented as a parser listener so this field is not directly used by
61
- /// other parser methods.
62
- TraceListener _tracer;
63
-
64
- /// The list of [ParseTreeListener] listeners registered to receive
65
- /// events during the parse.
66
- ///
67
- /// @see #addParseListener
68
- List<ParseTreeListener> _parseListeners;
69
-
70
- /// The number of syntax errors reported during parsing. This value is
71
- /// incremented each time {@link #notifyErrorListeners} is called.
72
- int _syntaxErrors = 0;
73
-
74
- /// Indicates parser has match()ed EOF token. See {@link #exitRule()}. */
75
- bool matchedEOF = false;
76
-
77
- Parser(TokenStream input) {
78
- inputStream = input;
79
- }
80
-
81
- /// reset the parser's state */
82
- void reset() {
83
- if (inputStream != null) inputStream.seek(0);
84
- errorHandler.reset(this);
85
- _ctx = null;
86
- _syntaxErrors = 0;
87
- matchedEOF = false;
88
- setTrace(false);
89
- _precedenceStack.clear();
90
- _precedenceStack.add(0);
91
- if (interpreter != null) {
92
- interpreter.reset();
93
- }
94
- }
95
-
96
- /// Match current input symbol against [ttype]. If the symbol type
97
- /// matches, {@link ANTLRErrorStrategy#reportMatch} and {@link #consume} are
98
- /// called to complete the match process.
99
- ///
100
- /// <p>If the symbol type does not match,
101
- /// {@link ANTLRErrorStrategy#recoverInline} is called on the current error
102
- /// strategy to attempt recovery. If {@link #getBuildParseTree} is
103
- /// [true] and the token index of the symbol returned by
104
- /// {@link ANTLRErrorStrategy#recoverInline} is -1, the symbol is added to
105
- /// the parse tree by calling {@link #createErrorNode(ParserRuleContext, Token)} then
106
- /// {@link ParserRuleContext#addErrorNode(ErrorNode)}.</p>
107
- ///
108
- /// @param ttype the token type to match
109
- /// @return the matched symbol
110
- /// @throws RecognitionException if the current input symbol did not match
111
- /// [ttype] and the error strategy could not recover from the
112
- /// mismatched symbol
113
- Token match(int ttype) {
114
- var t = currentToken;
115
- if (t.type == ttype) {
116
- if (ttype == Token.EOF) {
117
- matchedEOF = true;
118
- }
119
- errorHandler.reportMatch(this);
120
- consume();
121
- } else {
122
- t = errorHandler.recoverInline(this);
123
- if (_buildParseTrees && t.tokenIndex == -1) {
124
- // we must have conjured up a new token during single token insertion
125
- // if it's not the current symbol
126
- _ctx.addErrorNode(createErrorNode(_ctx, t));
127
- }
128
- }
129
- return t;
130
- }
131
-
132
- /// Match current input symbol as a wildcard. If the symbol type matches
133
- /// (i.e. has a value greater than 0), {@link ANTLRErrorStrategy#reportMatch}
134
- /// and {@link #consume} are called to complete the match process.
135
- ///
136
- /// <p>If the symbol type does not match,
137
- /// {@link ANTLRErrorStrategy#recoverInline} is called on the current error
138
- /// strategy to attempt recovery. If {@link #getBuildParseTree} is
139
- /// [true] and the token index of the symbol returned by
140
- /// {@link ANTLRErrorStrategy#recoverInline} is -1, the symbol is added to
141
- /// the parse tree by calling {@link Parser#createErrorNode(ParserRuleContext, Token)}. then
142
- /// {@link ParserRuleContext#addErrorNode(ErrorNode)}</p>
143
- ///
144
- /// @return the matched symbol
145
- /// @throws RecognitionException if the current input symbol did not match
146
- /// a wildcard and the error strategy could not recover from the mismatched
147
- /// symbol
148
- Token matchWildcard() {
149
- var t = currentToken;
150
- if (t.type > 0) {
151
- errorHandler.reportMatch(this);
152
- consume();
153
- } else {
154
- t = errorHandler.recoverInline(this);
155
- if (_buildParseTrees && t.tokenIndex == -1) {
156
- // we must have conjured up a new token during single token insertion
157
- // if it's not the current symbol
158
- _ctx.addErrorNode(createErrorNode(_ctx, t));
159
- }
160
- }
161
-
162
- return t;
163
- }
164
-
165
- /// Track the [ParserRuleContext] objects during the parse and hook
166
- /// them up using the {@link ParserRuleContext#children} list so that it
167
- /// forms a parse tree. The [ParserRuleContext] returned from the start
168
- /// rule represents the root of the parse tree.
169
- ///
170
- /// <p>Note that if we are not building parse trees, rule contexts only point
171
- /// upwards. When a rule exits, it returns the context but that gets garbage
172
- /// collected if nobody holds a reference. It points upwards but nobody
173
- /// points at it.</p>
174
- ///
175
- /// <p>When we build parse trees, we are adding all of these contexts to
176
- /// {@link ParserRuleContext#children} list. Contexts are then not candidates
177
- /// for garbage collection.</p>
178
- set buildParseTree(bool buildParseTrees) {
179
- _buildParseTrees = buildParseTrees;
180
- }
181
-
182
- /// Gets whether or not a complete parse tree will be constructed while
183
- /// parsing. This property is [true] for a newly constructed parser.
184
- ///
185
- /// @return [true] if a complete parse tree will be constructed while
186
- /// parsing, otherwise [false]
187
- bool get buildParseTree {
188
- return _buildParseTrees;
189
- }
190
-
191
- /// Trim the internal lists of the parse tree during parsing to conserve memory.
192
- /// This property is set to [false] by default for a newly constructed parser.
193
- ///
194
- /// @param trimParseTrees [true] to trim the capacity of the {@link ParserRuleContext#children}
195
- /// list to its size after a rule is parsed.
196
- set trimParseTree(bool trimParseTrees) {
197
- if (trimParseTrees) {
198
- if (trimParseTree) return;
199
- addParseListener(TrimToSizeListener.INSTANCE);
200
- } else {
201
- removeParseListener(TrimToSizeListener.INSTANCE);
202
- }
203
- }
204
-
205
- /// @return [true] if the {@link ParserRuleContext#children} list is trimmed
206
- /// using the default {@link Parser.TrimToSizeListener} during the parse process.
207
- bool get trimParseTree {
208
- return parseListeners.contains(TrimToSizeListener.INSTANCE);
209
- }
210
-
211
- List<ParseTreeListener> get parseListeners => _parseListeners;
212
-
213
- /// Registers [listener] to receive events during the parsing process.
214
- ///
215
- /// <p>To support output-preserving grammar transformations (including but not
216
- /// limited to left-recursion removal, automated left-factoring, and
217
- /// optimized code generation), calls to listener methods during the parse
218
- /// may differ substantially from calls made by
219
- /// {@link ParseTreeWalker#DEFAULT} used after the parse is complete. In
220
- /// particular, rule entry and exit events may occur in a different order
221
- /// during the parse than after the parser. In addition, calls to certain
222
- /// rule entry methods may be omitted.</p>
223
- ///
224
- /// <p>With the following specific exceptions, calls to listener events are
225
- /// <em>deterministic</em>, i.e. for identical input the calls to listener
226
- /// methods will be the same.</p>
227
- ///
228
- /// <ul>
229
- /// <li>Alterations to the grammar used to generate code may change the
230
- /// behavior of the listener calls.</li>
231
- /// <li>Alterations to the command line options passed to ANTLR 4 when
232
- /// generating the parser may change the behavior of the listener calls.</li>
233
- /// <li>Changing the version of the ANTLR Tool used to generate the parser
234
- /// may change the behavior of the listener calls.</li>
235
- /// </ul>
236
- ///
237
- /// @param listener the listener to add
238
- ///
239
- /// @throws NullPointerException if {@code} listener is null
240
- void addParseListener(ParseTreeListener listener) {
241
- if (listener == null) {
242
- throw ArgumentError.notNull('listener');
243
- }
244
-
245
- _parseListeners ??= [];
246
-
247
- _parseListeners.add(listener);
248
- }
249
-
250
- /// Remove [listener] from the list of parse listeners.
251
- ///
252
- /// <p>If [listener] is null or has not been added as a parse
253
- /// listener, this method does nothing.</p>
254
- ///
255
- /// @see #addParseListener
256
- ///
257
- /// @param listener the listener to remove
258
- void removeParseListener(ParseTreeListener listener) {
259
- if (_parseListeners != null) {
260
- if (_parseListeners.remove(listener)) {
261
- if (_parseListeners.isEmpty) {
262
- _parseListeners = null;
263
- }
264
- }
265
- }
266
- }
267
-
268
- /// Remove all parse listeners.
269
- ///
270
- /// @see #addParseListener
271
- void removeParseListeners() {
272
- _parseListeners = null;
273
- }
274
-
275
- /// Notify any parse listeners of an enter rule event.
276
- ///
277
- /// @see #addParseListener
278
- void triggerEnterRuleEvent() {
279
- for (var listener in _parseListeners) {
280
- listener.enterEveryRule(_ctx);
281
- _ctx.enterRule(listener);
282
- }
283
- }
284
-
285
- /// Notify any parse listeners of an exit rule event.
286
- ///
287
- /// @see #addParseListener
288
- void triggerExitRuleEvent() {
289
- // reverse order walk of listeners
290
- for (var i = _parseListeners.length - 1; i >= 0; i--) {
291
- final listener = _parseListeners[i];
292
- _ctx.exitRule(listener);
293
- listener.exitEveryRule(_ctx);
294
- }
295
- }
296
-
297
- /// Gets the number of syntax errors reported during parsing. This value is
298
- /// incremented each time {@link #notifyErrorListeners} is called.
299
- ///
300
- /// @see #notifyErrorListeners
301
- int get numberOfSyntaxErrors {
302
- return _syntaxErrors;
303
- }
304
-
305
- @override
306
- TokenFactory get tokenFactory {
307
- return _input.tokenSource.tokenFactory;
308
- }
309
-
310
- /// Tell our token source and error strategy about a new way to create tokens. */
311
- @override
312
- set tokenFactory(TokenFactory factory) {
313
- _input.tokenSource.tokenFactory = factory;
314
- }
315
-
316
- /// The ATN with bypass alternatives is expensive to create so we create it
317
- /// lazily.
318
- ///
319
- /// @throws UnsupportedOperationException if the current parser does not
320
- /// implement the {@link #getSerializedATN()} method.
321
- ATN get ATNWithBypassAlts {
322
- final serializedAtn = serializedATN;
323
- if (serializedAtn == null) {
324
- throw UnsupportedError(
325
- 'The current parser does not support an ATN with bypass alternatives.');
326
- }
327
-
328
- var result = bypassAltsAtnCache[serializedAtn];
329
- if (result == null) {
330
- final deserializationOptions =
331
- ATNDeserializationOptions();
332
- deserializationOptions.setGenerateRuleBypassTransitions(true);
333
- result = ATNDeserializer(deserializationOptions)
334
- .deserialize(serializedAtn.codeUnits);
335
- bypassAltsAtnCache[serializedAtn] = result;
336
- }
337
-
338
- return result;
339
- }
340
-
341
- /// The preferred method of getting a tree pattern. For example, here's a
342
- /// sample use:
343
- ///
344
- /// <pre>
345
- /// ParseTree t = parser.expr();
346
- /// ParseTreePattern p = parser.compileParseTreePattern("&lt;ID&gt;+0", MyParser.RULE_expr);
347
- /// ParseTreeMatch m = p.match(t);
348
- /// String id = m.get("ID");
349
- /// </pre>
350
- ParseTreePattern compileParseTreePattern(String pattern, int patternRuleIndex,
351
- [Lexer lexer]) {
352
- if (lexer == null) {
353
- final tokenSource = tokenStream?.tokenSource;
354
- if (tokenSource == null || !(tokenSource is Lexer)) {
355
- throw UnsupportedError("Parser can't discover a lexer to use");
356
- }
357
- lexer = tokenSource;
358
- }
359
-
360
- final m = ParseTreePatternMatcher(lexer, this);
361
- return m.compile(pattern, patternRuleIndex);
362
- }
363
-
364
- @override
365
- TokenStream get inputStream => tokenStream;
366
-
367
- @override
368
- set inputStream(IntStream input) {
369
- setTokenStream(input);
370
- }
371
-
372
- TokenStream get tokenStream => _input;
373
-
374
- /// Set the token stream and reset the parser. */
375
- void setTokenStream(TokenStream input) {
376
- _input = null;
377
- reset();
378
- _input = input;
379
- }
380
-
381
- /// Match needs to return the current input symbol, which gets put
382
- /// into the label for the associated token ref; e.g., x=ID.
383
-
384
- Token get currentToken {
385
- return _input.LT(1);
386
- }
387
-
388
- void notifyErrorListeners(String msg,
389
- [Token offendingToken, RecognitionException e]) {
390
- offendingToken = offendingToken ?? currentToken;
391
- _syntaxErrors++;
392
- var line = -1;
393
- var charPositionInLine = -1;
394
- line = offendingToken.line;
395
- charPositionInLine = offendingToken.charPositionInLine;
396
-
397
- final listener = errorListenerDispatch;
398
- listener.syntaxError(
399
- this, offendingToken, line, charPositionInLine, msg, e);
400
- }
401
-
402
- /// Consume and return the {@linkplain #getCurrentToken current symbol}.
403
- ///
404
- /// <p>E.g., given the following input with [A] being the current
405
- /// lookahead symbol, this function moves the cursor to [B] and returns
406
- /// [A].</p>
407
- ///
408
- /// <pre>
409
- /// A B
410
- /// ^
411
- /// </pre>
412
- ///
413
- /// If the parser is not in error recovery mode, the consumed symbol is added
414
- /// to the parse tree using {@link ParserRuleContext#addChild}, and
415
- /// {@link ParseTreeListener#visitTerminal} is called on any parse listeners.
416
- /// If the parser <em>is</em> in error recovery mode, the consumed symbol is
417
- /// added to the parse tree using {@link #createErrorNode(ParserRuleContext, Token)} then
418
- /// {@link ParserRuleContext#addErrorNode(ErrorNode)} and
419
- /// {@link ParseTreeListener#visitErrorNode} is called on any parse
420
- /// listeners.
421
- Token consume() {
422
- final o = currentToken;
423
- if (o.type != IntStream.EOF) {
424
- inputStream.consume();
425
- }
426
- final hasListener = _parseListeners != null && _parseListeners.isNotEmpty;
427
- if (_buildParseTrees || hasListener) {
428
- if (errorHandler.inErrorRecoveryMode(this)) {
429
- final node = _ctx.addErrorNode(createErrorNode(_ctx, o));
430
- if (_parseListeners != null) {
431
- for (var listener in _parseListeners) {
432
- listener.visitErrorNode(node);
433
- }
434
- }
435
- } else {
436
- final node = _ctx.addChild(createTerminalNode(_ctx, o));
437
- if (_parseListeners != null) {
438
- for (var listener in _parseListeners) {
439
- listener.visitTerminal(node);
440
- }
441
- }
442
- }
443
- }
444
- return o;
445
- }
446
-
447
- /// How to create a token leaf node associated with a parent.
448
- /// Typically, the terminal node to create is not a function of the parent.
449
- ///
450
- /// @since 4.7
451
- TerminalNode createTerminalNode(ParserRuleContext parent, Token t) {
452
- return TerminalNodeImpl(t);
453
- }
454
-
455
- /// How to create an error node, given a token, associated with a parent.
456
- /// Typically, the error node to create is not a function of the parent.
457
- ///
458
- /// @since 4.7
459
- ErrorNode createErrorNode(ParserRuleContext parent, Token t) {
460
- return ErrorNodeImpl(t);
461
- }
462
-
463
- void addContextToParseTree() {
464
- final parent = _ctx.parent;
465
- // add current context to parent if we have a parent
466
- if (parent != null) {
467
- parent.addAnyChild(_ctx);
468
- }
469
- }
470
-
471
- /// Always called by generated parsers upon entry to a rule. Access field
472
- /// {@link #_ctx} get the current context.
473
- void enterRule(ParserRuleContext localctx, int state, int ruleIndex) {
474
- this.state = state;
475
- _ctx = localctx;
476
- _ctx.start = _input.LT(1);
477
- if (_buildParseTrees) addContextToParseTree();
478
- if (_parseListeners != null) triggerEnterRuleEvent();
479
- }
480
-
481
- void exitRule() {
482
- if (matchedEOF) {
483
- // if we have matched EOF, it cannot consume past EOF so we use LT(1) here
484
- _ctx.stop = _input.LT(1); // LT(1) will be end of file
485
- } else {
486
- _ctx.stop = _input.LT(-1); // stop node is what we just matched
487
- }
488
- // trigger event on _ctx, before it reverts to parent
489
- if (_parseListeners != null) triggerExitRuleEvent();
490
- state = _ctx.invokingState;
491
- _ctx = _ctx.parent;
492
- }
493
-
494
- void enterOuterAlt(ParserRuleContext localctx, int altNum) {
495
- localctx.altNumber = altNum;
496
- // if we have new localctx, make sure we replace existing ctx
497
- // that is previous child of parse tree
498
- if (_buildParseTrees && _ctx != localctx) {
499
- final parent = _ctx.parent;
500
- if (parent != null) {
501
- parent.removeLastChild();
502
- parent.addAnyChild(localctx);
503
- }
504
- }
505
- _ctx = localctx;
506
- }
507
-
508
- /// Get the precedence level for the top-most precedence rule.
509
- ///
510
- /// @return The precedence level for the top-most precedence rule, or -1 if
511
- /// the parser context is not nested within a precedence rule.
512
- int get precedence {
513
- if (_precedenceStack.isEmpty) {
514
- return -1;
515
- }
516
-
517
- return _precedenceStack.last;
518
- }
519
-
520
- void enterRecursionRule(
521
- ParserRuleContext localctx, int state, int ruleIndex, int precedence) {
522
- this.state = state;
523
- _precedenceStack.add(precedence);
524
- _ctx = localctx;
525
- _ctx.start = _input.LT(1);
526
- if (_parseListeners != null) {
527
- triggerEnterRuleEvent(); // simulates rule entry for left-recursive rules
528
- }
529
- }
530
-
531
- /// Like {@link #enterRule} but for recursive rules.
532
- /// Make the current context the child of the incoming localctx.
533
- void pushNewRecursionContext(
534
- ParserRuleContext localctx, int state, int ruleIndex) {
535
- final previous = _ctx;
536
- previous.parent = localctx;
537
- previous.invokingState = state;
538
- previous.stop = _input.LT(-1);
539
-
540
- _ctx = localctx;
541
- _ctx.start = previous.start;
542
- if (_buildParseTrees) {
543
- _ctx.addAnyChild(previous);
544
- }
545
-
546
- if (_parseListeners != null) {
547
- triggerEnterRuleEvent(); // simulates rule entry for left-recursive rules
548
- }
549
- }
550
-
551
- void unrollRecursionContexts(ParserRuleContext _parentctx) {
552
- _precedenceStack.removeLast();
553
- _ctx.stop = _input.LT(-1);
554
- final retctx = _ctx; // save current ctx (return value)
555
-
556
- // unroll so _ctx is as it was before call to recursive method
557
- if (_parseListeners != null) {
558
- while (_ctx != _parentctx) {
559
- triggerExitRuleEvent();
560
- _ctx = _ctx.parent;
561
- }
562
- } else {
563
- _ctx = _parentctx;
564
- }
565
-
566
- // hook into tree
567
- retctx.parent = _parentctx;
568
-
569
- if (_buildParseTrees && _parentctx != null) {
570
- // add return ctx into invoking rule's tree
571
- _parentctx.addAnyChild(retctx);
572
- }
573
- }
574
-
575
- ParserRuleContext getInvokingContext(int ruleIndex) {
576
- var p = _ctx;
577
- while (p != null) {
578
- if (p.ruleIndex == ruleIndex) return p;
579
- p = p.parent;
580
- }
581
- return null;
582
- }
583
-
584
- ParserRuleContext get context {
585
- return _ctx;
586
- }
587
-
588
- set context(ParserRuleContext ctx) {
589
- _ctx = ctx;
590
- }
591
-
592
- @override
593
- bool precpred(RuleContext localctx, int precedence) {
594
- return precedence >= _precedenceStack.last;
595
- }
596
-
597
- bool inContext(String context) {
598
- // TODO: useful in parser?
599
- return false;
600
- }
601
-
602
- /// Checks whether or not [symbol] can follow the current state in the
603
- /// ATN. The behavior of this method is equivalent to the following, but is
604
- /// implemented such that the complete context-sensitive follow set does not
605
- /// need to be explicitly constructed.
606
- ///
607
- /// <pre>
608
- /// return expectedTokens.contains(symbol);
609
- /// </pre>
610
- ///
611
- /// @param symbol the symbol type to check
612
- /// @return [true] if [symbol] can follow the current state in
613
- /// the ATN, otherwise [false].
614
- bool isExpectedToken(int symbol) {
615
- // return interpreter.atn.nextTokens(_ctx);
616
- final atn = interpreter.atn;
617
- var ctx = _ctx;
618
- final s = atn.states[state];
619
- var following = atn.nextTokens(s);
620
- if (following.contains(symbol)) {
621
- return true;
622
- }
623
- // log("following "+s+"="+following);
624
- if (!following.contains(Token.EPSILON)) return false;
625
-
626
- while (ctx != null &&
627
- ctx.invokingState >= 0 &&
628
- following.contains(Token.EPSILON)) {
629
- final invokingState = atn.states[ctx.invokingState];
630
- RuleTransition rt = invokingState.transition(0);
631
- following = atn.nextTokens(rt.followState);
632
- if (following.contains(symbol)) {
633
- return true;
634
- }
635
-
636
- ctx = ctx.parent;
637
- }
638
-
639
- if (following.contains(Token.EPSILON) && symbol == Token.EOF) {
640
- return true;
641
- }
642
-
643
- return false;
644
- }
645
-
646
- bool isMatchedEOF() {
647
- return matchedEOF;
648
- }
649
-
650
- /// Computes the set of input symbols which could follow the current parser
651
- /// state and context, as given by {@link #getState} and {@link #getContext},
652
- /// respectively.
653
- ///
654
- /// @see ATN#getExpectedTokens(int, RuleContext)
655
- IntervalSet get expectedTokens {
656
- return getATN().getExpectedTokens(state, context);
657
- }
658
-
659
- IntervalSet get expectedTokensWithinCurrentRule {
660
- final atn = interpreter.atn;
661
- final s = atn.states[state];
662
- return atn.nextTokens(s);
663
- }
664
-
665
- /// Get a rule's index (i.e., {@code RULE_ruleName} field) or -1 if not found. */
666
- int getRuleIndex(String ruleName) {
667
- final ruleIndex = ruleIndexMap[ruleName];
668
- if (ruleIndex != null) return ruleIndex;
669
- return -1;
670
- }
671
-
672
- ParserRuleContext get ruleContext {
673
- return _ctx;
674
- }
675
-
676
- List<String> get ruleInvocationStack => getRuleInvocationStack();
677
-
678
- /// Return List&lt;String&gt; of the rule names in your parser instance
679
- /// leading up to a call to the current rule. You could override if
680
- /// you want more details such as the file/line info of where
681
- /// in the ATN a rule is invoked.
682
- ///
683
- /// This is very useful for error messages.
684
- List<String> getRuleInvocationStack([RuleContext p]) {
685
- p = p ?? _ctx;
686
- final _ruleNames = ruleNames;
687
- final stack = <String>[];
688
- while (p != null) {
689
- // compute what follows who invoked us
690
- final ruleIndex = p.ruleIndex;
691
- if (ruleIndex < 0) {
692
- stack.add('n/a');
693
- } else {
694
- stack.add(_ruleNames[ruleIndex]);
695
- }
696
- p = p.parent;
697
- }
698
- return stack;
699
- }
700
-
701
- /// For debugging and other purposes. */
702
- List<String> get dfaStrings {
703
- final s = <String>[];
704
- for (var d = 0; d < interpreter.decisionToDFA.length; d++) {
705
- final dfa = interpreter.decisionToDFA[d];
706
- s.add(dfa.toString(vocabulary));
707
- }
708
- return s;
709
- }
710
-
711
- /// For debugging and other purposes. */
712
- void dumpDFA() {
713
- var seenOne = false;
714
- for (var d = 0; d < interpreter.decisionToDFA.length; d++) {
715
- final dfa = interpreter.decisionToDFA[d];
716
- if (dfa.states.isNotEmpty) {
717
- if (seenOne) print('');
718
- print('Decision ${dfa.decision}:');
719
- stdout.write(dfa.toString(vocabulary));
720
- seenOne = true;
721
- }
722
- }
723
- }
724
-
725
- String get sourceName {
726
- return _input.sourceName;
727
- }
728
-
729
- @override
730
- ParseInfo get parseInfo {
731
- final interp = interpreter;
732
- if (interp is ProfilingATNSimulator) {
733
- return ParseInfo(interp);
734
- }
735
- return null;
736
- }
737
-
738
- /// @since 4.3
739
- void setProfile(bool profile) {
740
- final interp = interpreter;
741
- final saveMode = interp.predictionMode;
742
- if (profile) {
743
- if (!(interp is ProfilingATNSimulator)) {
744
- interpreter = ProfilingATNSimulator(this);
745
- }
746
- } else if (interp is ProfilingATNSimulator) {
747
- final sim = ParserATNSimulator(
748
- this, getATN(), interp.decisionToDFA, interp.sharedContextCache);
749
- interpreter = sim;
750
- }
751
- interpreter.predictionMode = saveMode;
752
- }
753
-
754
- /// During a parse is sometimes useful to listen in on the rule entry and exit
755
- /// events as well as token matches. This is for quick and dirty debugging.
756
- void setTrace(bool trace) {
757
- if (!trace) {
758
- removeParseListener(_tracer);
759
- _tracer = null;
760
- } else {
761
- if (_tracer != null) {
762
- removeParseListener(_tracer);
763
- } else {
764
- _tracer = TraceListener(this);
765
- }
766
- addParseListener(_tracer);
767
- }
768
- }
769
-
770
- /// Gets whether a [TraceListener] is registered as a parse listener
771
- /// for the parser.
772
- ///
773
- /// @see #setTrace(bool)
774
- bool isTrace() {
775
- return _tracer != null;
776
- }
777
- }