OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 /** | |
6 * Scanner that reads from a String and creates tokens that points to | |
7 * substrings. | |
8 */ | |
9 class StringScanner extends ArrayBasedScanner<SourceString> { | |
10 final String string; | |
11 | |
12 StringScanner(String this.string) : super(); | |
13 | |
14 int nextByte() => charAt(++byteOffset); | |
15 | |
16 int peek() => charAt(byteOffset + 1); | |
17 | |
18 int charAt(index) | |
19 => (string.length > index) ? string.charCodeAt(index) : $EOF; | |
20 | |
21 SourceString asciiString(int start, int offset) { | |
22 return new SubstringWrapper(string, start, byteOffset + offset); | |
23 } | |
24 | |
25 SourceString utf8String(int start, int offset) { | |
26 return new SubstringWrapper(string, start, byteOffset + offset + 1); | |
27 } | |
28 | |
29 void appendByteStringToken(PrecedenceInfo info, SourceString value) { | |
30 // assert(kind != $a || keywords.get(value) == null); | |
31 tail.next = new StringToken.fromSource(info, value, tokenStart); | |
32 tail = tail.next; | |
33 } | |
34 } | |
35 | |
36 class SubstringWrapper implements SourceString { | |
37 final String internalString; | |
38 final int begin; | |
39 final int end; | |
40 | |
41 const SubstringWrapper(String this.internalString, | |
42 int this.begin, int this.end); | |
43 | |
44 int hashCode() => slowToString().hashCode(); | |
45 | |
46 bool operator ==(other) { | |
47 return other is SourceString && slowToString() == other.slowToString(); | |
48 } | |
49 | |
50 void printOn(StringBuffer sb) { | |
51 sb.add(internalString.substring(begin, end)); | |
52 } | |
53 | |
54 String slowToString() => internalString.substring(begin, end); | |
55 | |
56 String toString() => "SubstringWrapper(${slowToString()})"; | |
57 | |
58 String get stringValue() => null; | |
59 | |
60 Iterator<int> iterator() => | |
61 new StringCodeIterator.substring(internalString, begin, end); | |
62 | |
63 SourceString copyWithoutQuotes(int initial, int terminal) { | |
64 assert(0 <= initial); | |
65 assert(0 <= terminal); | |
66 assert(initial + terminal <= internalString.length); | |
67 return new SubstringWrapper(internalString, | |
68 begin + initial, end - terminal); | |
69 } | |
70 | |
71 bool isEmpty() => begin == end; | |
72 | |
73 bool isPrivate() => !isEmpty() && internalString.charCodeAt(begin) === $_; | |
74 } | |
OLD | NEW |