| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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.abstract_scanner; | 5 library fasta.scanner.abstract_scanner; |
| 6 | 6 |
| 7 import 'dart:collection' show ListMixin; | 7 import 'dart:collection' show ListMixin; |
| 8 | 8 |
| 9 import 'dart:typed_data' show Uint16List, Uint32List; | 9 import 'dart:typed_data' show Uint16List, Uint32List; |
| 10 | 10 |
| 11 import '../../scanner/token.dart' show TokenType; | 11 import '../../scanner/token.dart' show TokenType; |
| 12 | 12 |
| 13 import '../scanner.dart' | 13 import '../scanner.dart' |
| 14 show ErrorToken, Keyword, Scanner, buildUnexpectedCharacterToken; | 14 show ErrorToken, Keyword, Scanner, buildUnexpectedCharacterToken; |
| 15 | 15 |
| 16 import 'error_token.dart' show UnterminatedToken; | 16 import 'error_token.dart' show UnterminatedToken; |
| 17 | 17 |
| 18 import 'keyword_state.dart' show KeywordState; | 18 import 'keyword_state.dart' show KeywordState; |
| 19 | 19 |
| 20 import 'precedence.dart'; | |
| 21 | |
| 22 import 'token.dart' | 20 import 'token.dart' |
| 23 show BeginGroupToken, CommentToken, DartDocToken, SymbolToken, Token; | 21 show BeginGroupToken, CommentToken, DartDocToken, SymbolToken, Token; |
| 24 | 22 |
| 25 import 'token_constants.dart'; | 23 import 'token_constants.dart'; |
| 26 | 24 |
| 27 import 'characters.dart'; | 25 import 'characters.dart'; |
| 28 | 26 |
| 29 abstract class AbstractScanner implements Scanner { | 27 abstract class AbstractScanner implements Scanner { |
| 30 final bool includeComments; | 28 final bool includeComments; |
| 31 | 29 |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 int nextLower = next | 0x20; | 264 int nextLower = next | 0x20; |
| 267 | 265 |
| 268 if ($a <= nextLower && nextLower <= $z) { | 266 if ($a <= nextLower && nextLower <= $z) { |
| 269 if (identical($r, next)) { | 267 if (identical($r, next)) { |
| 270 return tokenizeRawStringKeywordOrIdentifier(next); | 268 return tokenizeRawStringKeywordOrIdentifier(next); |
| 271 } | 269 } |
| 272 return tokenizeKeywordOrIdentifier(next, true); | 270 return tokenizeKeywordOrIdentifier(next, true); |
| 273 } | 271 } |
| 274 | 272 |
| 275 if (identical(next, $CLOSE_PAREN)) { | 273 if (identical(next, $CLOSE_PAREN)) { |
| 276 return appendEndGroup(CLOSE_PAREN_INFO, OPEN_PAREN_TOKEN); | 274 return appendEndGroup(TokenType.CLOSE_PAREN, OPEN_PAREN_TOKEN); |
| 277 } | 275 } |
| 278 | 276 |
| 279 if (identical(next, $OPEN_PAREN)) { | 277 if (identical(next, $OPEN_PAREN)) { |
| 280 appendBeginGroup(OPEN_PAREN_INFO); | 278 appendBeginGroup(TokenType.OPEN_PAREN); |
| 281 return advance(); | 279 return advance(); |
| 282 } | 280 } |
| 283 | 281 |
| 284 if (identical(next, $SEMICOLON)) { | 282 if (identical(next, $SEMICOLON)) { |
| 285 appendPrecedenceToken(SEMICOLON_INFO); | 283 appendPrecedenceToken(TokenType.SEMICOLON); |
| 286 // Type parameters and arguments cannot contain semicolon. | 284 // Type parameters and arguments cannot contain semicolon. |
| 287 discardOpenLt(); | 285 discardOpenLt(); |
| 288 return advance(); | 286 return advance(); |
| 289 } | 287 } |
| 290 | 288 |
| 291 if (identical(next, $PERIOD)) { | 289 if (identical(next, $PERIOD)) { |
| 292 return tokenizeDotsOrNumber(next); | 290 return tokenizeDotsOrNumber(next); |
| 293 } | 291 } |
| 294 | 292 |
| 295 if (identical(next, $COMMA)) { | 293 if (identical(next, $COMMA)) { |
| 296 appendPrecedenceToken(COMMA_INFO); | 294 appendPrecedenceToken(TokenType.COMMA); |
| 297 return advance(); | 295 return advance(); |
| 298 } | 296 } |
| 299 | 297 |
| 300 if (identical(next, $EQ)) { | 298 if (identical(next, $EQ)) { |
| 301 return tokenizeEquals(next); | 299 return tokenizeEquals(next); |
| 302 } | 300 } |
| 303 | 301 |
| 304 if (identical(next, $CLOSE_CURLY_BRACKET)) { | 302 if (identical(next, $CLOSE_CURLY_BRACKET)) { |
| 305 return appendEndGroup(CLOSE_CURLY_BRACKET_INFO, OPEN_CURLY_BRACKET_TOKEN); | 303 return appendEndGroup( |
| 304 TokenType.CLOSE_CURLY_BRACKET, OPEN_CURLY_BRACKET_TOKEN); |
| 306 } | 305 } |
| 307 | 306 |
| 308 if (identical(next, $SLASH)) { | 307 if (identical(next, $SLASH)) { |
| 309 return tokenizeSlashOrComment(next); | 308 return tokenizeSlashOrComment(next); |
| 310 } | 309 } |
| 311 | 310 |
| 312 if (identical(next, $OPEN_CURLY_BRACKET)) { | 311 if (identical(next, $OPEN_CURLY_BRACKET)) { |
| 313 appendBeginGroup(OPEN_CURLY_BRACKET_INFO); | 312 appendBeginGroup(TokenType.OPEN_CURLY_BRACKET); |
| 314 return advance(); | 313 return advance(); |
| 315 } | 314 } |
| 316 | 315 |
| 317 if (identical(next, $DQ) || identical(next, $SQ)) { | 316 if (identical(next, $DQ) || identical(next, $SQ)) { |
| 318 return tokenizeString(next, scanOffset, false); | 317 return tokenizeString(next, scanOffset, false); |
| 319 } | 318 } |
| 320 | 319 |
| 321 if (identical(next, $_)) { | 320 if (identical(next, $_)) { |
| 322 return tokenizeKeywordOrIdentifier(next, true); | 321 return tokenizeKeywordOrIdentifier(next, true); |
| 323 } | 322 } |
| 324 | 323 |
| 325 if (identical(next, $COLON)) { | 324 if (identical(next, $COLON)) { |
| 326 appendPrecedenceToken(COLON_INFO); | 325 appendPrecedenceToken(TokenType.COLON); |
| 327 return advance(); | 326 return advance(); |
| 328 } | 327 } |
| 329 | 328 |
| 330 if (identical(next, $LT)) { | 329 if (identical(next, $LT)) { |
| 331 return tokenizeLessThan(next); | 330 return tokenizeLessThan(next); |
| 332 } | 331 } |
| 333 | 332 |
| 334 if (identical(next, $GT)) { | 333 if (identical(next, $GT)) { |
| 335 return tokenizeGreaterThan(next); | 334 return tokenizeGreaterThan(next); |
| 336 } | 335 } |
| 337 | 336 |
| 338 if (identical(next, $BANG)) { | 337 if (identical(next, $BANG)) { |
| 339 return tokenizeExclamation(next); | 338 return tokenizeExclamation(next); |
| 340 } | 339 } |
| 341 | 340 |
| 342 if (identical(next, $OPEN_SQUARE_BRACKET)) { | 341 if (identical(next, $OPEN_SQUARE_BRACKET)) { |
| 343 return tokenizeOpenSquareBracket(next); | 342 return tokenizeOpenSquareBracket(next); |
| 344 } | 343 } |
| 345 | 344 |
| 346 if (identical(next, $CLOSE_SQUARE_BRACKET)) { | 345 if (identical(next, $CLOSE_SQUARE_BRACKET)) { |
| 347 return appendEndGroup( | 346 return appendEndGroup( |
| 348 CLOSE_SQUARE_BRACKET_INFO, OPEN_SQUARE_BRACKET_TOKEN); | 347 TokenType.CLOSE_SQUARE_BRACKET, OPEN_SQUARE_BRACKET_TOKEN); |
| 349 } | 348 } |
| 350 | 349 |
| 351 if (identical(next, $AT)) { | 350 if (identical(next, $AT)) { |
| 352 return tokenizeAt(next); | 351 return tokenizeAt(next); |
| 353 } | 352 } |
| 354 | 353 |
| 355 if (next >= $1 && next <= $9) { | 354 if (next >= $1 && next <= $9) { |
| 356 return tokenizeNumber(next); | 355 return tokenizeNumber(next); |
| 357 } | 356 } |
| 358 | 357 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 | 393 |
| 395 if (identical(next, $TILDE)) { | 394 if (identical(next, $TILDE)) { |
| 396 return tokenizeTilde(next); | 395 return tokenizeTilde(next); |
| 397 } | 396 } |
| 398 | 397 |
| 399 if (identical(next, $PERCENT)) { | 398 if (identical(next, $PERCENT)) { |
| 400 return tokenizePercent(next); | 399 return tokenizePercent(next); |
| 401 } | 400 } |
| 402 | 401 |
| 403 if (identical(next, $BACKPING)) { | 402 if (identical(next, $BACKPING)) { |
| 404 appendPrecedenceToken(BACKPING_INFO); | 403 appendPrecedenceToken(TokenType.BACKPING); |
| 405 return advance(); | 404 return advance(); |
| 406 } | 405 } |
| 407 | 406 |
| 408 if (identical(next, $BACKSLASH)) { | 407 if (identical(next, $BACKSLASH)) { |
| 409 appendPrecedenceToken(BACKSLASH_INFO); | 408 appendPrecedenceToken(TokenType.BACKSLASH); |
| 410 return advance(); | 409 return advance(); |
| 411 } | 410 } |
| 412 | 411 |
| 413 if (identical(next, $HASH)) { | 412 if (identical(next, $HASH)) { |
| 414 return tokenizeTag(next); | 413 return tokenizeTag(next); |
| 415 } | 414 } |
| 416 | 415 |
| 417 if (next < 0x1f) { | 416 if (next < 0x1f) { |
| 418 return unexpected(next); | 417 return unexpected(next); |
| 419 } | 418 } |
| 420 | 419 |
| 421 next = currentAsUnicode(next); | 420 next = currentAsUnicode(next); |
| 422 | 421 |
| 423 return unexpected(next); | 422 return unexpected(next); |
| 424 } | 423 } |
| 425 | 424 |
| 426 int tokenizeTag(int next) { | 425 int tokenizeTag(int next) { |
| 427 // # or #!.*[\n\r] | 426 // # or #!.*[\n\r] |
| 428 if (scanOffset == 0) { | 427 if (scanOffset == 0) { |
| 429 if (identical(peek(), $BANG)) { | 428 if (identical(peek(), $BANG)) { |
| 430 int start = scanOffset; | 429 int start = scanOffset; |
| 431 bool asciiOnly = true; | 430 bool asciiOnly = true; |
| 432 do { | 431 do { |
| 433 next = advance(); | 432 next = advance(); |
| 434 if (next > 127) asciiOnly = false; | 433 if (next > 127) asciiOnly = false; |
| 435 } while (!identical(next, $LF) && | 434 } while (!identical(next, $LF) && |
| 436 !identical(next, $CR) && | 435 !identical(next, $CR) && |
| 437 !identical(next, $EOF)); | 436 !identical(next, $EOF)); |
| 438 if (!asciiOnly) handleUnicode(start); | 437 if (!asciiOnly) handleUnicode(start); |
| 439 appendSubstringToken(SCRIPT_INFO, start, asciiOnly); | 438 appendSubstringToken(TokenType.SCRIPT_TAG, start, asciiOnly); |
| 440 return next; | 439 return next; |
| 441 } | 440 } |
| 442 } | 441 } |
| 443 appendPrecedenceToken(HASH_INFO); | 442 appendPrecedenceToken(TokenType.HASH); |
| 444 return advance(); | 443 return advance(); |
| 445 } | 444 } |
| 446 | 445 |
| 447 int tokenizeTilde(int next) { | 446 int tokenizeTilde(int next) { |
| 448 // ~ ~/ ~/= | 447 // ~ ~/ ~/= |
| 449 next = advance(); | 448 next = advance(); |
| 450 if (identical(next, $SLASH)) { | 449 if (identical(next, $SLASH)) { |
| 451 return select($EQ, TILDE_SLASH_EQ_INFO, TILDE_SLASH_INFO); | 450 return select($EQ, TokenType.TILDE_SLASH_EQ, TokenType.TILDE_SLASH); |
| 452 } else { | 451 } else { |
| 453 appendPrecedenceToken(TILDE_INFO); | 452 appendPrecedenceToken(TokenType.TILDE); |
| 454 return next; | 453 return next; |
| 455 } | 454 } |
| 456 } | 455 } |
| 457 | 456 |
| 458 int tokenizeOpenSquareBracket(int next) { | 457 int tokenizeOpenSquareBracket(int next) { |
| 459 // [ [] []= | 458 // [ [] []= |
| 460 next = advance(); | 459 next = advance(); |
| 461 if (identical(next, $CLOSE_SQUARE_BRACKET)) { | 460 if (identical(next, $CLOSE_SQUARE_BRACKET)) { |
| 462 return select($EQ, INDEX_EQ_INFO, INDEX_INFO); | 461 return select($EQ, TokenType.INDEX_EQ, TokenType.INDEX); |
| 463 } | 462 } |
| 464 appendBeginGroup(OPEN_SQUARE_BRACKET_INFO); | 463 appendBeginGroup(TokenType.OPEN_SQUARE_BRACKET); |
| 465 return next; | 464 return next; |
| 466 } | 465 } |
| 467 | 466 |
| 468 int tokenizeCaret(int next) { | 467 int tokenizeCaret(int next) { |
| 469 // ^ ^= | 468 // ^ ^= |
| 470 return select($EQ, CARET_EQ_INFO, CARET_INFO); | 469 return select($EQ, TokenType.CARET_EQ, TokenType.CARET); |
| 471 } | 470 } |
| 472 | 471 |
| 473 int tokenizeQuestion(int next) { | 472 int tokenizeQuestion(int next) { |
| 474 // ? ?. ?? ??= | 473 // ? ?. ?? ??= |
| 475 next = advance(); | 474 next = advance(); |
| 476 if (identical(next, $QUESTION)) { | 475 if (identical(next, $QUESTION)) { |
| 477 return select($EQ, QUESTION_QUESTION_EQ_INFO, QUESTION_QUESTION_INFO); | 476 return select( |
| 477 $EQ, TokenType.QUESTION_QUESTION_EQ, TokenType.QUESTION_QUESTION); |
| 478 } else if (identical(next, $PERIOD)) { | 478 } else if (identical(next, $PERIOD)) { |
| 479 appendPrecedenceToken(QUESTION_PERIOD_INFO); | 479 appendPrecedenceToken(TokenType.QUESTION_PERIOD); |
| 480 return advance(); | 480 return advance(); |
| 481 } else { | 481 } else { |
| 482 appendPrecedenceToken(QUESTION_INFO); | 482 appendPrecedenceToken(TokenType.QUESTION); |
| 483 return next; | 483 return next; |
| 484 } | 484 } |
| 485 } | 485 } |
| 486 | 486 |
| 487 int tokenizeBar(int next) { | 487 int tokenizeBar(int next) { |
| 488 // | || |= | 488 // | || |= |
| 489 next = advance(); | 489 next = advance(); |
| 490 if (identical(next, $BAR)) { | 490 if (identical(next, $BAR)) { |
| 491 appendPrecedenceToken(BAR_BAR_INFO); | 491 appendPrecedenceToken(TokenType.BAR_BAR); |
| 492 return advance(); | 492 return advance(); |
| 493 } else if (identical(next, $EQ)) { | 493 } else if (identical(next, $EQ)) { |
| 494 appendPrecedenceToken(BAR_EQ_INFO); | 494 appendPrecedenceToken(TokenType.BAR_EQ); |
| 495 return advance(); | 495 return advance(); |
| 496 } else { | 496 } else { |
| 497 appendPrecedenceToken(BAR_INFO); | 497 appendPrecedenceToken(TokenType.BAR); |
| 498 return next; | 498 return next; |
| 499 } | 499 } |
| 500 } | 500 } |
| 501 | 501 |
| 502 int tokenizeAmpersand(int next) { | 502 int tokenizeAmpersand(int next) { |
| 503 // && &= & | 503 // && &= & |
| 504 next = advance(); | 504 next = advance(); |
| 505 if (identical(next, $AMPERSAND)) { | 505 if (identical(next, $AMPERSAND)) { |
| 506 appendPrecedenceToken(AMPERSAND_AMPERSAND_INFO); | 506 appendPrecedenceToken(TokenType.AMPERSAND_AMPERSAND); |
| 507 return advance(); | 507 return advance(); |
| 508 } else if (identical(next, $EQ)) { | 508 } else if (identical(next, $EQ)) { |
| 509 appendPrecedenceToken(AMPERSAND_EQ_INFO); | 509 appendPrecedenceToken(TokenType.AMPERSAND_EQ); |
| 510 return advance(); | 510 return advance(); |
| 511 } else { | 511 } else { |
| 512 appendPrecedenceToken(AMPERSAND_INFO); | 512 appendPrecedenceToken(TokenType.AMPERSAND); |
| 513 return next; | 513 return next; |
| 514 } | 514 } |
| 515 } | 515 } |
| 516 | 516 |
| 517 int tokenizePercent(int next) { | 517 int tokenizePercent(int next) { |
| 518 // % %= | 518 // % %= |
| 519 return select($EQ, PERCENT_EQ_INFO, PERCENT_INFO); | 519 return select($EQ, TokenType.PERCENT_EQ, TokenType.PERCENT); |
| 520 } | 520 } |
| 521 | 521 |
| 522 int tokenizeMultiply(int next) { | 522 int tokenizeMultiply(int next) { |
| 523 // * *= | 523 // * *= |
| 524 return select($EQ, STAR_EQ_INFO, STAR_INFO); | 524 return select($EQ, TokenType.STAR_EQ, TokenType.STAR); |
| 525 } | 525 } |
| 526 | 526 |
| 527 int tokenizeMinus(int next) { | 527 int tokenizeMinus(int next) { |
| 528 // - -- -= | 528 // - -- -= |
| 529 next = advance(); | 529 next = advance(); |
| 530 if (identical(next, $MINUS)) { | 530 if (identical(next, $MINUS)) { |
| 531 appendPrecedenceToken(MINUS_MINUS_INFO); | 531 appendPrecedenceToken(TokenType.MINUS_MINUS); |
| 532 return advance(); | 532 return advance(); |
| 533 } else if (identical(next, $EQ)) { | 533 } else if (identical(next, $EQ)) { |
| 534 appendPrecedenceToken(MINUS_EQ_INFO); | 534 appendPrecedenceToken(TokenType.MINUS_EQ); |
| 535 return advance(); | 535 return advance(); |
| 536 } else { | 536 } else { |
| 537 appendPrecedenceToken(MINUS_INFO); | 537 appendPrecedenceToken(TokenType.MINUS); |
| 538 return next; | 538 return next; |
| 539 } | 539 } |
| 540 } | 540 } |
| 541 | 541 |
| 542 int tokenizePlus(int next) { | 542 int tokenizePlus(int next) { |
| 543 // + ++ += | 543 // + ++ += |
| 544 next = advance(); | 544 next = advance(); |
| 545 if (identical($PLUS, next)) { | 545 if (identical($PLUS, next)) { |
| 546 appendPrecedenceToken(PLUS_PLUS_INFO); | 546 appendPrecedenceToken(TokenType.PLUS_PLUS); |
| 547 return advance(); | 547 return advance(); |
| 548 } else if (identical($EQ, next)) { | 548 } else if (identical($EQ, next)) { |
| 549 appendPrecedenceToken(PLUS_EQ_INFO); | 549 appendPrecedenceToken(TokenType.PLUS_EQ); |
| 550 return advance(); | 550 return advance(); |
| 551 } else { | 551 } else { |
| 552 appendPrecedenceToken(PLUS_INFO); | 552 appendPrecedenceToken(TokenType.PLUS); |
| 553 return next; | 553 return next; |
| 554 } | 554 } |
| 555 } | 555 } |
| 556 | 556 |
| 557 int tokenizeExclamation(int next) { | 557 int tokenizeExclamation(int next) { |
| 558 // ! != | 558 // ! != |
| 559 // !== is kept for user-friendly error reporting. | 559 // !== is kept for user-friendly error reporting. |
| 560 | 560 |
| 561 next = advance(); | 561 next = advance(); |
| 562 if (identical(next, $EQ)) { | 562 if (identical(next, $EQ)) { |
| 563 return select($EQ, BANG_EQ_EQ_INFO, BANG_EQ_INFO); | 563 return select($EQ, TokenType.BANG_EQ_EQ, TokenType.BANG_EQ); |
| 564 } | 564 } |
| 565 appendPrecedenceToken(BANG_INFO); | 565 appendPrecedenceToken(TokenType.BANG); |
| 566 return next; | 566 return next; |
| 567 } | 567 } |
| 568 | 568 |
| 569 int tokenizeEquals(int next) { | 569 int tokenizeEquals(int next) { |
| 570 // = == => | 570 // = == => |
| 571 // === is kept for user-friendly error reporting. | 571 // === is kept for user-friendly error reporting. |
| 572 | 572 |
| 573 // Type parameters and arguments cannot contain any token that | 573 // Type parameters and arguments cannot contain any token that |
| 574 // starts with '='. | 574 // starts with '='. |
| 575 discardOpenLt(); | 575 discardOpenLt(); |
| 576 | 576 |
| 577 next = advance(); | 577 next = advance(); |
| 578 if (identical(next, $EQ)) { | 578 if (identical(next, $EQ)) { |
| 579 return select($EQ, EQ_EQ_EQ_INFO, EQ_EQ_INFO); | 579 return select($EQ, TokenType.EQ_EQ_EQ, TokenType.EQ_EQ); |
| 580 } else if (identical(next, $GT)) { | 580 } else if (identical(next, $GT)) { |
| 581 appendPrecedenceToken(FUNCTION_INFO); | 581 appendPrecedenceToken(TokenType.FUNCTION); |
| 582 return advance(); | 582 return advance(); |
| 583 } | 583 } |
| 584 appendPrecedenceToken(EQ_INFO); | 584 appendPrecedenceToken(TokenType.EQ); |
| 585 return next; | 585 return next; |
| 586 } | 586 } |
| 587 | 587 |
| 588 int tokenizeGreaterThan(int next) { | 588 int tokenizeGreaterThan(int next) { |
| 589 // > >= >> >>= | 589 // > >= >> >>= |
| 590 next = advance(); | 590 next = advance(); |
| 591 if (identical($EQ, next)) { | 591 if (identical($EQ, next)) { |
| 592 appendPrecedenceToken(GT_EQ_INFO); | 592 appendPrecedenceToken(TokenType.GT_EQ); |
| 593 return advance(); | 593 return advance(); |
| 594 } else if (identical($GT, next)) { | 594 } else if (identical($GT, next)) { |
| 595 next = advance(); | 595 next = advance(); |
| 596 if (identical($EQ, next)) { | 596 if (identical($EQ, next)) { |
| 597 appendPrecedenceToken(GT_GT_EQ_INFO); | 597 appendPrecedenceToken(TokenType.GT_GT_EQ); |
| 598 return advance(); | 598 return advance(); |
| 599 } else { | 599 } else { |
| 600 appendGtGt(GT_GT_INFO); | 600 appendGtGt(TokenType.GT_GT); |
| 601 return next; | 601 return next; |
| 602 } | 602 } |
| 603 } else { | 603 } else { |
| 604 appendGt(GT_INFO); | 604 appendGt(TokenType.GT); |
| 605 return next; | 605 return next; |
| 606 } | 606 } |
| 607 } | 607 } |
| 608 | 608 |
| 609 int tokenizeLessThan(int next) { | 609 int tokenizeLessThan(int next) { |
| 610 // < <= << <<= | 610 // < <= << <<= |
| 611 next = advance(); | 611 next = advance(); |
| 612 if (identical($EQ, next)) { | 612 if (identical($EQ, next)) { |
| 613 appendPrecedenceToken(LT_EQ_INFO); | 613 appendPrecedenceToken(TokenType.LT_EQ); |
| 614 return advance(); | 614 return advance(); |
| 615 } else if (identical($LT, next)) { | 615 } else if (identical($LT, next)) { |
| 616 return select($EQ, LT_LT_EQ_INFO, LT_LT_INFO); | 616 return select($EQ, TokenType.LT_LT_EQ, TokenType.LT_LT); |
| 617 } else { | 617 } else { |
| 618 appendBeginGroup(LT_INFO); | 618 appendBeginGroup(TokenType.LT); |
| 619 return next; | 619 return next; |
| 620 } | 620 } |
| 621 } | 621 } |
| 622 | 622 |
| 623 int tokenizeNumber(int next) { | 623 int tokenizeNumber(int next) { |
| 624 int start = scanOffset; | 624 int start = scanOffset; |
| 625 while (true) { | 625 while (true) { |
| 626 next = advance(); | 626 next = advance(); |
| 627 if ($0 <= next && next <= $9) { | 627 if ($0 <= next && next <= $9) { |
| 628 continue; | 628 continue; |
| 629 } else if (identical(next, $e) || identical(next, $E)) { | 629 } else if (identical(next, $e) || identical(next, $E)) { |
| 630 return tokenizeFractionPart(next, start); | 630 return tokenizeFractionPart(next, start); |
| 631 } else { | 631 } else { |
| 632 if (identical(next, $PERIOD)) { | 632 if (identical(next, $PERIOD)) { |
| 633 int nextnext = peek(); | 633 int nextnext = peek(); |
| 634 if ($0 <= nextnext && nextnext <= $9) { | 634 if ($0 <= nextnext && nextnext <= $9) { |
| 635 return tokenizeFractionPart(advance(), start); | 635 return tokenizeFractionPart(advance(), start); |
| 636 } | 636 } |
| 637 } | 637 } |
| 638 appendSubstringToken(INT_INFO, start, true); | 638 appendSubstringToken(TokenType.INT, start, true); |
| 639 return next; | 639 return next; |
| 640 } | 640 } |
| 641 } | 641 } |
| 642 } | 642 } |
| 643 | 643 |
| 644 int tokenizeHexOrNumber(int next) { | 644 int tokenizeHexOrNumber(int next) { |
| 645 int x = peek(); | 645 int x = peek(); |
| 646 if (identical(x, $x) || identical(x, $X)) { | 646 if (identical(x, $x) || identical(x, $X)) { |
| 647 return tokenizeHex(next); | 647 return tokenizeHex(next); |
| 648 } | 648 } |
| 649 return tokenizeNumber(next); | 649 return tokenizeNumber(next); |
| 650 } | 650 } |
| 651 | 651 |
| 652 int tokenizeHex(int next) { | 652 int tokenizeHex(int next) { |
| 653 int start = scanOffset; | 653 int start = scanOffset; |
| 654 next = advance(); // Advance past the $x or $X. | 654 next = advance(); // Advance past the $x or $X. |
| 655 bool hasDigits = false; | 655 bool hasDigits = false; |
| 656 while (true) { | 656 while (true) { |
| 657 next = advance(); | 657 next = advance(); |
| 658 if (($0 <= next && next <= $9) || | 658 if (($0 <= next && next <= $9) || |
| 659 ($A <= next && next <= $F) || | 659 ($A <= next && next <= $F) || |
| 660 ($a <= next && next <= $f)) { | 660 ($a <= next && next <= $f)) { |
| 661 hasDigits = true; | 661 hasDigits = true; |
| 662 } else { | 662 } else { |
| 663 if (!hasDigits) { | 663 if (!hasDigits) { |
| 664 unterminated('0x', shouldAdvance: false); | 664 unterminated('0x', shouldAdvance: false); |
| 665 return next; | 665 return next; |
| 666 } | 666 } |
| 667 appendSubstringToken(HEXADECIMAL_INFO, start, true); | 667 appendSubstringToken(TokenType.HEXADECIMAL, start, true); |
| 668 return next; | 668 return next; |
| 669 } | 669 } |
| 670 } | 670 } |
| 671 } | 671 } |
| 672 | 672 |
| 673 int tokenizeDotsOrNumber(int next) { | 673 int tokenizeDotsOrNumber(int next) { |
| 674 int start = scanOffset; | 674 int start = scanOffset; |
| 675 next = advance(); | 675 next = advance(); |
| 676 if (($0 <= next && next <= $9)) { | 676 if (($0 <= next && next <= $9)) { |
| 677 return tokenizeFractionPart(next, start); | 677 return tokenizeFractionPart(next, start); |
| 678 } else if (identical($PERIOD, next)) { | 678 } else if (identical($PERIOD, next)) { |
| 679 return select($PERIOD, PERIOD_PERIOD_PERIOD_INFO, PERIOD_PERIOD_INFO); | 679 return select( |
| 680 $PERIOD, TokenType.PERIOD_PERIOD_PERIOD, TokenType.PERIOD_PERIOD); |
| 680 } else { | 681 } else { |
| 681 appendPrecedenceToken(PERIOD_INFO); | 682 appendPrecedenceToken(TokenType.PERIOD); |
| 682 return next; | 683 return next; |
| 683 } | 684 } |
| 684 } | 685 } |
| 685 | 686 |
| 686 int tokenizeFractionPart(int next, int start) { | 687 int tokenizeFractionPart(int next, int start) { |
| 687 bool done = false; | 688 bool done = false; |
| 688 bool hasDigit = false; | 689 bool hasDigit = false; |
| 689 LOOP: | 690 LOOP: |
| 690 while (!done) { | 691 while (!done) { |
| 691 if ($0 <= next && next <= $9) { | 692 if ($0 <= next && next <= $9) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 713 done = true; | 714 done = true; |
| 714 continue LOOP; | 715 continue LOOP; |
| 715 } else { | 716 } else { |
| 716 done = true; | 717 done = true; |
| 717 continue LOOP; | 718 continue LOOP; |
| 718 } | 719 } |
| 719 next = advance(); | 720 next = advance(); |
| 720 } | 721 } |
| 721 if (!hasDigit) { | 722 if (!hasDigit) { |
| 722 // Reduce offset, we already advanced to the token past the period. | 723 // Reduce offset, we already advanced to the token past the period. |
| 723 appendSubstringToken(INT_INFO, start, true, -1); | 724 appendSubstringToken(TokenType.INT, start, true, -1); |
| 724 | 725 |
| 725 // TODO(ahe): Wrong offset for the period. Cannot call beginToken because | 726 // TODO(ahe): Wrong offset for the period. Cannot call beginToken because |
| 726 // the scanner already advanced past the period. | 727 // the scanner already advanced past the period. |
| 727 if (identical($PERIOD, next)) { | 728 if (identical($PERIOD, next)) { |
| 728 return select($PERIOD, PERIOD_PERIOD_PERIOD_INFO, PERIOD_PERIOD_INFO); | 729 return select( |
| 730 $PERIOD, TokenType.PERIOD_PERIOD_PERIOD, TokenType.PERIOD_PERIOD); |
| 729 } | 731 } |
| 730 appendPrecedenceToken(PERIOD_INFO); | 732 appendPrecedenceToken(TokenType.PERIOD); |
| 731 return next; | 733 return next; |
| 732 } | 734 } |
| 733 appendSubstringToken(DOUBLE_INFO, start, true); | 735 appendSubstringToken(TokenType.DOUBLE, start, true); |
| 734 return next; | 736 return next; |
| 735 } | 737 } |
| 736 | 738 |
| 737 int tokenizeSlashOrComment(int next) { | 739 int tokenizeSlashOrComment(int next) { |
| 738 int start = scanOffset; | 740 int start = scanOffset; |
| 739 next = advance(); | 741 next = advance(); |
| 740 if (identical($STAR, next)) { | 742 if (identical($STAR, next)) { |
| 741 return tokenizeMultiLineComment(next, start); | 743 return tokenizeMultiLineComment(next, start); |
| 742 } else if (identical($SLASH, next)) { | 744 } else if (identical($SLASH, next)) { |
| 743 return tokenizeSingleLineComment(next, start); | 745 return tokenizeSingleLineComment(next, start); |
| 744 } else if (identical($EQ, next)) { | 746 } else if (identical($EQ, next)) { |
| 745 appendPrecedenceToken(SLASH_EQ_INFO); | 747 appendPrecedenceToken(TokenType.SLASH_EQ); |
| 746 return advance(); | 748 return advance(); |
| 747 } else { | 749 } else { |
| 748 appendPrecedenceToken(SLASH_INFO); | 750 appendPrecedenceToken(TokenType.SLASH); |
| 749 return next; | 751 return next; |
| 750 } | 752 } |
| 751 } | 753 } |
| 752 | 754 |
| 753 int tokenizeSingleLineComment(int next, int start) { | 755 int tokenizeSingleLineComment(int next, int start) { |
| 754 bool asciiOnly = true; | 756 bool asciiOnly = true; |
| 755 bool dartdoc = identical($SLASH, peek()); | 757 bool dartdoc = identical($SLASH, peek()); |
| 756 while (true) { | 758 while (true) { |
| 757 next = advance(); | 759 next = advance(); |
| 758 if (next > 127) asciiOnly = false; | 760 if (next > 127) asciiOnly = false; |
| 759 if (identical($LF, next) || | 761 if (identical($LF, next) || |
| 760 identical($CR, next) || | 762 identical($CR, next) || |
| 761 identical($EOF, next)) { | 763 identical($EOF, next)) { |
| 762 if (!asciiOnly) handleUnicode(start); | 764 if (!asciiOnly) handleUnicode(start); |
| 763 if (dartdoc) { | 765 if (dartdoc) { |
| 764 appendDartDoc(start, SINGLE_LINE_COMMENT_INFO, asciiOnly); | 766 appendDartDoc(start, TokenType.SINGLE_LINE_COMMENT, asciiOnly); |
| 765 } else { | 767 } else { |
| 766 appendComment(start, SINGLE_LINE_COMMENT_INFO, asciiOnly); | 768 appendComment(start, TokenType.SINGLE_LINE_COMMENT, asciiOnly); |
| 767 } | 769 } |
| 768 return next; | 770 return next; |
| 769 } | 771 } |
| 770 } | 772 } |
| 771 } | 773 } |
| 772 | 774 |
| 773 int tokenizeMultiLineComment(int next, int start) { | 775 int tokenizeMultiLineComment(int next, int start) { |
| 774 bool asciiOnlyComment = true; // Track if the entire comment is ASCII. | 776 bool asciiOnlyComment = true; // Track if the entire comment is ASCII. |
| 775 bool asciiOnlyLines = true; // Track ASCII since the last handleUnicode. | 777 bool asciiOnlyLines = true; // Track ASCII since the last handleUnicode. |
| 776 int unicodeStart = start; | 778 int unicodeStart = start; |
| 777 int nesting = 1; | 779 int nesting = 1; |
| 778 next = advance(); | 780 next = advance(); |
| 779 bool dartdoc = identical($STAR, next); | 781 bool dartdoc = identical($STAR, next); |
| 780 while (true) { | 782 while (true) { |
| 781 if (identical($EOF, next)) { | 783 if (identical($EOF, next)) { |
| 782 if (!asciiOnlyLines) handleUnicode(unicodeStart); | 784 if (!asciiOnlyLines) handleUnicode(unicodeStart); |
| 783 unterminated('/*'); | 785 unterminated('/*'); |
| 784 break; | 786 break; |
| 785 } else if (identical($STAR, next)) { | 787 } else if (identical($STAR, next)) { |
| 786 next = advance(); | 788 next = advance(); |
| 787 if (identical($SLASH, next)) { | 789 if (identical($SLASH, next)) { |
| 788 --nesting; | 790 --nesting; |
| 789 if (0 == nesting) { | 791 if (0 == nesting) { |
| 790 if (!asciiOnlyLines) handleUnicode(unicodeStart); | 792 if (!asciiOnlyLines) handleUnicode(unicodeStart); |
| 791 next = advance(); | 793 next = advance(); |
| 792 if (dartdoc) { | 794 if (dartdoc) { |
| 793 appendDartDoc(start, MULTI_LINE_COMMENT_INFO, asciiOnlyComment); | 795 appendDartDoc( |
| 796 start, TokenType.MULTI_LINE_COMMENT, asciiOnlyComment); |
| 794 } else { | 797 } else { |
| 795 appendComment(start, MULTI_LINE_COMMENT_INFO, asciiOnlyComment); | 798 appendComment( |
| 799 start, TokenType.MULTI_LINE_COMMENT, asciiOnlyComment); |
| 796 } | 800 } |
| 797 break; | 801 break; |
| 798 } else { | 802 } else { |
| 799 next = advance(); | 803 next = advance(); |
| 800 } | 804 } |
| 801 } | 805 } |
| 802 } else if (identical($SLASH, next)) { | 806 } else if (identical($SLASH, next)) { |
| 803 next = advance(); | 807 next = advance(); |
| 804 if (identical($STAR, next)) { | 808 if (identical($STAR, next)) { |
| 805 next = advance(); | 809 next = advance(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 829 if (!includeComments) return; | 833 if (!includeComments) return; |
| 830 CommentToken newComment = createCommentToken(info, start, asciiOnly); | 834 CommentToken newComment = createCommentToken(info, start, asciiOnly); |
| 831 if (scanGenericMethodComments) { | 835 if (scanGenericMethodComments) { |
| 832 String value = newComment.lexeme; | 836 String value = newComment.lexeme; |
| 833 int length = value.length; | 837 int length = value.length; |
| 834 if (length > 5 && | 838 if (length > 5 && |
| 835 value.codeUnitAt(0) == $SLASH && | 839 value.codeUnitAt(0) == $SLASH && |
| 836 value.codeUnitAt(1) == $STAR && | 840 value.codeUnitAt(1) == $STAR && |
| 837 value.codeUnitAt(2) == $EQ) { | 841 value.codeUnitAt(2) == $EQ) { |
| 838 newComment = new CommentToken.fromString( | 842 newComment = new CommentToken.fromString( |
| 839 GENERIC_METHOD_TYPE_ASSIGN, value, start); | 843 TokenType.GENERIC_METHOD_TYPE_ASSIGN, value, start); |
| 840 } else if (length > 6 && | 844 } else if (length > 6 && |
| 841 value.codeUnitAt(0) == $SLASH && | 845 value.codeUnitAt(0) == $SLASH && |
| 842 value.codeUnitAt(1) == $STAR && | 846 value.codeUnitAt(1) == $STAR && |
| 843 value.codeUnitAt(2) == $LT && | 847 value.codeUnitAt(2) == $LT && |
| 844 value.codeUnitAt(length - 1) == $SLASH && | 848 value.codeUnitAt(length - 1) == $SLASH && |
| 845 value.codeUnitAt(length - 2) == $STAR && | 849 value.codeUnitAt(length - 2) == $STAR && |
| 846 value.codeUnitAt(length - 3) == $GT) { | 850 value.codeUnitAt(length - 3) == $GT) { |
| 847 newComment = | 851 newComment = new CommentToken.fromString( |
| 848 new CommentToken.fromString(GENERIC_METHOD_TYPE_LIST, value, start); | 852 TokenType.GENERIC_METHOD_TYPE_LIST, value, start); |
| 849 } | 853 } |
| 850 } | 854 } |
| 851 _appendToCommentStream(newComment); | 855 _appendToCommentStream(newComment); |
| 852 } | 856 } |
| 853 | 857 |
| 854 void appendDartDoc(int start, TokenType info, bool asciiOnly) { | 858 void appendDartDoc(int start, TokenType info, bool asciiOnly) { |
| 855 if (!includeComments) return; | 859 if (!includeComments) return; |
| 856 Token newComment = createDartDocToken(info, start, asciiOnly); | 860 Token newComment = createDartDocToken(info, start, asciiOnly); |
| 857 _appendToCommentStream(newComment); | 861 _appendToCommentStream(newComment); |
| 858 } | 862 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 ($A <= next && next <= $Z) || | 941 ($A <= next && next <= $Z) || |
| 938 ($0 <= next && next <= $9) || | 942 ($0 <= next && next <= $9) || |
| 939 identical(next, $_) || | 943 identical(next, $_) || |
| 940 (identical(next, $$) && allowDollar)) { | 944 (identical(next, $$) && allowDollar)) { |
| 941 next = advance(); | 945 next = advance(); |
| 942 } else { | 946 } else { |
| 943 // Identifier ends here. | 947 // Identifier ends here. |
| 944 if (start == scanOffset) { | 948 if (start == scanOffset) { |
| 945 return unexpected(next); | 949 return unexpected(next); |
| 946 } else { | 950 } else { |
| 947 appendSubstringToken(IDENTIFIER_INFO, start, true); | 951 appendSubstringToken(TokenType.IDENTIFIER, start, true); |
| 948 } | 952 } |
| 949 break; | 953 break; |
| 950 } | 954 } |
| 951 } | 955 } |
| 952 return next; | 956 return next; |
| 953 } | 957 } |
| 954 | 958 |
| 955 int tokenizeAt(int next) { | 959 int tokenizeAt(int next) { |
| 956 appendPrecedenceToken(AT_INFO); | 960 appendPrecedenceToken(TokenType.AT); |
| 957 return advance(); | 961 return advance(); |
| 958 } | 962 } |
| 959 | 963 |
| 960 int tokenizeString(int next, int start, bool raw) { | 964 int tokenizeString(int next, int start, bool raw) { |
| 961 int quoteChar = next; | 965 int quoteChar = next; |
| 962 next = advance(); | 966 next = advance(); |
| 963 if (identical(quoteChar, next)) { | 967 if (identical(quoteChar, next)) { |
| 964 next = advance(); | 968 next = advance(); |
| 965 if (identical(quoteChar, next)) { | 969 if (identical(quoteChar, next)) { |
| 966 // Multiline string. | 970 // Multiline string. |
| 967 return tokenizeMultiLineString(quoteChar, start, raw); | 971 return tokenizeMultiLineString(quoteChar, start, raw); |
| 968 } else { | 972 } else { |
| 969 // Empty string. | 973 // Empty string. |
| 970 appendSubstringToken(STRING_INFO, start, true); | 974 appendSubstringToken(TokenType.STRING, start, true); |
| 971 return next; | 975 return next; |
| 972 } | 976 } |
| 973 } | 977 } |
| 974 if (raw) { | 978 if (raw) { |
| 975 return tokenizeSingleLineRawString(next, quoteChar, start); | 979 return tokenizeSingleLineRawString(next, quoteChar, start); |
| 976 } else { | 980 } else { |
| 977 return tokenizeSingleLineString(next, quoteChar, start); | 981 return tokenizeSingleLineString(next, quoteChar, start); |
| 978 } | 982 } |
| 979 } | 983 } |
| 980 | 984 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1008 identical(next, $EOF))) { | 1012 identical(next, $EOF))) { |
| 1009 if (!asciiOnly) handleUnicode(start); | 1013 if (!asciiOnly) handleUnicode(start); |
| 1010 return unterminatedString(quoteChar); | 1014 return unterminatedString(quoteChar); |
| 1011 } | 1015 } |
| 1012 if (next > 127) asciiOnly = false; | 1016 if (next > 127) asciiOnly = false; |
| 1013 next = advance(); | 1017 next = advance(); |
| 1014 } | 1018 } |
| 1015 if (!asciiOnly) handleUnicode(start); | 1019 if (!asciiOnly) handleUnicode(start); |
| 1016 // Advance past the quote character. | 1020 // Advance past the quote character. |
| 1017 next = advance(); | 1021 next = advance(); |
| 1018 appendSubstringToken(STRING_INFO, start, asciiOnly); | 1022 appendSubstringToken(TokenType.STRING, start, asciiOnly); |
| 1019 return next; | 1023 return next; |
| 1020 } | 1024 } |
| 1021 | 1025 |
| 1022 int tokenizeStringInterpolation(int start, bool asciiOnly) { | 1026 int tokenizeStringInterpolation(int start, bool asciiOnly) { |
| 1023 appendSubstringToken(STRING_INFO, start, asciiOnly); | 1027 appendSubstringToken(TokenType.STRING, start, asciiOnly); |
| 1024 beginToken(); // $ starts here. | 1028 beginToken(); // $ starts here. |
| 1025 int next = advance(); | 1029 int next = advance(); |
| 1026 if (identical(next, $OPEN_CURLY_BRACKET)) { | 1030 if (identical(next, $OPEN_CURLY_BRACKET)) { |
| 1027 return tokenizeInterpolatedExpression(next); | 1031 return tokenizeInterpolatedExpression(next); |
| 1028 } else { | 1032 } else { |
| 1029 return tokenizeInterpolatedIdentifier(next); | 1033 return tokenizeInterpolatedIdentifier(next); |
| 1030 } | 1034 } |
| 1031 } | 1035 } |
| 1032 | 1036 |
| 1033 int tokenizeInterpolatedExpression(int next) { | 1037 int tokenizeInterpolatedExpression(int next) { |
| 1034 appendBeginGroup(STRING_INTERPOLATION_INFO); | 1038 appendBeginGroup(TokenType.STRING_INTERPOLATION_EXPRESSION); |
| 1035 beginToken(); // The expression starts here. | 1039 beginToken(); // The expression starts here. |
| 1036 next = advance(); // Move past the curly bracket. | 1040 next = advance(); // Move past the curly bracket. |
| 1037 while (!identical(next, $EOF) && !identical(next, $STX)) { | 1041 while (!identical(next, $EOF) && !identical(next, $STX)) { |
| 1038 next = bigSwitch(next); | 1042 next = bigSwitch(next); |
| 1039 } | 1043 } |
| 1040 if (identical(next, $EOF)) return next; | 1044 if (identical(next, $EOF)) return next; |
| 1041 next = advance(); // Move past the $STX. | 1045 next = advance(); // Move past the $STX. |
| 1042 beginToken(); // The string interpolation suffix starts here. | 1046 beginToken(); // The string interpolation suffix starts here. |
| 1043 return next; | 1047 return next; |
| 1044 } | 1048 } |
| 1045 | 1049 |
| 1046 int tokenizeInterpolatedIdentifier(int next) { | 1050 int tokenizeInterpolatedIdentifier(int next) { |
| 1047 appendPrecedenceToken(STRING_INTERPOLATION_IDENTIFIER_INFO); | 1051 appendPrecedenceToken(TokenType.STRING_INTERPOLATION_IDENTIFIER); |
| 1048 | 1052 |
| 1049 if ($a <= next && next <= $z || | 1053 if ($a <= next && next <= $z || |
| 1050 $A <= next && next <= $Z || | 1054 $A <= next && next <= $Z || |
| 1051 identical(next, $_)) { | 1055 identical(next, $_)) { |
| 1052 beginToken(); // The identifier starts here. | 1056 beginToken(); // The identifier starts here. |
| 1053 next = tokenizeKeywordOrIdentifier(next, false); | 1057 next = tokenizeKeywordOrIdentifier(next, false); |
| 1054 } else { | 1058 } else { |
| 1055 unterminated(r'$', shouldAdvance: false); | 1059 unterminated(r'$', shouldAdvance: false); |
| 1056 } | 1060 } |
| 1057 beginToken(); // The string interpolation suffix starts here. | 1061 beginToken(); // The string interpolation suffix starts here. |
| 1058 return next; | 1062 return next; |
| 1059 } | 1063 } |
| 1060 | 1064 |
| 1061 int tokenizeSingleLineRawString(int next, int quoteChar, int start) { | 1065 int tokenizeSingleLineRawString(int next, int quoteChar, int start) { |
| 1062 bool asciiOnly = true; | 1066 bool asciiOnly = true; |
| 1063 while (next != $EOF) { | 1067 while (next != $EOF) { |
| 1064 if (identical(next, quoteChar)) { | 1068 if (identical(next, quoteChar)) { |
| 1065 if (!asciiOnly) handleUnicode(start); | 1069 if (!asciiOnly) handleUnicode(start); |
| 1066 next = advance(); | 1070 next = advance(); |
| 1067 appendSubstringToken(STRING_INFO, start, asciiOnly); | 1071 appendSubstringToken(TokenType.STRING, start, asciiOnly); |
| 1068 return next; | 1072 return next; |
| 1069 } else if (identical(next, $LF) || identical(next, $CR)) { | 1073 } else if (identical(next, $LF) || identical(next, $CR)) { |
| 1070 if (!asciiOnly) handleUnicode(start); | 1074 if (!asciiOnly) handleUnicode(start); |
| 1071 return unterminatedRawString(quoteChar); | 1075 return unterminatedRawString(quoteChar); |
| 1072 } else if (next > 127) { | 1076 } else if (next > 127) { |
| 1073 asciiOnly = false; | 1077 asciiOnly = false; |
| 1074 } | 1078 } |
| 1075 next = advance(); | 1079 next = advance(); |
| 1076 } | 1080 } |
| 1077 if (!asciiOnly) handleUnicode(start); | 1081 if (!asciiOnly) handleUnicode(start); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1100 } | 1104 } |
| 1101 next = advance(); | 1105 next = advance(); |
| 1102 if (identical(next, $EOF)) break outer; | 1106 if (identical(next, $EOF)) break outer; |
| 1103 } | 1107 } |
| 1104 next = advance(); | 1108 next = advance(); |
| 1105 if (identical(next, quoteChar)) { | 1109 if (identical(next, quoteChar)) { |
| 1106 next = advance(); | 1110 next = advance(); |
| 1107 if (identical(next, quoteChar)) { | 1111 if (identical(next, quoteChar)) { |
| 1108 if (!asciiOnlyLine) handleUnicode(unicodeStart); | 1112 if (!asciiOnlyLine) handleUnicode(unicodeStart); |
| 1109 next = advance(); | 1113 next = advance(); |
| 1110 appendSubstringToken(STRING_INFO, start, asciiOnlyString); | 1114 appendSubstringToken(TokenType.STRING, start, asciiOnlyString); |
| 1111 return next; | 1115 return next; |
| 1112 } | 1116 } |
| 1113 } | 1117 } |
| 1114 } | 1118 } |
| 1115 if (!asciiOnlyLine) handleUnicode(unicodeStart); | 1119 if (!asciiOnlyLine) handleUnicode(unicodeStart); |
| 1116 return unterminatedRawMultiLineString(quoteChar); | 1120 return unterminatedRawMultiLineString(quoteChar); |
| 1117 } | 1121 } |
| 1118 | 1122 |
| 1119 int tokenizeMultiLineString(int quoteChar, int start, bool raw) { | 1123 int tokenizeMultiLineString(int quoteChar, int start, bool raw) { |
| 1120 if (raw) return tokenizeMultiLineRawString(quoteChar, start); | 1124 if (raw) return tokenizeMultiLineRawString(quoteChar, start); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1132 asciiOnlyLine = true; | 1136 asciiOnlyLine = true; |
| 1133 continue; | 1137 continue; |
| 1134 } | 1138 } |
| 1135 if (identical(next, quoteChar)) { | 1139 if (identical(next, quoteChar)) { |
| 1136 next = advance(); | 1140 next = advance(); |
| 1137 if (identical(next, quoteChar)) { | 1141 if (identical(next, quoteChar)) { |
| 1138 next = advance(); | 1142 next = advance(); |
| 1139 if (identical(next, quoteChar)) { | 1143 if (identical(next, quoteChar)) { |
| 1140 if (!asciiOnlyLine) handleUnicode(unicodeStart); | 1144 if (!asciiOnlyLine) handleUnicode(unicodeStart); |
| 1141 next = advance(); | 1145 next = advance(); |
| 1142 appendSubstringToken(STRING_INFO, start, asciiOnlyString); | 1146 appendSubstringToken(TokenType.STRING, start, asciiOnlyString); |
| 1143 return next; | 1147 return next; |
| 1144 } | 1148 } |
| 1145 } | 1149 } |
| 1146 continue; | 1150 continue; |
| 1147 } | 1151 } |
| 1148 if (identical(next, $BACKSLASH)) { | 1152 if (identical(next, $BACKSLASH)) { |
| 1149 next = advance(); | 1153 next = advance(); |
| 1150 if (identical(next, $EOF)) break; | 1154 if (identical(next, $EOF)) break; |
| 1151 } | 1155 } |
| 1152 if (identical(next, $LF)) { | 1156 if (identical(next, $LF)) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 if (shouldAdvance) { | 1204 if (shouldAdvance) { |
| 1201 return advance(); // Ensure progress. | 1205 return advance(); // Ensure progress. |
| 1202 } else { | 1206 } else { |
| 1203 return -1; | 1207 return -1; |
| 1204 } | 1208 } |
| 1205 } | 1209 } |
| 1206 } | 1210 } |
| 1207 | 1211 |
| 1208 TokenType closeBraceInfoFor(BeginGroupToken begin) { | 1212 TokenType closeBraceInfoFor(BeginGroupToken begin) { |
| 1209 return const { | 1213 return const { |
| 1210 '(': CLOSE_PAREN_INFO, | 1214 '(': TokenType.CLOSE_PAREN, |
| 1211 '[': CLOSE_SQUARE_BRACKET_INFO, | 1215 '[': TokenType.CLOSE_SQUARE_BRACKET, |
| 1212 '{': CLOSE_CURLY_BRACKET_INFO, | 1216 '{': TokenType.CLOSE_CURLY_BRACKET, |
| 1213 '<': GT_INFO, | 1217 '<': TokenType.GT, |
| 1214 r'${': CLOSE_CURLY_BRACKET_INFO, | 1218 r'${': TokenType.CLOSE_CURLY_BRACKET, |
| 1215 }[begin.lexeme]; | 1219 }[begin.lexeme]; |
| 1216 } | 1220 } |
| 1217 | 1221 |
| 1218 class LineStarts extends Object with ListMixin<int> { | 1222 class LineStarts extends Object with ListMixin<int> { |
| 1219 List<int> array; | 1223 List<int> array; |
| 1220 int arrayLength = 0; | 1224 int arrayLength = 0; |
| 1221 | 1225 |
| 1222 LineStarts(int numberOfBytesHint) { | 1226 LineStarts(int numberOfBytesHint) { |
| 1223 // Let's assume the average Dart file is 300 bytes. | 1227 // Let's assume the average Dart file is 300 bytes. |
| 1224 if (numberOfBytesHint == null) numberOfBytesHint = 300; | 1228 if (numberOfBytesHint == null) numberOfBytesHint = 300; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1284 switchToUint32(newLength); | 1288 switchToUint32(newLength); |
| 1285 } | 1289 } |
| 1286 } | 1290 } |
| 1287 | 1291 |
| 1288 void switchToUint32(int newLength) { | 1292 void switchToUint32(int newLength) { |
| 1289 final newArray = new Uint32List(newLength); | 1293 final newArray = new Uint32List(newLength); |
| 1290 newArray.setRange(0, arrayLength, array); | 1294 newArray.setRange(0, arrayLength, array); |
| 1291 array = newArray; | 1295 array = newArray; |
| 1292 } | 1296 } |
| 1293 } | 1297 } |
| OLD | NEW |