@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,204 +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 '../../atn/atn.dart';
8
- import '../../input_stream.dart';
9
- import '../../interval_set.dart';
10
- import '../../lexer.dart';
11
- import '../../parser.dart';
12
- import '../../parser_rule_context.dart';
13
- import '../../recognizer.dart';
14
- import '../../rule_context.dart';
15
- import '../../token.dart';
16
- import '../../token_stream.dart';
17
- import '../../util/utils.dart';
18
-
19
- /// The root of the ANTLR exception hierarchy. In general, ANTLR tracks just
20
- /// 3 kinds of errors: prediction errors, failed predicate errors, and
21
- /// mismatched input errors. In each case, the parser knows where it is
22
- /// in the input, where it is in the ATN, the rule invocation stack,
23
- /// and what kind of problem occurred.
24
- class RecognitionException extends StateError {
25
- /// Gets the [Recognizer] where this exception occurred.
26
- ///
27
- /// <p>If the recognizer is not available, this method returns null.</p>
28
- ///
29
- /// @return The recognizer where this exception occurred, or null if
30
- /// the recognizer is not available.
31
- final Recognizer recognizer;
32
-
33
- /// Gets the [RuleContext] at the time this exception was thrown.
34
- ///
35
- /// <p>If the context is not available, this method returns null.</p>
36
- ///
37
- /// @return The [RuleContext] at the time this exception was thrown.
38
- /// If the context is not available, this method returns null.
39
- final RuleContext ctx;
40
-
41
- /// Gets the input stream which is the symbol source for the recognizer where
42
- /// this exception was thrown.
43
- ///
44
- /// <p>If the input stream is not available, this method returns null.</p>
45
- ///
46
- /// @return The input stream which is the symbol source for the recognizer
47
- /// where this exception was thrown, or null if the stream is not
48
- /// available.
49
- final IntStream inputStream;
50
-
51
- /// The current [Token] when an error occurred. Since not all streams
52
- /// support accessing symbols by index, we have to track the [Token]
53
- /// instance itself.
54
- Token offendingToken;
55
-
56
- /// Get the ATN state number the parser was in at the time the error
57
- /// occurred. For [NoViableAltException] and
58
- /// [LexerNoViableAltException] exceptions, this is the
59
- /// [DecisionState] number. For others, it is the state whose outgoing
60
- /// edge we couldn't match.
61
- ///
62
- /// <p>If the state number is not known, this method returns -1.</p>
63
- int offendingState = -1;
64
-
65
- RecognitionException(this.recognizer, this.inputStream, this.ctx,
66
- [String message = ''])
67
- : super(message) {
68
- if (recognizer != null) offendingState = recognizer.state;
69
- }
70
-
71
- /// Gets the set of input symbols which could potentially follow the
72
- /// previously matched symbol at the time this exception was thrown.
73
- ///
74
- /// <p>If the set of expected tokens is not known and could not be computed,
75
- /// this method returns null.</p>
76
- ///
77
- /// @return The set of token types that could potentially follow the current
78
- /// state in the ATN, or null if the information is not available.
79
- IntervalSet get expectedTokens {
80
- if (recognizer != null) {
81
- return recognizer.getATN().getExpectedTokens(offendingState, ctx);
82
- }
83
- return null;
84
- }
85
- }
86
-
87
- class LexerNoViableAltException extends RecognitionException {
88
- /// Matching attempted at what input index? */
89
- final int startIndex;
90
-
91
- /// Which configurations did we try at input.index() that couldn't match input.LA(1)? */
92
- final ATNConfigSet deadEndConfigs;
93
-
94
- LexerNoViableAltException(
95
- Lexer lexer, CharStream input, this.startIndex, this.deadEndConfigs)
96
- : super(lexer, input, null);
97
-
98
- @override
99
- CharStream get inputStream {
100
- return super.inputStream;
101
- }
102
-
103
- @override
104
- String toString() {
105
- var symbol = '';
106
- if (startIndex >= 0 && startIndex < inputStream.size) {
107
- symbol = inputStream.getText(Interval.of(startIndex, startIndex));
108
- symbol = escapeWhitespace(symbol);
109
- }
110
-
111
- return "${LexerNoViableAltException}('${symbol}')";
112
- }
113
- }
114
-
115
- /// Indicates that the parser could not decide which of two or more paths
116
- /// to take based upon the remaining input. It tracks the starting token
117
- /// of the offending input and also knows where the parser was
118
- /// in the various paths when the error. Reported by reportNoViableAlternative()
119
- class NoViableAltException extends RecognitionException {
120
- /// Which configurations did we try at input.index() that couldn't match input.LT(1)? */
121
-
122
- final ATNConfigSet deadEndConfigs;
123
-
124
- /// The token object at the start index; the input stream might
125
- /// not be buffering tokens so get a reference to it. (At the
126
- /// time the error occurred, of course the stream needs to keep a
127
- /// buffer all of the tokens but later we might not have access to those.)
128
-
129
- final Token startToken;
130
-
131
- // NoViableAltException(Parser recognizer) { // LL(1) error
132
- // this(recognizer,
133
- // recognizer.inputStream,
134
- // recognizer.getCurrentToken(),
135
- // recognizer.getCurrentToken(),
136
- // null,
137
- // recognizer._ctx);
138
- // }
139
-
140
- NoViableAltException._(Parser recognizer, TokenStream input, this.startToken,
141
- Token offendingToken, this.deadEndConfigs, ParserRuleContext ctx)
142
- : super(recognizer, input, ctx) {
143
- this.offendingToken = offendingToken;
144
- }
145
-
146
- NoViableAltException(Parser recognizer,
147
- [TokenStream input,
148
- Token startToken,
149
- Token offendingToken,
150
- ATNConfigSet deadEndConfigs,
151
- ParserRuleContext ctx])
152
- : this._(
153
- recognizer,
154
- input ?? recognizer.inputStream,
155
- startToken ?? recognizer.currentToken,
156
- offendingToken ?? recognizer.currentToken,
157
- deadEndConfigs,
158
- ctx ?? recognizer.context);
159
- }
160
-
161
- /// This signifies any kind of mismatched input exceptions such as
162
- /// when the current input does not match the expected token.
163
- class InputMismatchException extends RecognitionException {
164
- InputMismatchException(Parser recognizer,
165
- [int state = -1, ParserRuleContext ctx])
166
- : super(recognizer, recognizer.inputStream, ctx ?? recognizer.context) {
167
- if (state != -1 && ctx != null) {
168
- offendingState = state;
169
- }
170
- offendingToken = recognizer.currentToken;
171
- }
172
- }
173
-
174
- /// A semantic predicate failed during validation. Validation of predicates
175
- /// occurs when normally parsing the alternative just like matching a token.
176
- /// Disambiguating predicate evaluation occurs when we test a predicate during
177
- /// prediction.
178
- class FailedPredicateException extends RecognitionException {
179
- int ruleIndex;
180
- int predIndex;
181
- final String predicate;
182
-
183
- FailedPredicateException(Parser recognizer,
184
- [this.predicate, String message])
185
- : super(recognizer, recognizer.inputStream, recognizer.context,
186
- formatMessage(predicate, message)) {
187
- final s = recognizer.interpreter.atn.states[recognizer.state];
188
-
189
- AbstractPredicateTransition trans = s.transition(0);
190
- if (trans is PredicateTransition) {
191
- ruleIndex = trans.ruleIndex;
192
- predIndex = trans.predIndex;
193
- }
194
- offendingToken = recognizer.currentToken;
195
- }
196
-
197
- static String formatMessage(String predicate, String message) {
198
- if (message != null) {
199
- return message;
200
- }
201
-
202
- return 'failed predicate: {$predicate}?';
203
- }
204
- }
@@ -1,335 +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:async';
8
- import 'dart:convert';
9
- import 'dart:io';
10
- import 'dart:math';
11
-
12
- import 'interval_set.dart';
13
- import 'token.dart';
14
-
15
- /// A simple stream of symbols whose values are represented as integers. This
16
- /// interface provides <em>marked ranges</em> with support for a minimum level
17
- /// of buffering necessary to implement arbitrary lookahead during prediction.
18
- /// For more information on marked ranges, see {@link #mark}.
19
- ///
20
- /// <p><strong>Initializing Methods:</strong> Some methods in this interface have
21
- /// unspecified behavior if no call to an initializing method has occurred after
22
- /// the stream was constructed. The following is a list of initializing methods:</p>
23
- ///
24
- /// <ul>
25
- /// <li>{@link #LA}</li>
26
- /// <li>{@link #consume}</li>
27
- /// <li>{@link #size}</li>
28
- /// </ul>
29
- abstract class IntStream {
30
- /// The value returned by {@link #LA LA()} when the end of the stream is
31
- /// reached.
32
- static const int EOF = -1;
33
-
34
- /// The value returned by {@link #getSourceName} when the actual name of the
35
- /// underlying source is not known.
36
- static const UNKNOWN_SOURCE_NAME = '<unknown>';
37
-
38
- /// Consumes the current symbol in the stream. This method has the following
39
- /// effects:
40
- ///
41
- /// <ul>
42
- /// <li><strong>Forward movement:</strong> The value of {@link #index index()}
43
- /// before calling this method is less than the value of {@code index()}
44
- /// after calling this method.</li>
45
- /// <li><strong>Ordered lookahead:</strong> The value of {@code LA(1)} before
46
- /// calling this method becomes the value of {@code LA(-1)} after calling
47
- /// this method.</li>
48
- /// </ul>
49
- ///
50
- /// Note that calling this method does not guarantee that {@code index()} is
51
- /// incremented by exactly 1, as that would preclude the ability to implement
52
- /// filtering streams (e.g. [CommonTokenStream] which distinguishes
53
- /// between "on-channel" and "off-channel" tokens).
54
- ///
55
- /// @throws IllegalStateException if an attempt is made to consume the
56
- /// end of the stream (i.e. if {@code LA(1)==}{@link #EOF EOF} before calling
57
- /// [consume]).
58
- void consume();
59
-
60
- /// Gets the value of the symbol at offset [i] from the current
61
- /// position. When {@code i==1}, this method returns the value of the current
62
- /// symbol in the stream (which is the next symbol to be consumed). When
63
- /// {@code i==-1}, this method returns the value of the previously read
64
- /// symbol in the stream. It is not valid to call this method with
65
- /// {@code i==0}, but the specific behavior is unspecified because this
66
- /// method is frequently called from performance-critical code.
67
- ///
68
- /// <p>This method is guaranteed to succeed if any of the following are true:</p>
69
- ///
70
- /// <ul>
71
- /// <li>{@code i>0}</li>
72
- /// <li>{@code i==-1} and {@link #index index()} returns a value greater
73
- /// than the value of {@code index()} after the stream was constructed
74
- /// and {@code LA(1)} was called in that order. Specifying the current
75
- /// {@code index()} relative to the index after the stream was created
76
- /// allows for filtering implementations that do not return every symbol
77
- /// from the underlying source. Specifying the call to {@code LA(1)}
78
- /// allows for lazily initialized streams.</li>
79
- /// <li>{@code LA(i)} refers to a symbol consumed within a marked region
80
- /// that has not yet been released.</li>
81
- /// </ul>
82
- ///
83
- /// <p>If [i] represents a position at or beyond the end of the stream,
84
- /// this method returns {@link #EOF}.</p>
85
- ///
86
- /// <p>The return value is unspecified if {@code i<0} and fewer than {@code -i}
87
- /// calls to {@link #consume consume()} have occurred from the beginning of
88
- /// the stream before calling this method.</p>
89
- ///
90
- /// @throws UnsupportedOperationException if the stream does not support
91
- /// retrieving the value of the specified symbol
92
- int LA(int i);
93
-
94
- /// A mark provides a guarantee that {@link #seek seek()} operations will be
95
- /// valid over a "marked range" extending from the index where {@code mark()}
96
- /// was called to the current {@link #index index()}. This allows the use of
97
- /// streaming input sources by specifying the minimum buffering requirements
98
- /// to support arbitrary lookahead during prediction.
99
- ///
100
- /// <p>The returned mark is an opaque handle (type [int]) which is passed
101
- /// to {@link #release release()} when the guarantees provided by the marked
102
- /// range are no longer necessary. When calls to
103
- /// {@code mark()}/{@code release()} are nested, the marks must be released
104
- /// in reverse order of which they were obtained. Since marked regions are
105
- /// used during performance-critical sections of prediction, the specific
106
- /// behavior of invalid usage is unspecified (i.e. a mark is not released, or
107
- /// a mark is released twice, or marks are not released in reverse order from
108
- /// which they were created).</p>
109
- ///
110
- /// <p>The behavior of this method is unspecified if no call to an
111
- /// {@link IntStream initializing method} has occurred after this stream was
112
- /// constructed.</p>
113
- ///
114
- /// <p>This method does not change the current position in the input stream.</p>
115
- ///
116
- /// <p>The following example shows the use of {@link #mark mark()},
117
- /// {@link #release release(mark)}, {@link #index index()}, and
118
- /// {@link #seek seek(index)} as part of an operation to safely work within a
119
- /// marked region, then restore the stream position to its original value and
120
- /// release the mark.</p>
121
- /// <pre>
122
- /// IntStream stream = ...;
123
- /// int index = -1;
124
- /// int mark = stream.mark();
125
- /// try {
126
- /// index = stream.index();
127
- /// // perform work here...
128
- /// } finally {
129
- /// if (index != -1) {
130
- /// stream.seek(index);
131
- /// }
132
- /// stream.release(mark);
133
- /// }
134
- /// </pre>
135
- ///
136
- /// @return An opaque marker which should be passed to
137
- /// {@link #release release()} when the marked range is no longer required.
138
- int mark();
139
-
140
- /// This method releases a marked range created by a call to
141
- /// {@link #mark mark()}. Calls to {@code release()} must appear in the
142
- /// reverse order of the corresponding calls to {@code mark()}. If a mark is
143
- /// released twice, or if marks are not released in reverse order of the
144
- /// corresponding calls to {@code mark()}, the behavior is unspecified.
145
- ///
146
- /// <p>For more information and an example, see {@link #mark}.</p>
147
- ///
148
- /// @param marker A marker returned by a call to {@code mark()}.
149
- /// @see #mark
150
- void release(int marker);
151
-
152
- /// Return the index into the stream of the input symbol referred to by
153
- /// {@code LA(1)}.
154
- ///
155
- /// <p>The behavior of this method is unspecified if no call to an
156
- /// {@link IntStream initializing method} has occurred after this stream was
157
- /// constructed.</p>
158
- int get index;
159
-
160
- /// Set the input cursor to the position indicated by [index]. If the
161
- /// specified index lies past the end of the stream, the operation behaves as
162
- /// though [index] was the index of the EOF symbol. After this method
163
- /// returns without throwing an exception, then at least one of the following
164
- /// will be true.
165
- ///
166
- /// <ul>
167
- /// <li>{@link #index index()} will return the index of the first symbol
168
- /// appearing at or after the specified [index]. Specifically,
169
- /// implementations which filter their sources should automatically
170
- /// adjust [index] forward the minimum amount required for the
171
- /// operation to target a non-ignored symbol.</li>
172
- /// <li>{@code LA(1)} returns {@link #EOF}</li>
173
- /// </ul>
174
- ///
175
- /// This operation is guaranteed to not throw an exception if [index]
176
- /// lies within a marked region. For more information on marked regions, see
177
- /// {@link #mark}. The behavior of this method is unspecified if no call to
178
- /// an {@link IntStream initializing method} has occurred after this stream
179
- /// was constructed.
180
- ///
181
- /// @param index The absolute index to seek to.
182
- ///
183
- /// @throws IllegalArgumentException if [index] is less than 0
184
- /// @throws UnsupportedOperationException if the stream does not support
185
- /// seeking to the specified index
186
- void seek(int index);
187
-
188
- /// Returns the total number of symbols in the stream, including a single EOF
189
- /// symbol.
190
- ///
191
- /// @throws UnsupportedOperationException if the size of the stream is
192
- /// unknown.
193
- int get size;
194
-
195
- /// Gets the name of the underlying symbol source. This method returns a
196
- /// non-null, non-empty string. If such a name is not known, this method
197
- /// returns {@link #UNKNOWN_SOURCE_NAME}.
198
-
199
- String get sourceName;
200
- }
201
-
202
- /// A source of characters for an ANTLR lexer. */
203
- abstract class CharStream extends IntStream {
204
- /// This method returns the text for a range of characters within this input
205
- /// stream. This method is guaranteed to not throw an exception if the
206
- /// specified [interval] lies entirely within a marked range. For more
207
- /// information about marked ranges, see {@link IntStream#mark}.
208
- ///
209
- /// @param interval an interval within the stream
210
- /// @return the text of the specified interval
211
- ///
212
- /// @throws NullPointerException if [interval] is null
213
- /// @throws IllegalArgumentException if {@code interval.a < 0}, or if
214
- /// {@code interval.b < interval.a - 1}, or if {@code interval.b} lies at or
215
- /// past the end of the stream
216
- /// @throws UnsupportedOperationException if the stream does not support
217
- /// getting the text of the specified interval
218
- String getText(Interval interval);
219
- }
220
-
221
- // Vacuum all input from a string and then treat it like a buffer.
222
- class InputStream extends CharStream {
223
- final name = '<empty>';
224
- List<int> data;
225
- int _index = 0;
226
- bool decodeToUnicodeCodePoints = false;
227
-
228
- InputStream(List<int> data) {
229
- this.data = data;
230
- }
231
-
232
- InputStream.fromString(String data) {
233
- this.data = data.runes.toList(growable: false);
234
- }
235
-
236
- static Future<InputStream> fromStringStream(Stream<String> stream) async {
237
- final data = StringBuffer();
238
- await stream.listen((buf) {
239
- data.write(buf);
240
- }).asFuture();
241
- return InputStream.fromString(data.toString());
242
- }
243
-
244
- static Future<InputStream> fromStream(Stream<List<int>> stream,
245
- {Encoding encoding = utf8}) {
246
- final data = stream.transform(encoding.decoder);
247
- return fromStringStream(data);
248
- }
249
-
250
- static Future<InputStream> fromPath(String path, {Encoding encoding = utf8}) {
251
- return fromStream(File(path).openRead());
252
- }
253
-
254
- @override
255
- int get index {
256
- return _index;
257
- }
258
-
259
- @override
260
- int get size {
261
- return data.length;
262
- }
263
-
264
- /// Reset the stream so that it's in the same state it was
265
- /// when the object was created *except* the data array is not
266
- /// touched.
267
- void reset() {
268
- _index = 0;
269
- }
270
-
271
- @override
272
- void consume() {
273
- if (_index >= size) {
274
- // assert this.LA(1) == Token.EOF
275
- throw ('cannot consume EOF');
276
- }
277
- _index += 1;
278
- }
279
-
280
- @override
281
- int LA(int offset) {
282
- if (offset == 0) {
283
- return 0; // undefined
284
- }
285
- if (offset < 0) {
286
- offset += 1; // e.g., translate LA(-1) to use offset=0
287
- }
288
- final pos = _index + offset - 1;
289
- if (pos < 0 || pos >= size) {
290
- // invalid
291
- return Token.EOF;
292
- }
293
- return data[pos];
294
- }
295
-
296
- /// mark/release do nothing; we have entire buffer
297
- @override
298
- int mark() {
299
- return -1;
300
- }
301
-
302
- @override
303
- void release(int marker) {}
304
-
305
- /// consume() ahead until p==_index; can't just set p=_index as we must
306
- /// update line and column. If we seek backwards, just set p
307
- @override
308
- void seek(int _index) {
309
- if (_index <= this._index) {
310
- this._index = _index; // just jump; don't update stream state (line,
311
- // ...)
312
- return;
313
- }
314
- // seek forward
315
- this._index = min(_index, size);
316
- }
317
-
318
- @override
319
- String getText(Interval interval) {
320
- final startIdx = min(interval.a, size);
321
- final len = min(interval.b - interval.a + 1, size - startIdx);
322
- return String.fromCharCodes(data, startIdx, startIdx + len);
323
- }
324
-
325
- @override
326
- String toString() {
327
- return String.fromCharCodes(data);
328
- }
329
-
330
- @override
331
- String get sourceName {
332
- // TODO: implement getSourceName
333
- return IntStream.UNKNOWN_SOURCE_NAME;
334
- }
335
- }