@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,809 +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 '../../interval_set.dart';
8
- import '../../misc/pair.dart';
9
- import '../../token.dart';
10
- import 'atn.dart';
11
- import 'atn_state.dart';
12
- import 'atn_type.dart';
13
- import 'lexer_action.dart';
14
- import 'transition.dart';
15
-
16
- class ATNDeserializationOptions {
17
- static final ATNDeserializationOptions defaultOptions =
18
- ATNDeserializationOptions()..makeReadOnly();
19
-
20
- bool readOnly;
21
- bool verifyATN;
22
- bool generateRuleBypassTransitions;
23
-
24
- ATNDeserializationOptions([ATNDeserializationOptions options]) {
25
- if (options == null) {
26
- verifyATN = true;
27
- generateRuleBypassTransitions = false;
28
- } else {
29
- verifyATN = options.verifyATN;
30
- generateRuleBypassTransitions =
31
- options.generateRuleBypassTransitions;
32
- }
33
- }
34
-
35
- bool isReadOnly() {
36
- return readOnly;
37
- }
38
-
39
- void makeReadOnly() {
40
- readOnly = true;
41
- }
42
-
43
- bool isVerifyATN() {
44
- return verifyATN;
45
- }
46
-
47
- void setVerifyATN(bool verifyATN) {
48
- throwIfReadOnly();
49
- this.verifyATN = verifyATN;
50
- }
51
-
52
- bool isGenerateRuleBypassTransitions() {
53
- return generateRuleBypassTransitions;
54
- }
55
-
56
- void setGenerateRuleBypassTransitions(bool generateRuleBypassTransitions) {
57
- throwIfReadOnly();
58
- this.generateRuleBypassTransitions = generateRuleBypassTransitions;
59
- }
60
-
61
- void throwIfReadOnly() {
62
- if (isReadOnly()) {
63
- throw StateError('The object is read only.');
64
- }
65
- }
66
- }
67
-
68
- class ATNDeserializer {
69
- /// This value should never change. Updates following this version are
70
- /// reflected as change in the unique ID SERIALIZED_UUID.
71
- static final SERIALIZED_VERSION = 3;
72
-
73
- /** WARNING: DO NOT MERGE THESE LINES. If UUIDs differ during a merge,
74
- * resolve the conflict by generating a new ID!
75
- */
76
- /// This is the earliest supported serialized UUID.
77
- static final BASE_SERIALIZED_UUID = '33761B2D-78BB-4A43-8B0B-4F5BEE8AACF3';
78
-
79
- /// This UUID indicates an extension of {@link BASE_SERIALIZED_UUID} for the
80
- /// addition of precedence predicates.
81
- static final ADDED_PRECEDENCE_TRANSITIONS =
82
- '1DA0C57D-6C06-438A-9B27-10BCB3CE0F61';
83
-
84
- /// This UUID indicates an extension of {@link #ADDED_PRECEDENCE_TRANSITIONS}
85
- /// for the addition of lexer actions encoded as a sequence of
86
- /// [LexerAction] instances.
87
- static final ADDED_LEXER_ACTIONS = 'AADB8D7E-AEEF-4415-AD2B-8204D6CF042E';
88
-
89
- /// This UUID indicates the serialized ATN contains two sets of
90
- /// IntervalSets, where the second set's values are encoded as
91
- /// 32-bit integers to support the full Unicode SMP range up to U+10FFFF.
92
- static final ADDED_UNICODE_SMP = '59627784-3BE5-417A-B9EB-8131A7286089';
93
-
94
- /// This list contains all of the currently supported UUIDs, ordered by when
95
- /// the feature first appeared in this branch.
96
- static final SUPPORTED_UUIDS = [
97
- BASE_SERIALIZED_UUID,
98
- ADDED_PRECEDENCE_TRANSITIONS,
99
- ADDED_LEXER_ACTIONS,
100
- ADDED_UNICODE_SMP
101
- ];
102
-
103
- /// This is the current serialized UUID.
104
- static final SERIALIZED_UUID = ADDED_UNICODE_SMP;
105
-
106
- ATNDeserializationOptions deserializationOptions;
107
- List<int> data;
108
- var pos;
109
- String uuid;
110
-
111
- ATNDeserializer([options]) {
112
- deserializationOptions =
113
- options ?? ATNDeserializationOptions.defaultOptions;
114
- }
115
-
116
- /// Determines if a particular serialized representation of an ATN supports
117
- /// a particular feature, identified by the [UUID] used for serializing
118
- /// the ATN at the time the feature was first introduced.
119
- ///
120
- /// @param feature The [UUID] marking the first time the feature was
121
- /// supported in the serialized ATN.
122
- /// @param actualUuid The [UUID] of the actual serialized ATN which is
123
- /// currently being deserialized.
124
- /// @return [true] if the [actualUuid] value represents a
125
- /// serialized ATN at or after the feature identified by [feature] was
126
- /// introduced; otherwise, [false].
127
- bool isFeatureSupported(feature, actualUuid) {
128
- final idx1 = SUPPORTED_UUIDS.indexOf(feature);
129
- if (idx1 < 0) {
130
- return false;
131
- }
132
- final idx2 = SUPPORTED_UUIDS.indexOf(actualUuid);
133
- return idx2 >= idx1;
134
- }
135
-
136
- ATN deserialize(List<int> data) {
137
- reset(data);
138
- checkVersion();
139
- checkUUID();
140
- final atn = readATN();
141
- readStates(atn);
142
- readRules(atn);
143
- readModes(atn);
144
- final sets = <IntervalSet>[];
145
- // First, deserialize sets with 16-bit arguments <= U+FFFF.
146
- readSets(atn, sets, () => readInt());
147
- // Next, if the ATN was serialized with the Unicode SMP feature,
148
- // deserialize sets with 32-bit arguments <= U+10FFFF.
149
- if (isFeatureSupported(ADDED_UNICODE_SMP, uuid)) {
150
- readSets(atn, sets, () => readInt32());
151
- }
152
- readEdges(atn, sets);
153
- readDecisions(atn);
154
- readLexerActions(atn);
155
- markPrecedenceDecisions(atn);
156
- verifyATN(atn);
157
- if (deserializationOptions.generateRuleBypassTransitions &&
158
- atn.grammarType == ATNType.PARSER) {
159
- generateRuleBypassTransitions(atn);
160
- // re-verify after modification
161
- verifyATN(atn);
162
- }
163
- return atn;
164
- }
165
-
166
- /// Each char value in data is shifted by +2 at the entry to this method.
167
- /// This is an encoding optimization targeting the serialized values 0
168
- /// and -1 (serialized to 0xFFFF), each of which are very common in the
169
- /// serialized form of the ATN. In the modified UTF-8 that Java uses for
170
- /// compiled string literals, these two character values have multi-byte
171
- /// forms. By shifting each value by +2, they become characters 2 and 1
172
- /// prior to writing the string, each of which have single-byte
173
- /// representations. Since the shift occurs in the tool during ATN
174
- /// serialization, each target is responsible for adjusting the values
175
- /// during deserialization.
176
- ///
177
- /// As a special case, note that the first element of data is not
178
- /// adjusted because it contains the major version number of the
179
- /// serialized ATN, which was fixed at 3 at the time the value shifting
180
- /// was implemented.
181
- void reset(List<int> data) {
182
- final adjust = (int c) {
183
- final v = c;
184
- return v > 1 ? v - 2 : v + 65534;
185
- };
186
- final temp = data.map(adjust).toList();
187
- // don't adjust the first value since that's the version number
188
- temp[0] = data[0];
189
- this.data = temp;
190
- pos = 0;
191
- }
192
-
193
- void checkVersion() {
194
- final version = readInt();
195
- if (version != SERIALIZED_VERSION) {
196
- throw ('Could not deserialize ATN with version $version (expected $SERIALIZED_VERSION).');
197
- }
198
- }
199
-
200
- void checkUUID() {
201
- final uuid = readUUID();
202
- if (!SUPPORTED_UUIDS.contains(uuid)) {
203
- throw ('Could not deserialize ATN with UUID: $uuid (expected $SERIALIZED_UUID or a legacy UUID).');
204
- }
205
- this.uuid = uuid;
206
- }
207
-
208
- ATN readATN() {
209
- final grammarType = readInt();
210
- final maxTokenType = readInt();
211
- return ATN(ATNType.values[grammarType], maxTokenType);
212
- }
213
-
214
- void readStates(ATN atn) {
215
- final loopBackStateNumbers = <Pair<LoopEndState, int>>[];
216
- final endStateNumbers = <Pair<BlockStartState, int>>[];
217
- final nstates = readInt();
218
- for (var i = 0; i < nstates; i++) {
219
- final stype = StateType.values[readInt()];
220
- // ignore bad type of states
221
- if (stype == StateType.INVALID_TYPE) {
222
- atn.addState(null);
223
- continue;
224
- }
225
-
226
- var ruleIndex = readInt();
227
- if (ruleIndex == 0xFFFF) {
228
- ruleIndex = -1;
229
- }
230
-
231
- final s = stateFactory(stype, ruleIndex);
232
- if (s is LoopEndState) {
233
- // special case
234
- final loopBackStateNumber = readInt();
235
- loopBackStateNumbers.add(Pair(s, loopBackStateNumber));
236
- } else if (s is BlockStartState) {
237
- final endStateNumber = readInt();
238
- endStateNumbers.add(Pair(s, endStateNumber));
239
- }
240
- atn.addState(s);
241
- }
242
-
243
- // delay the assignment of loop back and end states until we know all the state instances have been initialized
244
- for (final pair in loopBackStateNumbers) {
245
- pair.a.loopBackState = atn.states[pair.b];
246
- }
247
-
248
- for (final pair in endStateNumbers) {
249
- pair.a.endState = atn.states[pair.b] as BlockEndState;
250
- }
251
-
252
- final numNonGreedyStates = readInt();
253
- for (var i = 0; i < numNonGreedyStates; i++) {
254
- final stateNumber = readInt();
255
- (atn.states[stateNumber] as DecisionState).nonGreedy = true;
256
- }
257
- if (isFeatureSupported(ADDED_PRECEDENCE_TRANSITIONS, uuid)) {
258
- final numPrecedenceStates = readInt();
259
- for (var i = 0; i < numPrecedenceStates; i++) {
260
- final stateNumber = readInt();
261
- (atn.states[stateNumber] as RuleStartState).isLeftRecursiveRule = true;
262
- }
263
- }
264
- }
265
-
266
- void readRules(ATN atn) {
267
- final nrules = readInt();
268
- if (atn.grammarType == ATNType.LEXER) {
269
- atn.ruleToTokenType = List<int>(nrules);
270
- }
271
-
272
- atn.ruleToStartState = List<RuleStartState>(nrules);
273
- for (var i = 0; i < nrules; i++) {
274
- final s = readInt();
275
- RuleStartState startState = atn.states[s];
276
- atn.ruleToStartState[i] = startState;
277
- if (atn.grammarType == ATNType.LEXER) {
278
- var tokenType = readInt();
279
- if (tokenType == 0xFFFF) {
280
- tokenType = Token.EOF;
281
- }
282
-
283
- atn.ruleToTokenType[i] = tokenType;
284
-
285
- if (!isFeatureSupported(ADDED_LEXER_ACTIONS, uuid)) {
286
- // this piece of unused metadata was serialized prior to the
287
- // addition of LexerAction
288
- final actionIndexIgnored = readInt();
289
- }
290
- }
291
- }
292
-
293
- atn.ruleToStopState = List<RuleStopState>(nrules);
294
- for (var state in atn.states) {
295
- if (!(state is RuleStopState)) {
296
- continue;
297
- }
298
-
299
- RuleStopState stopState = state;
300
- atn.ruleToStopState[state.ruleIndex] = stopState;
301
- atn.ruleToStartState[state.ruleIndex].stopState = stopState;
302
- }
303
- }
304
-
305
- void readModes(ATN atn) {
306
- final nmodes = readInt();
307
- for (var i = 0; i < nmodes; i++) {
308
- final s = readInt();
309
- atn.modeToStartState.add(atn.states[s] as TokensStartState);
310
- }
311
- }
312
-
313
- void readSets(ATN atn, List<IntervalSet> sets, readUnicode) {
314
- final nsets = readInt();
315
- for (var i = 0; i < nsets; i++) {
316
- final nintervals = readInt();
317
- final set = IntervalSet();
318
- sets.add(set);
319
-
320
- final containsEof = readInt() != 0;
321
- if (containsEof) {
322
- set.addOne(-1);
323
- }
324
-
325
- for (var j = 0; j < nintervals; j++) {
326
- int a = readUnicode();
327
- int b = readUnicode();
328
- set.addRange(a, b);
329
- }
330
- }
331
- }
332
-
333
- void readEdges(ATN atn, sets) {
334
- final nedges = readInt();
335
- for (var i = 0; i < nedges; i++) {
336
- final src = readInt();
337
- final trg = readInt();
338
- final ttype = TransitionType.values[readInt()];
339
- final arg1 = readInt();
340
- final arg2 = readInt();
341
- final arg3 = readInt();
342
- final trans =
343
- edgeFactory(atn, ttype, src, trg, arg1, arg2, arg3, sets);
344
- // System.out.println("EDGE "+trans.getClass().getSimpleName()+" "+
345
- // src+"->"+trg+
346
- // " "+Transition.serializationNames[ttype]+
347
- // " "+arg1+","+arg2+","+arg3);
348
- final srcState = atn.states[src];
349
- srcState.addTransition(trans);
350
- }
351
-
352
- // edges for rule stop states can be derived, so they aren't serialized
353
- for (var state in atn.states) {
354
- for (var i = 0; i < state.numberOfTransitions; i++) {
355
- final t = state.transition(i);
356
- if (t is RuleTransition) {
357
- final ruleTransition = t;
358
- var outermostPrecedenceReturn = -1;
359
- if (atn.ruleToStartState[ruleTransition.target.ruleIndex]
360
- .isLeftRecursiveRule) {
361
- if (ruleTransition.precedence == 0) {
362
- outermostPrecedenceReturn = ruleTransition.target.ruleIndex;
363
- }
364
- }
365
-
366
- final returnTransition = EpsilonTransition(
367
- ruleTransition.followState, outermostPrecedenceReturn);
368
- atn.ruleToStopState[ruleTransition.target.ruleIndex]
369
- .addTransition(returnTransition);
370
- }
371
- }
372
- }
373
-
374
- for (var state in atn.states) {
375
- if (state is BlockStartState) {
376
- // we need to know the end state to set its start state
377
- if (state.endState == null) {
378
- throw StateError('');
379
- }
380
-
381
- // block end states can only be associated to a single block start state
382
- if (state.endState.startState != null) {
383
- throw StateError('');
384
- }
385
-
386
- state.endState.startState = state;
387
- }
388
-
389
- if (state is PlusLoopbackState) {
390
- final loopbackState = state;
391
- for (var i = 0; i < loopbackState.numberOfTransitions; i++) {
392
- final target = loopbackState.transition(i).target;
393
- if (target is PlusBlockStartState) {
394
- target.loopBackState = loopbackState;
395
- }
396
- }
397
- } else if (state is StarLoopbackState) {
398
- final loopbackState = state;
399
- for (var i = 0; i < loopbackState.numberOfTransitions; i++) {
400
- final target = loopbackState.transition(i).target;
401
- if (target is StarLoopEntryState) {
402
- target.loopBackState = loopbackState;
403
- }
404
- }
405
- }
406
- }
407
- }
408
-
409
- void readDecisions(ATN atn) {
410
- final ndecisions = readInt();
411
- for (var i = 1; i <= ndecisions; i++) {
412
- final s = readInt();
413
- DecisionState decState = atn.states[s];
414
- atn.decisionToState.add(decState);
415
- decState.decision = i - 1;
416
- }
417
- }
418
-
419
- void readLexerActions(ATN atn) {
420
- if (atn.grammarType == ATNType.LEXER) {
421
- if (isFeatureSupported(ADDED_LEXER_ACTIONS, uuid)) {
422
- atn.lexerActions = List<LexerAction>(readInt());
423
- for (var i = 0; i < atn.lexerActions.length; i++) {
424
- final actionType = LexerActionType.values[readInt()];
425
- var data1 = readInt();
426
- if (data1 == 0xFFFF) {
427
- data1 = -1;
428
- }
429
-
430
- var data2 = readInt();
431
- if (data2 == 0xFFFF) {
432
- data2 = -1;
433
- }
434
- final lexerAction =
435
- lexerActionFactory(actionType, data1, data2);
436
-
437
- atn.lexerActions[i] = lexerAction;
438
- }
439
- } else {
440
- // for compatibility with older serialized ATNs, convert the old
441
- // serialized action index for action transitions to the new
442
- // form, which is the index of a LexerCustomAction
443
- final legacyLexerActions = <LexerAction>[];
444
- for (var state in atn.states) {
445
- for (var i = 0; i < state.numberOfTransitions; i++) {
446
- final transition = state.transition(i);
447
- if (transition is ActionTransition) {
448
- final ruleIndex = transition.ruleIndex;
449
- final actionIndex = transition.actionIndex;
450
- final lexerAction =
451
- LexerCustomAction(ruleIndex, actionIndex);
452
- state.setTransition(
453
- i,
454
- ActionTransition(transition.target, ruleIndex,
455
- legacyLexerActions.length, false));
456
- legacyLexerActions.add(lexerAction);
457
- }
458
- }
459
- }
460
-
461
- atn.lexerActions = legacyLexerActions;
462
- }
463
- }
464
- }
465
-
466
- void generateRuleBypassTransitions(ATN atn) {
467
- for (var i = 0; i < atn.ruleToStartState.length; i++) {
468
- atn.ruleToTokenType[i] = atn.maxTokenType + i + 1;
469
- }
470
- for (var i = 0; i < atn.ruleToStartState.length; i++) {
471
- generateRuleBypassTransition(atn, i);
472
- }
473
- }
474
-
475
- void generateRuleBypassTransition(ATN atn, int idx) {
476
- final bypassStart = BasicBlockStartState();
477
- bypassStart.ruleIndex = idx;
478
- atn.addState(bypassStart);
479
-
480
- final bypassStop = BlockEndState();
481
- bypassStop.ruleIndex = idx;
482
- atn.addState(bypassStop);
483
-
484
- bypassStart.endState = bypassStop;
485
- atn.defineDecisionState(bypassStart);
486
-
487
- bypassStop.startState = bypassStart;
488
-
489
- ATNState endState;
490
- Transition excludeTransition;
491
- if (atn.ruleToStartState[idx].isLeftRecursiveRule) {
492
- // wrap from the beginning of the rule to the StarLoopEntryState
493
- endState = null;
494
- for (var state in atn.states) {
495
- if (state.ruleIndex != idx) {
496
- continue;
497
- }
498
-
499
- if (!(state is StarLoopEntryState)) {
500
- continue;
501
- }
502
-
503
- final maybeLoopEndState =
504
- state.transition(state.numberOfTransitions - 1).target;
505
- if (!(maybeLoopEndState is LoopEndState)) {
506
- continue;
507
- }
508
-
509
- if (maybeLoopEndState.epsilonOnlyTransitions &&
510
- maybeLoopEndState.transition(0).target is RuleStopState) {
511
- endState = state;
512
- break;
513
- }
514
- }
515
-
516
- if (endState == null) {
517
- throw UnsupportedError(
518
- "Couldn't identify final state of the precedence rule prefix section.");
519
- }
520
-
521
- excludeTransition =
522
- (endState as StarLoopEntryState).loopBackState.transition(0);
523
- } else {
524
- endState = atn.ruleToStopState[idx];
525
- }
526
-
527
- // all non-excluded transitions that currently target end state need to target blockEnd instead
528
- for (var state in atn.states) {
529
- for (var transition in state.transitions) {
530
- if (transition == excludeTransition) {
531
- continue;
532
- }
533
-
534
- if (transition.target == endState) {
535
- transition.target = bypassStop;
536
- }
537
- }
538
- }
539
-
540
- // all transitions leaving the rule start state need to leave blockStart instead
541
- while (atn.ruleToStartState[idx].numberOfTransitions > 0) {
542
- final transition = atn.ruleToStartState[idx].removeTransition(
543
- atn.ruleToStartState[idx].numberOfTransitions - 1);
544
- bypassStart.addTransition(transition);
545
- }
546
-
547
- // link the new states
548
- atn.ruleToStartState[idx].addTransition(EpsilonTransition(bypassStart));
549
- bypassStop.addTransition(EpsilonTransition(endState));
550
-
551
- ATNState matchState = BasicState();
552
- atn.addState(matchState);
553
- matchState.addTransition(
554
- AtomTransition(bypassStop, atn.ruleToTokenType[idx]));
555
- bypassStart.addTransition(EpsilonTransition(matchState));
556
- }
557
-
558
- /// Analyze the [StarLoopEntryState] states in the specified ATN to set
559
- /// the {@link StarLoopEntryState#isPrecedenceDecision} field to the
560
- /// correct value.
561
- ///
562
- /// @param atn The ATN.
563
- void markPrecedenceDecisions(ATN atn) {
564
- for (var state in atn.states) {
565
- if (state is StarLoopEntryState) {
566
- /* We analyze the ATN to determine if this ATN decision state is the
567
- * decision for the closure block that determines whether a
568
- * precedence rule should continue or complete.
569
- */
570
- if (atn.ruleToStartState[state.ruleIndex].isLeftRecursiveRule) {
571
- final maybeLoopEndState =
572
- state.transition(state.numberOfTransitions - 1).target;
573
- if (maybeLoopEndState is LoopEndState) {
574
- if (maybeLoopEndState.epsilonOnlyTransitions &&
575
- maybeLoopEndState.transition(0).target is RuleStopState) {
576
- state.isPrecedenceDecision = true;
577
- }
578
- }
579
- }
580
- }
581
- }
582
- }
583
-
584
- void verifyATN(ATN atn) {
585
- // verify assumptions
586
- for (var state in atn.states) {
587
- if (state == null) {
588
- continue;
589
- }
590
-
591
- checkCondition(state.onlyHasEpsilonTransitions() ||
592
- state.numberOfTransitions <= 1);
593
-
594
- if (state is PlusBlockStartState) {
595
- checkCondition(state.loopBackState != null);
596
- }
597
-
598
- if (state is StarLoopEntryState) {
599
- final starLoopEntryState = state;
600
- checkCondition(starLoopEntryState.loopBackState != null);
601
- checkCondition(starLoopEntryState.numberOfTransitions == 2);
602
-
603
- if (starLoopEntryState.transition(0).target is StarBlockStartState) {
604
- checkCondition(
605
- starLoopEntryState.transition(1).target is LoopEndState);
606
- checkCondition(!starLoopEntryState.nonGreedy);
607
- } else if (starLoopEntryState.transition(0).target is LoopEndState) {
608
- checkCondition(
609
- starLoopEntryState.transition(1).target is StarBlockStartState);
610
- checkCondition(starLoopEntryState.nonGreedy);
611
- } else {
612
- throw StateError('');
613
- }
614
- }
615
-
616
- if (state is StarLoopbackState) {
617
- checkCondition(state.numberOfTransitions == 1);
618
- checkCondition(state.transition(0).target is StarLoopEntryState);
619
- }
620
-
621
- if (state is LoopEndState) {
622
- checkCondition(state.loopBackState != null);
623
- }
624
-
625
- if (state is RuleStartState) {
626
- checkCondition(state.stopState != null);
627
- }
628
-
629
- if (state is BlockStartState) {
630
- checkCondition(state.endState != null);
631
- }
632
-
633
- if (state is BlockEndState) {
634
- checkCondition(state.startState != null);
635
- }
636
-
637
- if (state is DecisionState) {
638
- final decisionState = state;
639
- checkCondition(decisionState.numberOfTransitions <= 1 ||
640
- decisionState.decision >= 0);
641
- } else {
642
- checkCondition(
643
- state.numberOfTransitions <= 1 || state is RuleStopState);
644
- }
645
- }
646
- }
647
-
648
- void checkCondition(bool condition, [String message = '']) {
649
- if (!condition) {
650
- throw StateError(message);
651
- }
652
- }
653
-
654
- int readInt() {
655
- return data[pos++];
656
- }
657
-
658
- int readInt32() {
659
- final low = readInt();
660
- final high = readInt();
661
- return low | (high << 16);
662
- }
663
-
664
- int readLong() {
665
- final low = readInt32();
666
- final high = readInt32();
667
- return (low & 0x00000000FFFFFFFF) | (high << 32);
668
- }
669
-
670
- static final byteToHex = List.generate(256, (i) => i.toRadixString(16).padLeft(2, '0').toUpperCase());
671
-
672
- String readUUID() {
673
- final bb = List<int>(16);
674
- for (var i = 7; i >= 0; i--) {
675
- final int = readInt();
676
- /* jshint bitwise: false */
677
- bb[(2 * i) + 1] = int & 0xFF;
678
- bb[2 * i] = (int >> 8) & 0xFF;
679
- }
680
- return byteToHex[bb[0]] + byteToHex[bb[1]] +
681
- byteToHex[bb[2]] + byteToHex[bb[3]] + '-' +
682
- byteToHex[bb[4]] + byteToHex[bb[5]] + '-' +
683
- byteToHex[bb[6]] + byteToHex[bb[7]] + '-' +
684
- byteToHex[bb[8]] + byteToHex[bb[9]] + '-' +
685
- byteToHex[bb[10]] + byteToHex[bb[11]] +
686
- byteToHex[bb[12]] + byteToHex[bb[13]] +
687
- byteToHex[bb[14]] + byteToHex[bb[15]];
688
- }
689
-
690
- Transition edgeFactory(ATN atn, TransitionType type, int src, int trg,
691
- int arg1, int arg2, int arg3, List<IntervalSet> sets) {
692
- final target = atn.states[trg];
693
- switch (type) {
694
- case TransitionType.EPSILON:
695
- return EpsilonTransition(target);
696
- case TransitionType.RANGE:
697
- return arg3 != 0
698
- ? RangeTransition(target, Token.EOF, arg2)
699
- : RangeTransition(target, arg1, arg2);
700
- case TransitionType.RULE:
701
- final rt =
702
- RuleTransition(atn.states[arg1], arg2, arg3, target);
703
- return rt;
704
- case TransitionType.PREDICATE:
705
- final pt =
706
- PredicateTransition(target, arg1, arg2, arg3 != 0);
707
- return pt;
708
- case TransitionType.PRECEDENCE:
709
- return PrecedencePredicateTransition(target, arg1);
710
- case TransitionType.ATOM:
711
- return arg3 != 0
712
- ? AtomTransition(target, Token.EOF)
713
- : AtomTransition(target, arg1);
714
- case TransitionType.ACTION:
715
- final a =
716
- ActionTransition(target, arg1, arg2, arg3 != 0);
717
- return a;
718
- case TransitionType.SET:
719
- return SetTransition(target, sets[arg1]);
720
- case TransitionType.NOT_SET:
721
- return NotSetTransition(target, sets[arg1]);
722
- case TransitionType.WILDCARD:
723
- return WildcardTransition(target);
724
- case TransitionType.INVALID:
725
- throw ArgumentError.value(type, 'transition type', 'not valid.');
726
- default:
727
- throw ArgumentError.value(type, 'transition type', 'not valid.');
728
- }
729
- }
730
-
731
- ATNState stateFactory(StateType type, int ruleIndex) {
732
- ATNState s;
733
- switch (type) {
734
- case StateType.INVALID_TYPE:
735
- return null;
736
- case StateType.BASIC:
737
- s = BasicState();
738
- break;
739
- case StateType.RULE_START:
740
- s = RuleStartState();
741
- break;
742
- case StateType.BLOCK_START:
743
- s = BasicBlockStartState();
744
- break;
745
- case StateType.PLUS_BLOCK_START:
746
- s = PlusBlockStartState();
747
- break;
748
- case StateType.STAR_BLOCK_START:
749
- s = StarBlockStartState();
750
- break;
751
- case StateType.TOKEN_START:
752
- s = TokensStartState();
753
- break;
754
- case StateType.RULE_STOP:
755
- s = RuleStopState();
756
- break;
757
- case StateType.BLOCK_END:
758
- s = BlockEndState();
759
- break;
760
- case StateType.STAR_LOOP_BACK:
761
- s = StarLoopbackState();
762
- break;
763
- case StateType.STAR_LOOP_ENTRY:
764
- s = StarLoopEntryState();
765
- break;
766
- case StateType.PLUS_LOOP_BACK:
767
- s = PlusLoopbackState();
768
- break;
769
- case StateType.LOOP_END:
770
- s = LoopEndState();
771
- break;
772
- default:
773
- throw ArgumentError.value(type, 'state type', 'not valid.');
774
- }
775
-
776
- s.ruleIndex = ruleIndex;
777
- return s;
778
- }
779
-
780
- LexerAction lexerActionFactory(LexerActionType type, int data1, int data2) {
781
- switch (type) {
782
- case LexerActionType.CHANNEL:
783
- return LexerChannelAction(data1);
784
-
785
- case LexerActionType.CUSTOM:
786
- return LexerCustomAction(data1, data2);
787
-
788
- case LexerActionType.MODE:
789
- return LexerModeAction(data1);
790
-
791
- case LexerActionType.MORE:
792
- return LexerMoreAction.INSTANCE;
793
-
794
- case LexerActionType.POP_MODE:
795
- return LexerPopModeAction.INSTANCE;
796
-
797
- case LexerActionType.PUSH_MODE:
798
- return LexerPushModeAction(data1);
799
-
800
- case LexerActionType.SKIP:
801
- return LexerSkipAction.INSTANCE;
802
-
803
- case LexerActionType.TYPE:
804
- return LexerTypeAction(data1);
805
- default:
806
- throw ArgumentError.value(type, 'lexer action type', 'not valid.');
807
- }
808
- }
809
- }