| 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 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 SourceString utf8String(int start, int offset) { | 28 SourceString utf8String(int start, int offset) { |
| 29 return new SubstringWrapper(string, start, byteOffset + offset + 1); | 29 return new SubstringWrapper(string, start, byteOffset + offset + 1); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void appendByteStringToken(PrecedenceInfo info, SourceString value) { | 32 void appendByteStringToken(PrecedenceInfo info, SourceString value) { |
| 33 // assert(kind != $a || keywords.get(value) == null); | 33 // assert(kind != $a || keywords.get(value) == null); |
| 34 tail.next = new StringToken.fromSource(info, value, tokenStart); | 34 tail.next = new StringToken.fromSource(info, value, tokenStart); |
| 35 tail = tail.next; | 35 tail = tail.next; |
| 36 } | 36 } |
| 37 |
| 38 void unmatchedBeginGroup(BeginGroupToken begin) { |
| 39 SourceString error = new SourceString('unmatched "${begin.stringValue}"'); |
| 40 Token close = |
| 41 new StringToken.fromSource(BAD_INPUT_INFO, error, begin.charOffset); |
| 42 // We want to ensure that unmatched BeginGroupTokens are reported |
| 43 // as errors. However, the rest of the parser assume the groups |
| 44 // are well-balanced and will never look at the endGroup |
| 45 // token. This is a nice property that allows us to skip quickly |
| 46 // over correct code. By inserting an additional error token in |
| 47 // the stream, we can keep ignoring endGroup tokens. |
| 48 Token next = |
| 49 new StringToken.fromSource(BAD_INPUT_INFO, error, begin.charOffset); |
| 50 begin.endGroup = close; |
| 51 close.next = next; |
| 52 next.next = begin.next; |
| 53 } |
| 37 } | 54 } |
| 38 | 55 |
| 39 class SubstringWrapper implements SourceString { | 56 class SubstringWrapper implements SourceString { |
| 40 final String internalString; | 57 final String internalString; |
| 41 final int begin; | 58 final int begin; |
| 42 final int end; | 59 final int end; |
| 43 int cashedHash = 0; | 60 int cashedHash = 0; |
| 44 String cachedSubString; | 61 String cachedSubString; |
| 45 | 62 |
| 46 SubstringWrapper(String this.internalString, | 63 SubstringWrapper(String this.internalString, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 assert(0 <= terminal); | 97 assert(0 <= terminal); |
| 81 assert(initial + terminal <= internalString.length); | 98 assert(initial + terminal <= internalString.length); |
| 82 return new SubstringWrapper(internalString, | 99 return new SubstringWrapper(internalString, |
| 83 begin + initial, end - terminal); | 100 begin + initial, end - terminal); |
| 84 } | 101 } |
| 85 | 102 |
| 86 bool get isEmpty => begin == end; | 103 bool get isEmpty => begin == end; |
| 87 | 104 |
| 88 bool isPrivate() => !isEmpty && identical(internalString.charCodeAt(begin), $_
); | 105 bool isPrivate() => !isEmpty && identical(internalString.charCodeAt(begin), $_
); |
| 89 } | 106 } |
| OLD | NEW |