| 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 final int EOF_TOKEN = 0; | 5 final int EOF_TOKEN = 0; |
| 6 | 6 |
| 7 final int KEYWORD_TOKEN = $k; | 7 final int KEYWORD_TOKEN = $k; |
| 8 final int IDENTIFIER_TOKEN = $a; | 8 final int IDENTIFIER_TOKEN = $a; |
| 9 final int DOUBLE_TOKEN = $d; | 9 final int DOUBLE_TOKEN = $d; |
| 10 final int INT_TOKEN = $i; | 10 final int INT_TOKEN = $i; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 115 |
| 116 StringToken(PrecedenceInfo info, String value, int charOffset) | 116 StringToken(PrecedenceInfo info, String value, int charOffset) |
| 117 : this.fromSource(info, new SourceString(value), charOffset); | 117 : this.fromSource(info, new SourceString(value), charOffset); |
| 118 | 118 |
| 119 StringToken.fromSource(PrecedenceInfo info, this.value, int charOffset) | 119 StringToken.fromSource(PrecedenceInfo info, this.value, int charOffset) |
| 120 : super(info, charOffset); | 120 : super(info, charOffset); |
| 121 | 121 |
| 122 String toString() => value.toString(); | 122 String toString() => value.toString(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 interface SourceString extends Hashable default StringWrapper { | 125 interface SourceString extends Hashable, Iterable<int> default StringWrapper { |
| 126 const SourceString(String string); | 126 const SourceString(String string); |
| 127 | 127 |
| 128 int get length(); | 128 int get length(); |
| 129 | 129 |
| 130 void printOn(StringBuffer sb); | 130 void printOn(StringBuffer sb); |
| 131 | 131 |
| 132 String get stringValue(); | 132 String get stringValue(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 class StringWrapper implements SourceString { | 135 class StringWrapper implements SourceString { |
| 136 final String stringValue; | 136 final String stringValue; |
| 137 | 137 |
| 138 const StringWrapper(String this.stringValue); | 138 const StringWrapper(String this.stringValue); |
| 139 | 139 |
| 140 int hashCode() => stringValue.hashCode(); | 140 int hashCode() => stringValue.hashCode(); |
| 141 | 141 |
| 142 bool operator ==(other) { | 142 bool operator ==(other) { |
| 143 return other is SourceString && toString() == other.toString(); | 143 return other is SourceString && toString() == other.toString(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 Iterator<int> iterator() => new StringCodeIterator(stringValue); |
| 147 |
| 146 int get length() => stringValue.length; | 148 int get length() => stringValue.length; |
| 147 | 149 |
| 148 void printOn(StringBuffer sb) { | 150 void printOn(StringBuffer sb) { |
| 149 sb.add(stringValue); | 151 sb.add(stringValue); |
| 150 } | 152 } |
| 151 | 153 |
| 152 String toString() => stringValue; | 154 String toString() => stringValue; |
| 153 } | 155 } |
| 154 | 156 |
| 157 class StringCodeIterator implements Iterator<int> { |
| 158 final String string; |
| 159 int index; |
| 160 final int end; |
| 161 |
| 162 StringCodeIterator(String string) : |
| 163 this.string = string, index = 0, end = string.length; |
| 164 |
| 165 StringCodeIterator.substring(this.string, this.index, this.end) { |
| 166 assert(0 <= index); |
| 167 assert(index <= end); |
| 168 assert(end <= string.length); |
| 169 } |
| 170 |
| 171 bool hasNext() => index < end; |
| 172 int next() => string.charCodeAt(index++); |
| 173 } |
| 174 |
| 155 class BeginGroupToken extends StringToken { | 175 class BeginGroupToken extends StringToken { |
| 156 Token endGroup; | 176 Token endGroup; |
| 157 BeginGroupToken(PrecedenceInfo info, String value, int charOffset) | 177 BeginGroupToken(PrecedenceInfo info, String value, int charOffset) |
| 158 : super(info, value, charOffset); | 178 : super(info, value, charOffset); |
| 159 } | 179 } |
| 160 | 180 |
| 161 class PrecedenceInfo { | 181 class PrecedenceInfo { |
| 162 final SourceString value; | 182 final SourceString value; |
| 163 final int precedence; | 183 final int precedence; |
| 164 final int kind; | 184 final int kind; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 | 375 |
| 356 final PrecedenceInfo DOUBLE_INFO = | 376 final PrecedenceInfo DOUBLE_INFO = |
| 357 const PrecedenceInfo(const SourceString('double'), 0, DOUBLE_TOKEN); | 377 const PrecedenceInfo(const SourceString('double'), 0, DOUBLE_TOKEN); |
| 358 | 378 |
| 359 final PrecedenceInfo STRING_INTERPOLATION_INFO = | 379 final PrecedenceInfo STRING_INTERPOLATION_INFO = |
| 360 const PrecedenceInfo(const SourceString('\${'), 0, | 380 const PrecedenceInfo(const SourceString('\${'), 0, |
| 361 STRING_INTERPOLATION_TOKEN); | 381 STRING_INTERPOLATION_TOKEN); |
| 362 | 382 |
| 363 final PrecedenceInfo HEXADECIMAL_INFO = | 383 final PrecedenceInfo HEXADECIMAL_INFO = |
| 364 const PrecedenceInfo(const SourceString('hexadecimal'), 0, HEXADECIMAL_TOKEN); | 384 const PrecedenceInfo(const SourceString('hexadecimal'), 0, HEXADECIMAL_TOKEN); |
| OLD | NEW |