| 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 /** | 5 /** |
| 6 * Scanner that reads from a String and creates tokens that points to | 6 * Scanner that reads from a String and creates tokens that points to |
| 7 * substrings. | 7 * substrings. |
| 8 */ | 8 */ |
| 9 class StringScanner extends ArrayBasedScanner<SourceString> { | 9 class StringScanner extends ArrayBasedScanner<SourceString> { |
| 10 final String string; | 10 final String string; |
| 11 | 11 |
| 12 StringScanner(String this.string) : super(); | 12 StringScanner(String this.string) : super(); |
| 13 | 13 |
| 14 int nextByte() => charAt(++byteOffset); | 14 int nextByte() => charAt(++byteOffset); |
| 15 | 15 |
| 16 int peek() => charAt(byteOffset + 1); | 16 int peek() => charAt(byteOffset + 1); |
| 17 | 17 |
| 18 int charAt(index) | 18 int charAt(index) |
| 19 => (string.length > index) ? string.charCodeAt(index) : $EOF; | 19 => (string.length > index) ? string.charCodeAt(index) : $EOF; |
| 20 | 20 |
| 21 SourceString asciiString(int start) { | 21 SourceString asciiString(int start, int offset) { |
| 22 return new SubstringWrapper(string, start, byteOffset); | 22 return new SubstringWrapper(string, start, byteOffset + offset); |
| 23 } | 23 } |
| 24 | 24 |
| 25 SourceString utf8String(int start, int offset) { | 25 SourceString utf8String(int start, int offset) { |
| 26 return new SubstringWrapper(string, start, byteOffset + offset + 1); | 26 return new SubstringWrapper(string, start, byteOffset + offset + 1); |
| 27 } | 27 } |
| 28 | 28 |
| 29 void appendByteStringToken(int kind, SourceString value) { | 29 void appendByteStringToken(int kind, SourceString value) { |
| 30 // assert(kind != $a || keywords.get(value) == null); | 30 // assert(kind != $a || keywords.get(value) == null); |
| 31 tail.next = new StringToken.fromSource(kind, value, tokenStart); | 31 tail.next = new StringToken.fromSource(kind, value, tokenStart); |
| 32 tail = tail.next; | 32 tail = tail.next; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 48 } | 48 } |
| 49 | 49 |
| 50 void printOn(StringBuffer sb) { | 50 void printOn(StringBuffer sb) { |
| 51 sb.add(this); | 51 sb.add(this); |
| 52 } | 52 } |
| 53 | 53 |
| 54 String toString() => internalString.substring(begin, end); | 54 String toString() => internalString.substring(begin, end); |
| 55 | 55 |
| 56 String get stringValue() => toString(); | 56 String get stringValue() => toString(); |
| 57 } | 57 } |
| OLD | NEW |