| 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 library dart_scanner.token; | 5 library dart_scanner.token; |
| 6 | 6 |
| 7 import 'dart:collection' show | 7 import 'dart:collection' show |
| 8 HashSet; | 8 HashSet; |
| 9 | 9 |
| 10 import 'dart:convert' show | 10 import 'dart:convert' show |
| 11 UTF8; | 11 UTF8; |
| 12 | 12 |
| 13 import 'keyword.dart' show | 13 import 'keyword.dart' show |
| 14 Keyword; | 14 Keyword; |
| 15 | 15 |
| 16 import 'precedence.dart' show | 16 import 'precedence.dart' show |
| 17 BAD_INPUT_INFO, | 17 BAD_INPUT_INFO, |
| 18 EOF_INFO, |
| 18 PrecedenceInfo; | 19 PrecedenceInfo; |
| 19 | 20 |
| 20 import 'token_constants.dart' show | 21 import 'token_constants.dart' show |
| 21 IDENTIFIER_TOKEN; | 22 IDENTIFIER_TOKEN; |
| 22 | 23 |
| 23 /** | 24 /** |
| 24 * A token that doubles as a linked list. | 25 * A token that doubles as a linked list. |
| 25 */ | 26 */ |
| 26 abstract class Token { | 27 abstract class Token { |
| 27 /** | 28 /** |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 // This is a token that wraps around an error message. Return 1 | 106 // This is a token that wraps around an error message. Return 1 |
| 106 // instead of the size of the length of the error message. | 107 // instead of the size of the length of the error message. |
| 107 return 1; | 108 return 1; |
| 108 } else { | 109 } else { |
| 109 return value.length; | 110 return value.length; |
| 110 } | 111 } |
| 111 } | 112 } |
| 112 | 113 |
| 113 /// The character offset of the end of this token within the source text. | 114 /// The character offset of the end of this token within the source text. |
| 114 int get charEnd => charOffset + charCount; | 115 int get charEnd => charOffset + charCount; |
| 116 |
| 117 bool get isEof => false; |
| 115 } | 118 } |
| 116 | 119 |
| 117 /** | 120 /** |
| 118 * A [SymbolToken] represents the symbol in its precendence info. | 121 * A [SymbolToken] represents the symbol in its precendence info. |
| 119 * Also used for end of file with EOF_INFO. | 122 * Also used for end of file with EOF_INFO. |
| 120 */ | 123 */ |
| 121 class SymbolToken extends Token { | 124 class SymbolToken extends Token { |
| 122 final PrecedenceInfo info; | 125 final PrecedenceInfo info; |
| 123 | 126 |
| 124 SymbolToken(this.info, int charOffset) : super(charOffset); | 127 SymbolToken(this.info, int charOffset) : super(charOffset); |
| 125 | 128 |
| 126 String get value => info.value; | 129 String get value => info.value; |
| 127 | 130 |
| 128 String get stringValue => info.value; | 131 String get stringValue => info.value; |
| 129 | 132 |
| 130 bool isIdentifier() => false; | 133 bool isIdentifier() => false; |
| 131 | 134 |
| 132 String toString() => "SymbolToken($value)"; | 135 String toString() => "SymbolToken($value)"; |
| 136 |
| 137 bool get isEof => info == EOF_INFO; |
| 133 } | 138 } |
| 134 | 139 |
| 135 /** | 140 /** |
| 136 * A [BeginGroupToken] represents a symbol that may be the beginning of | 141 * A [BeginGroupToken] represents a symbol that may be the beginning of |
| 137 * a pair of brackets, i.e., ( { [ < or ${ | 142 * a pair of brackets, i.e., ( { [ < or ${ |
| 138 * The [endGroup] token points to the matching closing bracked in case | 143 * The [endGroup] token points to the matching closing bracked in case |
| 139 * it can be identified during scanning. | 144 * it can be identified during scanning. |
| 140 */ | 145 */ |
| 141 class BeginGroupToken extends SymbolToken { | 146 class BeginGroupToken extends SymbolToken { |
| 142 Token endGroup; | 147 Token endGroup; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 157 | 162 |
| 158 String get value => keyword.syntax; | 163 String get value => keyword.syntax; |
| 159 | 164 |
| 160 String get stringValue => keyword.syntax; | 165 String get stringValue => keyword.syntax; |
| 161 | 166 |
| 162 bool isIdentifier() => keyword.isPseudo || keyword.isBuiltIn; | 167 bool isIdentifier() => keyword.isPseudo || keyword.isBuiltIn; |
| 163 | 168 |
| 164 String toString() => "KeywordToken($value)"; | 169 String toString() => "KeywordToken($value)"; |
| 165 } | 170 } |
| 166 | 171 |
| 167 abstract class ErrorToken extends Token { | |
| 168 ErrorToken(int charOffset) : super(charOffset); | |
| 169 | |
| 170 PrecedenceInfo get info => BAD_INPUT_INFO; | |
| 171 | |
| 172 String get value { | |
| 173 throw assertionMessage; | |
| 174 } | |
| 175 | |
| 176 String get stringValue => null; | |
| 177 | |
| 178 bool isIdentifier() => false; | |
| 179 | |
| 180 String get assertionMessage; | |
| 181 } | |
| 182 | |
| 183 class BadInputToken extends ErrorToken { | |
| 184 final int character; | |
| 185 | |
| 186 BadInputToken(this.character, int charOffset) : super(charOffset); | |
| 187 | |
| 188 String toString() => "BadInputToken($character)"; | |
| 189 | |
| 190 String get assertionMessage { | |
| 191 return 'Character U+${character.toRadixString(16)} not allowed here.'; | |
| 192 } | |
| 193 } | |
| 194 | |
| 195 class UnterminatedToken extends ErrorToken { | |
| 196 final String start; | |
| 197 final int endOffset; | |
| 198 | |
| 199 UnterminatedToken(this.start, int charOffset, this.endOffset) | |
| 200 : super(charOffset); | |
| 201 | |
| 202 String toString() => "UnterminatedToken($start)"; | |
| 203 | |
| 204 String get assertionMessage => "'$start' isn't terminated."; | |
| 205 | |
| 206 int get charCount => endOffset - charOffset; | |
| 207 } | |
| 208 | |
| 209 class UnmatchedToken extends ErrorToken { | |
| 210 final BeginGroupToken begin; | |
| 211 | |
| 212 UnmatchedToken(BeginGroupToken begin) | |
| 213 : this.begin = begin, | |
| 214 super(begin.charOffset); | |
| 215 | |
| 216 String toString() => "UnmatchedToken(${begin.value})"; | |
| 217 | |
| 218 String get assertionMessage => "'$begin' isn't closed."; | |
| 219 } | |
| 220 | |
| 221 /** | 172 /** |
| 222 * A String-valued token. Represents identifiers, string literals, | 173 * A String-valued token. Represents identifiers, string literals, |
| 223 * number literals, comments, and error tokens, using the corresponding | 174 * number literals, comments, and error tokens, using the corresponding |
| 224 * precedence info. | 175 * precedence info. |
| 225 */ | 176 */ |
| 226 class StringToken extends Token { | 177 class StringToken extends Token { |
| 227 /** | 178 /** |
| 228 * The length threshold above which substring tokens are computed lazily. | 179 * The length threshold above which substring tokens are computed lazily. |
| 229 * | 180 * |
| 230 * For string tokens that are substrings of the program source, the actual | 181 * For string tokens that are substrings of the program source, the actual |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 value == '<=' || | 367 value == '<=' || |
| 417 value == '<' || | 368 value == '<' || |
| 418 value == '&' || | 369 value == '&' || |
| 419 value == '^' || | 370 value == '^' || |
| 420 value == '|'; | 371 value == '|'; |
| 421 } | 372 } |
| 422 | 373 |
| 423 bool isTernaryOperator(String value) => value == '[]='; | 374 bool isTernaryOperator(String value) => value == '[]='; |
| 424 | 375 |
| 425 bool isMinusOperator(String value) => value == '-'; | 376 bool isMinusOperator(String value) => value == '-'; |
| OLD | NEW |