OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 part of scanner; | 5 part of scanner; |
6 | 6 |
7 /** | 7 /** |
8 * Scanner that reads from a String and creates tokens that points to | 8 * Scanner that reads from a String and creates tokens that points to |
9 * substrings. | 9 * substrings. |
10 */ | 10 */ |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 // over correct code. By inserting an additional error token in | 46 // over correct code. By inserting an additional error token in |
47 // the stream, we can keep ignoring endGroup tokens. | 47 // the stream, we can keep ignoring endGroup tokens. |
48 Token next = | 48 Token next = |
49 new StringToken.fromSource(BAD_INPUT_INFO, error, begin.charOffset); | 49 new StringToken.fromSource(BAD_INPUT_INFO, error, begin.charOffset); |
50 begin.endGroup = close; | 50 begin.endGroup = close; |
51 close.next = next; | 51 close.next = next; |
52 next.next = begin.next; | 52 next.next = begin.next; |
53 } | 53 } |
54 } | 54 } |
55 | 55 |
56 class SubstringWrapper implements SourceString { | 56 class SubstringWrapper extends Iterable<int> implements SourceString { |
57 final String internalString; | 57 final String internalString; |
58 final int begin; | 58 final int begin; |
59 final int end; | 59 final int end; |
60 int cashedHash = 0; | 60 int cashedHash = 0; |
61 String cachedSubString; | 61 String cachedSubString; |
62 | 62 |
63 SubstringWrapper(String this.internalString, | 63 SubstringWrapper(String this.internalString, |
64 int this.begin, int this.end); | 64 int this.begin, int this.end); |
65 | 65 |
66 int get hashCode { | 66 int get hashCode { |
(...skipping 15 matching lines...) Expand all Loading... |
82 if (cachedSubString == null) { | 82 if (cachedSubString == null) { |
83 cachedSubString = internalString.substring(begin, end); | 83 cachedSubString = internalString.substring(begin, end); |
84 } | 84 } |
85 return cachedSubString; | 85 return cachedSubString; |
86 } | 86 } |
87 | 87 |
88 String toString() => "SubstringWrapper(${slowToString()})"; | 88 String toString() => "SubstringWrapper(${slowToString()})"; |
89 | 89 |
90 String get stringValue => null; | 90 String get stringValue => null; |
91 | 91 |
92 Iterator<int> iterator() => | 92 Iterator<int> get iterator => |
93 new StringCodeIterator.substring(internalString, begin, end); | 93 new StringCodeIterator.substring(internalString, begin, end); |
94 | 94 |
95 SourceString copyWithoutQuotes(int initial, int terminal) { | 95 SourceString copyWithoutQuotes(int initial, int terminal) { |
96 assert(0 <= initial); | 96 assert(0 <= initial); |
97 assert(0 <= terminal); | 97 assert(0 <= terminal); |
98 assert(initial + terminal <= internalString.length); | 98 assert(initial + terminal <= internalString.length); |
99 return new SubstringWrapper(internalString, | 99 return new SubstringWrapper(internalString, |
100 begin + initial, end - terminal); | 100 begin + initial, end - terminal); |
101 } | 101 } |
102 | 102 |
103 bool get isEmpty => begin == end; | 103 bool get isEmpty => begin == end; |
104 | 104 |
105 bool isPrivate() => !isEmpty && identical(internalString.charCodeAt(begin), $_
); | 105 bool isPrivate() => !isEmpty && identical(internalString.charCodeAt(begin), $_
); |
106 } | 106 } |
OLD | NEW |