| 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 fasta.scanner.token; | 5 library fasta.scanner.token; |
| 6 | 6 |
| 7 import '../../scanner/token.dart' as analyzer; | 7 import '../../scanner/token.dart' as analyzer; |
| 8 import '../../scanner/token.dart' show TokenType; | 8 import '../../scanner/token.dart' show TokenType; |
| 9 | 9 |
| 10 import 'token_constants.dart' show IDENTIFIER_TOKEN; | 10 import 'token_constants.dart' show IDENTIFIER_TOKEN; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 @override | 47 @override |
| 48 analyzer.CommentToken get precedingComments => precedingCommentTokens; | 48 analyzer.CommentToken get precedingComments => precedingCommentTokens; |
| 49 | 49 |
| 50 @override | 50 @override |
| 51 void set precedingComments(analyzer.CommentToken token) { | 51 void set precedingComments(analyzer.CommentToken token) { |
| 52 precedingCommentTokens = token; | 52 precedingCommentTokens = token; |
| 53 } | 53 } |
| 54 | 54 |
| 55 /** | 55 /** |
| 56 * The precedence info for this token. [info] determines the kind and the | |
| 57 * precedence level of this token. | |
| 58 * | |
| 59 * Defined as getter to save a field in the [KeywordToken] subclass. | |
| 60 */ | |
| 61 TokenType get info; | |
| 62 | |
| 63 /** | |
| 64 * The string represented by this token, a substring of the source code. | 56 * The string represented by this token, a substring of the source code. |
| 65 * | 57 * |
| 66 * For [StringToken]s the [lexeme] includes the quotes, explicit escapes, etc. | 58 * For [StringToken]s the [lexeme] includes the quotes, explicit escapes, etc. |
| 67 */ | 59 */ |
| 68 String get lexeme; | 60 String get lexeme; |
| 69 | 61 |
| 70 /** | 62 /** |
| 71 * For symbol and keyword tokens, returns the string value represented by this | 63 * For symbol and keyword tokens, returns the string value represented by this |
| 72 * token. For [StringToken]s this method returns [:null:]. | 64 * token. For [StringToken]s this method returns [:null:]. |
| 73 * | 65 * |
| 74 * For [SymbolToken]s and [KeywordToken]s, the string value is a compile-time | 66 * For [SymbolToken]s and [KeywordToken]s, the string value is a compile-time |
| 75 * constant originating in the [TokenType] or in the [Keyword] instance. | 67 * constant originating in the [TokenType] or in the [Keyword] instance. |
| 76 * This allows testing for keywords and symbols using [:identical:], e.g., | 68 * This allows testing for keywords and symbols using [:identical:], e.g., |
| 77 * [:identical('class', token.value):]. | 69 * [:identical('class', token.value):]. |
| 78 * | 70 * |
| 79 * Note that returning [:null:] for string tokens is important to identify | 71 * Note that returning [:null:] for string tokens is important to identify |
| 80 * symbols and keywords, we cannot use [lexeme] instead. The string literal | 72 * symbols and keywords, we cannot use [lexeme] instead. The string literal |
| 81 * "$a($b" | 73 * "$a($b" |
| 82 * produces ..., SymbolToken($), StringToken(a), StringToken((), ... | 74 * produces ..., SymbolToken($), StringToken(a), StringToken((), ... |
| 83 * | 75 * |
| 84 * After parsing the identifier 'a', the parser tests for a function | 76 * After parsing the identifier 'a', the parser tests for a function |
| 85 * declaration using [:identical(next.stringValue, '('):], which (rightfully) | 77 * declaration using [:identical(next.stringValue, '('):], which (rightfully) |
| 86 * returns false because stringValue returns [:null:]. | 78 * returns false because stringValue returns [:null:]. |
| 87 */ | 79 */ |
| 88 String get stringValue; | 80 String get stringValue; |
| 89 | 81 |
| 90 /** | 82 /** |
| 91 * The kind enum of this token as determined by its [info]. | 83 * The kind enum of this token as determined by its [type]. |
| 92 */ | 84 */ |
| 93 int get kind => info.kind; | 85 int get kind => type.kind; |
| 94 | 86 |
| 95 /** | 87 /** |
| 96 * The precedence level for this token. | 88 * The precedence level for this token. |
| 97 */ | 89 */ |
| 98 int get precedence => info.precedence; | 90 int get precedence => type.precedence; |
| 99 | 91 |
| 100 /** | 92 /** |
| 101 * True if this token is an identifier. Some keywords allowed as identifiers, | 93 * True if this token is an identifier. Some keywords allowed as identifiers, |
| 102 * see implementation in [KeywordToken]. | 94 * see implementation in [KeywordToken]. |
| 103 */ | 95 */ |
| 104 bool get isIdentifier; | 96 bool get isIdentifier; |
| 105 | 97 |
| 106 bool get isPseudo => false; | 98 bool get isPseudo => false; |
| 107 | 99 |
| 108 /** | 100 /** |
| 109 * Returns a textual representation of this token to be used for debugging | 101 * Returns a textual representation of this token to be used for debugging |
| 110 * purposes. The resulting string might contain information about the | 102 * purposes. The resulting string might contain information about the |
| 111 * structure of the token, for example 'StringToken(foo)' for the identifier | 103 * structure of the token, for example 'StringToken(foo)' for the identifier |
| 112 * token 'foo'. | 104 * token 'foo'. |
| 113 * | 105 * |
| 114 * Use [lexeme] for the text actually parsed by the token. | 106 * Use [lexeme] for the text actually parsed by the token. |
| 115 */ | 107 */ |
| 116 String toString(); | 108 String toString(); |
| 117 | 109 |
| 118 /** | 110 /** |
| 119 * The number of characters parsed by this token. | 111 * The number of characters parsed by this token. |
| 120 */ | 112 */ |
| 121 int get charCount { | 113 int get charCount { |
| 122 if (info == analyzer.TokenType.BAD_INPUT) { | 114 if (type == analyzer.TokenType.BAD_INPUT) { |
| 123 // This is a token that wraps around an error message. Return 1 | 115 // This is a token that wraps around an error message. Return 1 |
| 124 // instead of the size of the length of the error message. | 116 // instead of the size of the length of the error message. |
| 125 return 1; | 117 return 1; |
| 126 } else { | 118 } else { |
| 127 return lexeme.length; | 119 return lexeme.length; |
| 128 } | 120 } |
| 129 } | 121 } |
| 130 | 122 |
| 131 /// The character offset of the end of this token within the source text. | 123 /// The character offset of the end of this token within the source text. |
| 132 int get charEnd => charOffset + charCount; | 124 int get charEnd => charOffset + charCount; |
| 133 | 125 |
| 134 bool get isEof => false; | 126 bool get isEof => false; |
| 135 | 127 |
| 136 bool get isBuiltInIdentifier => false; | 128 bool get isBuiltInIdentifier => false; |
| 137 | 129 |
| 138 @override | 130 @override |
| 139 bool get isOperator => info.isOperator; | 131 bool get isOperator => type.isOperator; |
| 140 | 132 |
| 141 @override | 133 @override |
| 142 bool get isUserDefinableOperator => info.isUserDefinableOperator; | 134 bool get isUserDefinableOperator => type.isUserDefinableOperator; |
| 143 | |
| 144 @override | |
| 145 analyzer.TokenType get type => info; | |
| 146 | 135 |
| 147 @override | 136 @override |
| 148 int get offset => charOffset; | 137 int get offset => charOffset; |
| 149 | 138 |
| 150 @override | 139 @override |
| 151 set offset(int newOffset) { | 140 set offset(int newOffset) { |
| 152 charOffset = newOffset; | 141 charOffset = newOffset; |
| 153 } | 142 } |
| 154 | 143 |
| 155 @override | 144 @override |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 | 220 |
| 232 @override | 221 @override |
| 233 Object value() => lexeme; | 222 Object value() => lexeme; |
| 234 } | 223 } |
| 235 | 224 |
| 236 /** | 225 /** |
| 237 * A [SymbolToken] represents the symbol in its precedence info. | 226 * A [SymbolToken] represents the symbol in its precedence info. |
| 238 * Also used for end of file with EOF_INFO. | 227 * Also used for end of file with EOF_INFO. |
| 239 */ | 228 */ |
| 240 class SymbolToken extends Token { | 229 class SymbolToken extends Token { |
| 241 final TokenType info; | 230 final TokenType type; |
| 242 | 231 |
| 243 SymbolToken(this.info, int charOffset) : super(charOffset); | 232 SymbolToken(this.type, int charOffset) : super(charOffset); |
| 244 | 233 |
| 245 factory SymbolToken.eof(int charOffset) { | 234 factory SymbolToken.eof(int charOffset) { |
| 246 var eof = new SyntheticSymbolToken(analyzer.TokenType.EOF, charOffset); | 235 var eof = new SyntheticSymbolToken(analyzer.TokenType.EOF, charOffset); |
| 247 // EOF points to itself so there's always infinite look-ahead. | 236 // EOF points to itself so there's always infinite look-ahead. |
| 248 eof.previousToken = eof; | 237 eof.previousToken = eof; |
| 249 eof.next = eof; | 238 eof.next = eof; |
| 250 return eof; | 239 return eof; |
| 251 } | 240 } |
| 252 | 241 |
| 253 @override | 242 @override |
| 254 String get lexeme => info.value; | 243 String get lexeme => type.value; |
| 255 | 244 |
| 256 @override | 245 @override |
| 257 String get stringValue => info.value; | 246 String get stringValue => type.value; |
| 258 | 247 |
| 259 @override | 248 @override |
| 260 bool get isIdentifier => false; | 249 bool get isIdentifier => false; |
| 261 | 250 |
| 262 @override | 251 @override |
| 263 String toString() => "SymbolToken(${isEof ? '-eof-' : lexeme})"; | 252 String toString() => "SymbolToken(${isEof ? '-eof-' : lexeme})"; |
| 264 | 253 |
| 265 @override | 254 @override |
| 266 bool get isEof => info == analyzer.TokenType.EOF; | 255 bool get isEof => type == analyzer.TokenType.EOF; |
| 267 | 256 |
| 268 @override | 257 @override |
| 269 Token copyWithoutComments() => isEof | 258 Token copyWithoutComments() => isEof |
| 270 ? new SymbolToken.eof(charOffset) | 259 ? new SymbolToken.eof(charOffset) |
| 271 : new SymbolToken(info, charOffset); | 260 : new SymbolToken(type, charOffset); |
| 272 } | 261 } |
| 273 | 262 |
| 274 /** | 263 /** |
| 275 * A [SyntheticSymbolToken] represents the symbol in its precedence info | 264 * A [SyntheticSymbolToken] represents the symbol in its precedence info |
| 276 * which does not exist in the original source. | 265 * which does not exist in the original source. |
| 277 * For example, if the scanner finds '(' missing a ')' | 266 * For example, if the scanner finds '(' missing a ')' |
| 278 * then it will insert an synthetic ')'. | 267 * then it will insert an synthetic ')'. |
| 279 */ | 268 */ |
| 280 class SyntheticSymbolToken extends SymbolToken { | 269 class SyntheticSymbolToken extends SymbolToken { |
| 281 SyntheticSymbolToken(TokenType info, int charOffset) | 270 SyntheticSymbolToken(TokenType type, int charOffset) |
| 282 : super(info, charOffset); | 271 : super(type, charOffset); |
| 283 | 272 |
| 284 @override | 273 @override |
| 285 int get charCount => 0; | 274 int get charCount => 0; |
| 286 | 275 |
| 287 @override | 276 @override |
| 288 bool get isSynthetic => true; | 277 bool get isSynthetic => true; |
| 289 | 278 |
| 290 @override | 279 @override |
| 291 Token copyWithoutComments() => isEof | 280 Token copyWithoutComments() => isEof |
| 292 ? new SymbolToken.eof(charOffset) | 281 ? new SymbolToken.eof(charOffset) |
| 293 : new SyntheticSymbolToken(info, charOffset); | 282 : new SyntheticSymbolToken(type, charOffset); |
| 294 } | 283 } |
| 295 | 284 |
| 296 /** | 285 /** |
| 297 * A [BeginGroupToken] represents a symbol that may be the beginning of | 286 * A [BeginGroupToken] represents a symbol that may be the beginning of |
| 298 * a pair of brackets, i.e., ( { [ < or ${ | 287 * a pair of brackets, i.e., ( { [ < or ${ |
| 299 * The [endGroup] token points to the matching closing bracket in case | 288 * The [endGroup] token points to the matching closing bracket in case |
| 300 * it can be identified during scanning. | 289 * it can be identified during scanning. |
| 301 */ | 290 */ |
| 302 class BeginGroupToken extends SymbolToken | 291 class BeginGroupToken extends SymbolToken |
| 303 implements analyzer.BeginTokenWithComment { | 292 implements analyzer.BeginTokenWithComment { |
| 304 Token endGroup; | 293 Token endGroup; |
| 305 | 294 |
| 306 BeginGroupToken(TokenType info, int charOffset) : super(info, charOffset); | 295 BeginGroupToken(TokenType type, int charOffset) : super(type, charOffset); |
| 307 | 296 |
| 308 @override | 297 @override |
| 309 analyzer.Token get endToken => endGroup; | 298 analyzer.Token get endToken => endGroup; |
| 310 | 299 |
| 311 @override | 300 @override |
| 312 void set endToken(analyzer.Token token) { | 301 void set endToken(analyzer.Token token) { |
| 313 endGroup = token; | 302 endGroup = token; |
| 314 } | 303 } |
| 315 | 304 |
| 316 @override | 305 @override |
| 317 Token copyWithoutComments() => new BeginGroupToken(info, charOffset); | 306 Token copyWithoutComments() => new BeginGroupToken(type, charOffset); |
| 318 } | 307 } |
| 319 | 308 |
| 320 /** | 309 /** |
| 321 * A keyword token. | 310 * A keyword token. |
| 322 */ | 311 */ |
| 323 class KeywordToken extends Token implements analyzer.KeywordTokenWithComment { | 312 class KeywordToken extends Token implements analyzer.KeywordTokenWithComment { |
| 324 final analyzer.Keyword keyword; | 313 final analyzer.Keyword keyword; |
| 325 | 314 |
| 326 KeywordToken(this.keyword, int charOffset) : super(charOffset); | 315 KeywordToken(this.keyword, int charOffset) : super(charOffset); |
| 327 | 316 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 * | 371 * |
| 383 * For string tokens that are substrings of the program source, the actual | 372 * For string tokens that are substrings of the program source, the actual |
| 384 * substring extraction is performed lazily. This is beneficial because | 373 * substring extraction is performed lazily. This is beneficial because |
| 385 * not all scanned code is actually used. For unused parts, the substrings | 374 * not all scanned code is actually used. For unused parts, the substrings |
| 386 * are never computed and allocated. | 375 * are never computed and allocated. |
| 387 */ | 376 */ |
| 388 static const int LAZY_THRESHOLD = 4; | 377 static const int LAZY_THRESHOLD = 4; |
| 389 | 378 |
| 390 var /* String | LazySubtring */ valueOrLazySubstring; | 379 var /* String | LazySubtring */ valueOrLazySubstring; |
| 391 | 380 |
| 392 final TokenType info; | 381 final TokenType type; |
| 393 | 382 |
| 394 /** | 383 /** |
| 395 * Creates a non-lazy string token. If [canonicalize] is true, the string | 384 * Creates a non-lazy string token. If [canonicalize] is true, the string |
| 396 * is canonicalized before the token is created. | 385 * is canonicalized before the token is created. |
| 397 */ | 386 */ |
| 398 StringToken.fromString(this.info, String value, int charOffset, | 387 StringToken.fromString(this.type, String value, int charOffset, |
| 399 {bool canonicalize: false}) | 388 {bool canonicalize: false}) |
| 400 : valueOrLazySubstring = | 389 : valueOrLazySubstring = |
| 401 canonicalizedString(value, 0, value.length, canonicalize), | 390 canonicalizedString(value, 0, value.length, canonicalize), |
| 402 super(charOffset); | 391 super(charOffset); |
| 403 | 392 |
| 404 /** | 393 /** |
| 405 * Creates a lazy string token. If [canonicalize] is true, the string | 394 * Creates a lazy string token. If [canonicalize] is true, the string |
| 406 * is canonicalized before the token is created. | 395 * is canonicalized before the token is created. |
| 407 */ | 396 */ |
| 408 StringToken.fromSubstring( | 397 StringToken.fromSubstring( |
| 409 this.info, String data, int start, int end, int charOffset, | 398 this.type, String data, int start, int end, int charOffset, |
| 410 {bool canonicalize: false}) | 399 {bool canonicalize: false}) |
| 411 : super(charOffset) { | 400 : super(charOffset) { |
| 412 int length = end - start; | 401 int length = end - start; |
| 413 if (length <= LAZY_THRESHOLD) { | 402 if (length <= LAZY_THRESHOLD) { |
| 414 valueOrLazySubstring = | 403 valueOrLazySubstring = |
| 415 canonicalizedString(data, start, end, canonicalize); | 404 canonicalizedString(data, start, end, canonicalize); |
| 416 } else { | 405 } else { |
| 417 valueOrLazySubstring = | 406 valueOrLazySubstring = |
| 418 new LazySubstring(data, start, length, canonicalize); | 407 new LazySubstring(data, start, length, canonicalize); |
| 419 } | 408 } |
| 420 } | 409 } |
| 421 | 410 |
| 422 /** | 411 /** |
| 423 * Creates a lazy string token. If [asciiOnly] is false, the byte array | 412 * Creates a lazy string token. If [asciiOnly] is false, the byte array |
| 424 * is passed through a UTF-8 decoder. | 413 * is passed through a UTF-8 decoder. |
| 425 */ | 414 */ |
| 426 StringToken.fromUtf8Bytes(this.info, List<int> data, int start, int end, | 415 StringToken.fromUtf8Bytes(this.type, List<int> data, int start, int end, |
| 427 bool asciiOnly, int charOffset) | 416 bool asciiOnly, int charOffset) |
| 428 : super(charOffset) { | 417 : super(charOffset) { |
| 429 int length = end - start; | 418 int length = end - start; |
| 430 if (length <= LAZY_THRESHOLD) { | 419 if (length <= LAZY_THRESHOLD) { |
| 431 valueOrLazySubstring = decodeUtf8(data, start, end, asciiOnly); | 420 valueOrLazySubstring = decodeUtf8(data, start, end, asciiOnly); |
| 432 } else { | 421 } else { |
| 433 valueOrLazySubstring = new LazySubstring(data, start, length, asciiOnly); | 422 valueOrLazySubstring = new LazySubstring(data, start, length, asciiOnly); |
| 434 } | 423 } |
| 435 } | 424 } |
| 436 | 425 |
| 437 StringToken._(this.info, this.valueOrLazySubstring, int charOffset) | 426 StringToken._(this.type, this.valueOrLazySubstring, int charOffset) |
| 438 : super(charOffset); | 427 : super(charOffset); |
| 439 | 428 |
| 440 String get lexeme { | 429 String get lexeme { |
| 441 if (valueOrLazySubstring is String) { | 430 if (valueOrLazySubstring is String) { |
| 442 return valueOrLazySubstring; | 431 return valueOrLazySubstring; |
| 443 } else { | 432 } else { |
| 444 assert(valueOrLazySubstring is LazySubstring); | 433 assert(valueOrLazySubstring is LazySubstring); |
| 445 var data = valueOrLazySubstring.data; | 434 var data = valueOrLazySubstring.data; |
| 446 int start = valueOrLazySubstring.start; | 435 int start = valueOrLazySubstring.start; |
| 447 int end = start + valueOrLazySubstring.length; | 436 int end = start + valueOrLazySubstring.length; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 470 if (!canonicalize) return s; | 459 if (!canonicalize) return s; |
| 471 return canonicalizer.canonicalize(s, start, end, false); | 460 return canonicalizer.canonicalize(s, start, end, false); |
| 472 } | 461 } |
| 473 | 462 |
| 474 static String decodeUtf8(List<int> data, int start, int end, bool asciiOnly) { | 463 static String decodeUtf8(List<int> data, int start, int end, bool asciiOnly) { |
| 475 return canonicalizer.canonicalize(data, start, end, asciiOnly); | 464 return canonicalizer.canonicalize(data, start, end, asciiOnly); |
| 476 } | 465 } |
| 477 | 466 |
| 478 @override | 467 @override |
| 479 Token copyWithoutComments() => | 468 Token copyWithoutComments() => |
| 480 new StringToken._(info, valueOrLazySubstring, charOffset); | 469 new StringToken._(type, valueOrLazySubstring, charOffset); |
| 481 | 470 |
| 482 @override | 471 @override |
| 483 String value() => lexeme; | 472 String value() => lexeme; |
| 484 } | 473 } |
| 485 | 474 |
| 486 /** | 475 /** |
| 487 * A String-valued token that does not exist in the original source. | 476 * A String-valued token that does not exist in the original source. |
| 488 */ | 477 */ |
| 489 class SyntheticStringToken extends StringToken | 478 class SyntheticStringToken extends StringToken |
| 490 implements analyzer.SyntheticStringToken { | 479 implements analyzer.SyntheticStringToken { |
| 491 SyntheticStringToken(TokenType info, String value, int offset) | 480 SyntheticStringToken(TokenType type, String value, int offset) |
| 492 : super._(info, value, offset); | 481 : super._(type, value, offset); |
| 493 | 482 |
| 494 @override | 483 @override |
| 495 bool get isSynthetic => true; | 484 bool get isSynthetic => true; |
| 496 | 485 |
| 497 @override | 486 @override |
| 498 int get length => 0; | 487 int get length => 0; |
| 499 | 488 |
| 500 @override | 489 @override |
| 501 Token copyWithoutComments() => | 490 Token copyWithoutComments() => |
| 502 new SyntheticStringToken(info, valueOrLazySubstring, offset); | 491 new SyntheticStringToken(type, valueOrLazySubstring, offset); |
| 503 } | 492 } |
| 504 | 493 |
| 505 class CommentToken extends StringToken implements analyzer.CommentToken { | 494 class CommentToken extends StringToken implements analyzer.CommentToken { |
| 506 @override | 495 @override |
| 507 analyzer.TokenWithComment parent; | 496 analyzer.TokenWithComment parent; |
| 508 | 497 |
| 509 /** | 498 /** |
| 510 * Creates a lazy comment token. If [canonicalize] is true, the string | 499 * Creates a lazy comment token. If [canonicalize] is true, the string |
| 511 * is canonicalized before the token is created. | 500 * is canonicalized before the token is created. |
| 512 */ | 501 */ |
| 513 CommentToken.fromSubstring( | 502 CommentToken.fromSubstring( |
| 514 TokenType info, String data, int start, int end, int charOffset, | 503 TokenType type, String data, int start, int end, int charOffset, |
| 515 {bool canonicalize: false}) | 504 {bool canonicalize: false}) |
| 516 : super.fromSubstring(info, data, start, end, charOffset, | 505 : super.fromSubstring(type, data, start, end, charOffset, |
| 517 canonicalize: canonicalize); | 506 canonicalize: canonicalize); |
| 518 | 507 |
| 519 /** | 508 /** |
| 520 * Creates a non-lazy comment token. | 509 * Creates a non-lazy comment token. |
| 521 */ | 510 */ |
| 522 CommentToken.fromString(TokenType info, String lexeme, int charOffset) | 511 CommentToken.fromString(TokenType type, String lexeme, int charOffset) |
| 523 : super.fromString(info, lexeme, charOffset); | 512 : super.fromString(type, lexeme, charOffset); |
| 524 | 513 |
| 525 /** | 514 /** |
| 526 * Creates a lazy string token. If [asciiOnly] is false, the byte array | 515 * Creates a lazy string token. If [asciiOnly] is false, the byte array |
| 527 * is passed through a UTF-8 decoder. | 516 * is passed through a UTF-8 decoder. |
| 528 */ | 517 */ |
| 529 CommentToken.fromUtf8Bytes(TokenType info, List<int> data, int start, int end, | 518 CommentToken.fromUtf8Bytes(TokenType type, List<int> data, int start, int end, |
| 530 bool asciiOnly, int charOffset) | 519 bool asciiOnly, int charOffset) |
| 531 : super.fromUtf8Bytes(info, data, start, end, asciiOnly, charOffset); | 520 : super.fromUtf8Bytes(type, data, start, end, asciiOnly, charOffset); |
| 532 | 521 |
| 533 CommentToken._(TokenType info, valueOrLazySubstring, int charOffset) | 522 CommentToken._(TokenType type, valueOrLazySubstring, int charOffset) |
| 534 : super._(info, valueOrLazySubstring, charOffset); | 523 : super._(type, valueOrLazySubstring, charOffset); |
| 535 | 524 |
| 536 @override | 525 @override |
| 537 CommentToken copy() => | 526 CommentToken copy() => |
| 538 new CommentToken._(info, valueOrLazySubstring, charOffset); | 527 new CommentToken._(type, valueOrLazySubstring, charOffset); |
| 539 | 528 |
| 540 @override | 529 @override |
| 541 void remove() { | 530 void remove() { |
| 542 if (previous != null) { | 531 if (previous != null) { |
| 543 previous.setNextWithoutSettingPrevious(next); | 532 previous.setNextWithoutSettingPrevious(next); |
| 544 next?.previous = previous; | 533 next?.previous = previous; |
| 545 } else { | 534 } else { |
| 546 assert(parent.precedingComments == this); | 535 assert(parent.precedingComments == this); |
| 547 parent.precedingComments = next as CommentToken; | 536 parent.precedingComments = next as CommentToken; |
| 548 } | 537 } |
| 549 } | 538 } |
| 550 } | 539 } |
| 551 | 540 |
| 552 class DartDocToken extends CommentToken | 541 class DartDocToken extends CommentToken |
| 553 implements analyzer.DocumentationCommentToken { | 542 implements analyzer.DocumentationCommentToken { |
| 554 /** | 543 /** |
| 555 * The references embedded within the documentation comment. | 544 * The references embedded within the documentation comment. |
| 556 * This list will be empty unless this is a documentation comment that has | 545 * This list will be empty unless this is a documentation comment that has |
| 557 * references embedded within it. | 546 * references embedded within it. |
| 558 */ | 547 */ |
| 559 final List<Token> references = <Token>[]; | 548 final List<Token> references = <Token>[]; |
| 560 | 549 |
| 561 /** | 550 /** |
| 562 * Creates a lazy comment token. If [canonicalize] is true, the string | 551 * Creates a lazy comment token. If [canonicalize] is true, the string |
| 563 * is canonicalized before the token is created. | 552 * is canonicalized before the token is created. |
| 564 */ | 553 */ |
| 565 DartDocToken.fromSubstring( | 554 DartDocToken.fromSubstring( |
| 566 TokenType info, String data, int start, int end, int charOffset, | 555 TokenType type, String data, int start, int end, int charOffset, |
| 567 {bool canonicalize: false}) | 556 {bool canonicalize: false}) |
| 568 : super.fromSubstring(info, data, start, end, charOffset, | 557 : super.fromSubstring(type, data, start, end, charOffset, |
| 569 canonicalize: canonicalize); | 558 canonicalize: canonicalize); |
| 570 | 559 |
| 571 /** | 560 /** |
| 572 * Creates a lazy string token. If [asciiOnly] is false, the byte array | 561 * Creates a lazy string token. If [asciiOnly] is false, the byte array |
| 573 * is passed through a UTF-8 decoder. | 562 * is passed through a UTF-8 decoder. |
| 574 */ | 563 */ |
| 575 DartDocToken.fromUtf8Bytes(TokenType info, List<int> data, int start, int end, | 564 DartDocToken.fromUtf8Bytes(TokenType type, List<int> data, int start, int end, |
| 576 bool asciiOnly, int charOffset) | 565 bool asciiOnly, int charOffset) |
| 577 : super.fromUtf8Bytes(info, data, start, end, asciiOnly, charOffset); | 566 : super.fromUtf8Bytes(type, data, start, end, asciiOnly, charOffset); |
| 578 | 567 |
| 579 DartDocToken._(TokenType info, valueOrLazySubstring, int charOffset) | 568 DartDocToken._(TokenType type, valueOrLazySubstring, int charOffset) |
| 580 : super._(info, valueOrLazySubstring, charOffset); | 569 : super._(type, valueOrLazySubstring, charOffset); |
| 581 | 570 |
| 582 @override | 571 @override |
| 583 DartDocToken copy() { | 572 DartDocToken copy() { |
| 584 DartDocToken copy = | 573 DartDocToken copy = |
| 585 new DartDocToken._(info, valueOrLazySubstring, charOffset); | 574 new DartDocToken._(type, valueOrLazySubstring, charOffset); |
| 586 references.forEach((ref) => copy.references.add(ref.copy())); | 575 references.forEach((ref) => copy.references.add(ref.copy())); |
| 587 return copy; | 576 return copy; |
| 588 } | 577 } |
| 589 } | 578 } |
| 590 | 579 |
| 591 /** | 580 /** |
| 592 * This class represents the necessary information to compute a substring | 581 * This class represents the necessary information to compute a substring |
| 593 * lazily. The substring can either originate from a string or from | 582 * lazily. The substring can either originate from a string or from |
| 594 * a [:List<int>:] of UTF-8 bytes. | 583 * a [:List<int>:] of UTF-8 bytes. |
| 595 */ | 584 */ |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 identical(value, "<=") || | 666 identical(value, "<=") || |
| 678 identical(value, "<") || | 667 identical(value, "<") || |
| 679 identical(value, "&") || | 668 identical(value, "&") || |
| 680 identical(value, "^") || | 669 identical(value, "^") || |
| 681 identical(value, "|"); | 670 identical(value, "|"); |
| 682 } | 671 } |
| 683 | 672 |
| 684 bool isTernaryOperator(String value) => identical(value, "[]="); | 673 bool isTernaryOperator(String value) => identical(value, "[]="); |
| 685 | 674 |
| 686 bool isMinusOperator(String value) => identical(value, "-"); | 675 bool isMinusOperator(String value) => identical(value, "-"); |
| OLD | NEW |