OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library analyzer.src.dart.scanner.reader; | 5 library analyzer.src.dart.scanner.reader; |
6 | 6 |
| 7 import 'package:front_end/src/scanner/reader.dart'; |
| 8 |
| 9 export 'package:front_end/src/scanner/reader.dart' show CharacterReader; |
| 10 |
7 /** | 11 /** |
8 * A [CharacterReader] that reads a range of characters from another character | 12 * A [CharacterReader] that reads a range of characters from another character |
9 * reader. | 13 * reader. |
10 */ | 14 */ |
11 class CharacterRangeReader extends CharacterReader { | 15 class CharacterRangeReader extends CharacterReader { |
12 /** | 16 /** |
13 * The reader from which the characters are actually being read. | 17 * The reader from which the characters are actually being read. |
14 */ | 18 */ |
15 final CharacterReader baseReader; | 19 final CharacterReader baseReader; |
16 | 20 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 @override | 54 @override |
51 int peek() { | 55 int peek() { |
52 if (baseReader.offset + 1 >= endIndex) { | 56 if (baseReader.offset + 1 >= endIndex) { |
53 return -1; | 57 return -1; |
54 } | 58 } |
55 return baseReader.peek(); | 59 return baseReader.peek(); |
56 } | 60 } |
57 } | 61 } |
58 | 62 |
59 /** | 63 /** |
60 * An object used by the scanner to read the characters to be scanned. | |
61 */ | |
62 abstract class CharacterReader { | |
63 /** | |
64 * The current offset relative to the beginning of the source. Return the | |
65 * initial offset if the scanner has not yet scanned the source code, and one | |
66 * (1) past the end of the source code if the entire source code has been | |
67 * scanned. | |
68 */ | |
69 int get offset; | |
70 | |
71 /** | |
72 * Set the current offset relative to the beginning of the source to the given | |
73 * [offset]. The new offset must be between the initial offset and one (1) | |
74 * past the end of the source code. | |
75 */ | |
76 void set offset(int offset); | |
77 | |
78 /** | |
79 * Advance the current position and return the character at the new current | |
80 * position. | |
81 */ | |
82 int advance(); | |
83 | |
84 /** | |
85 * Return the substring of the source code between the [start] offset and the | |
86 * modified current position. The current position is modified by adding the | |
87 * [endDelta], which is the number of characters after the current location to | |
88 * be included in the string, or the number of characters before the current | |
89 * location to be excluded if the offset is negative. | |
90 */ | |
91 String getString(int start, int endDelta); | |
92 | |
93 /** | |
94 * Return the character at the current position without changing the current | |
95 * position. | |
96 */ | |
97 int peek(); | |
98 } | |
99 | |
100 /** | |
101 * A [CharacterReader] that reads characters from a character sequence. | 64 * A [CharacterReader] that reads characters from a character sequence. |
102 */ | 65 */ |
103 class CharSequenceReader implements CharacterReader { | 66 class CharSequenceReader implements CharacterReader { |
104 /** | 67 /** |
105 * The sequence from which characters will be read. | 68 * The sequence from which characters will be read. |
106 */ | 69 */ |
107 final String _sequence; | 70 final String _sequence; |
108 | 71 |
109 /** | 72 /** |
110 * The number of characters in the string. | 73 * The number of characters in the string. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 141 |
179 @override | 142 @override |
180 void set offset(int offset) { | 143 void set offset(int offset) { |
181 super.offset = offset - _offsetDelta; | 144 super.offset = offset - _offsetDelta; |
182 } | 145 } |
183 | 146 |
184 @override | 147 @override |
185 String getString(int start, int endDelta) => | 148 String getString(int start, int endDelta) => |
186 super.getString(start - _offsetDelta, endDelta); | 149 super.getString(start - _offsetDelta, endDelta); |
187 } | 150 } |
OLD | NEW |