| OLD | NEW |
| 1 // This code was auto-generated, is not intended to be edited, and is subject to | 1 // This code was auto-generated, is not intended to be edited, and is subject to |
| 2 // significant change. Please see the README file for more information. | 2 // significant change. Please see the README file for more information. |
| 3 library engine.scanner; | 3 library engine.scanner; |
| 4 import 'dart:collection'; | 4 import 'dart:collection'; |
| 5 import 'java_core.dart'; | 5 import 'java_core.dart'; |
| 6 import 'java_engine.dart'; | 6 import 'java_engine.dart'; |
| 7 import 'source.dart'; | 7 import 'source.dart'; |
| 8 import 'error.dart'; | 8 import 'error.dart'; |
| 9 import 'instrumentation.dart'; | 9 import 'instrumentation.dart'; |
| 10 /** | 10 /** |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 ScannerErrorCode.con2(String name, int ordinal, String message, String correct
ion) : super(name, ordinal) { | 181 ScannerErrorCode.con2(String name, int ordinal, String message, String correct
ion) : super(name, ordinal) { |
| 182 this._message = message; | 182 this._message = message; |
| 183 this.correction10 = correction; | 183 this.correction10 = correction; |
| 184 } | 184 } |
| 185 String get correction => correction10; | 185 String get correction => correction10; |
| 186 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; | 186 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; |
| 187 String get message => _message; | 187 String get message => _message; |
| 188 ErrorType get type => ErrorType.SYNTACTIC_ERROR; | 188 ErrorType get type => ErrorType.SYNTACTIC_ERROR; |
| 189 } | 189 } |
| 190 /** | 190 /** |
| 191 * Instances of the class `SubSequenceReader` implement a [CharacterReader] that
reads |
| 192 * characters from a character sequence, but adds a delta when reporting the cur
rent character |
| 193 * offset so that the character sequence can be a subsequence from a larger sequ
ence. |
| 194 */ |
| 195 class SubSequenceReader extends CharSequenceReader { |
| 196 |
| 197 /** |
| 198 * The offset from the beginning of the file to the beginning of the source be
ing scanned. |
| 199 */ |
| 200 int _offsetDelta = 0; |
| 201 |
| 202 /** |
| 203 * Initialize a newly created reader to read the characters in the given seque
nce. |
| 204 * |
| 205 * @param sequence the sequence from which characters will be read |
| 206 * @param offsetDelta the offset from the beginning of the file to the beginni
ng of the source |
| 207 * being scanned |
| 208 */ |
| 209 SubSequenceReader(CharSequence sequence, int offsetDelta) : super(sequence) { |
| 210 this._offsetDelta = offsetDelta; |
| 211 } |
| 212 int get offset => _offsetDelta + super.offset; |
| 213 String getString(int start, int endDelta) => super.getString(start - _offsetDe
lta, endDelta); |
| 214 } |
| 215 /** |
| 191 * Instances of the class `TokenWithComment` represent a string token that is pr
eceded by | 216 * Instances of the class `TokenWithComment` represent a string token that is pr
eceded by |
| 192 * comments. | 217 * comments. |
| 193 * | 218 * |
| 194 * @coverage dart.engine.parser | 219 * @coverage dart.engine.parser |
| 195 */ | 220 */ |
| 196 class StringTokenWithComment extends StringToken { | 221 class StringTokenWithComment extends StringToken { |
| 197 | 222 |
| 198 /** | 223 /** |
| 199 * The first comment in the list of comments that precede this token. | 224 * The first comment in the list of comments that precede this token. |
| 200 */ | 225 */ |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 * | 385 * |
| 361 * @param syntax the lexeme for the keyword | 386 * @param syntax the lexeme for the keyword |
| 362 * @param isPseudoKeyword `true` if this keyword is a pseudo-keyword | 387 * @param isPseudoKeyword `true` if this keyword is a pseudo-keyword |
| 363 */ | 388 */ |
| 364 Keyword.con2(String name, int ordinal, String syntax, bool isPseudoKeyword) :
super(name, ordinal) { | 389 Keyword.con2(String name, int ordinal, String syntax, bool isPseudoKeyword) :
super(name, ordinal) { |
| 365 this.syntax = syntax; | 390 this.syntax = syntax; |
| 366 this.isPseudoKeyword = isPseudoKeyword; | 391 this.isPseudoKeyword = isPseudoKeyword; |
| 367 } | 392 } |
| 368 } | 393 } |
| 369 /** | 394 /** |
| 370 * The abstract class `AbstractScanner` implements a scanner for Dart code. Subc
lasses are | 395 * Instances of the class `CharSequenceReader` implement a [CharacterReader] tha
t reads |
| 371 * required to implement the interface used to access the characters being scann
ed. | 396 * characters from a character sequence. |
| 397 */ |
| 398 class CharSequenceReader implements CharacterReader { |
| 399 |
| 400 /** |
| 401 * The sequence from which characters will be read. |
| 402 */ |
| 403 CharSequence _sequence; |
| 404 |
| 405 /** |
| 406 * The number of characters in the string. |
| 407 */ |
| 408 int _stringLength = 0; |
| 409 |
| 410 /** |
| 411 * The index, relative to the string, of the last character that was read. |
| 412 */ |
| 413 int _charOffset = 0; |
| 414 |
| 415 /** |
| 416 * Initialize a newly created reader to read the characters in the given seque
nce. |
| 417 * |
| 418 * @param sequence the sequence from which characters will be read |
| 419 */ |
| 420 CharSequenceReader(CharSequence sequence) { |
| 421 this._sequence = sequence; |
| 422 this._stringLength = sequence.length(); |
| 423 this._charOffset = -1; |
| 424 } |
| 425 int advance() { |
| 426 if (_charOffset + 1 >= _stringLength) { |
| 427 return -1; |
| 428 } |
| 429 return _sequence.charAt(++_charOffset); |
| 430 } |
| 431 int get offset => _charOffset; |
| 432 String getString(int start, int endDelta) => _sequence.subSequence(start, _cha
rOffset + 1 + endDelta).toString(); |
| 433 int peek() { |
| 434 if (_charOffset + 1 >= _sequence.length()) { |
| 435 return -1; |
| 436 } |
| 437 return _sequence.charAt(_charOffset + 1); |
| 438 } |
| 439 } |
| 440 /** |
| 441 * The class `Scanner` implements a scanner for Dart code. |
| 372 * | 442 * |
| 373 * The lexical structure of Dart is ambiguous without knowledge of the context i
n which a token is | 443 * The lexical structure of Dart is ambiguous without knowledge of the context i
n which a token is |
| 374 * being scanned. For example, without context we cannot determine whether sourc
e of the form "<<" | 444 * being scanned. For example, without context we cannot determine whether sourc
e of the form "<<" |
| 375 * should be scanned as a single left-shift operator or as two left angle bracke
ts. This scanner | 445 * should be scanned as a single left-shift operator or as two left angle bracke
ts. This scanner |
| 376 * does not have any context, so it always resolves such conflicts by scanning t
he longest possible | 446 * does not have any context, so it always resolves such conflicts by scanning t
he longest possible |
| 377 * token. | 447 * token. |
| 378 * | 448 * |
| 379 * @coverage dart.engine.parser | 449 * @coverage dart.engine.parser |
| 380 */ | 450 */ |
| 381 abstract class AbstractScanner { | 451 class Scanner { |
| 382 | 452 |
| 383 /** | 453 /** |
| 384 * The source being scanned. | 454 * The source being scanned. |
| 385 */ | 455 */ |
| 386 Source source; | 456 Source source; |
| 387 | 457 |
| 388 /** | 458 /** |
| 459 * The reader used to access the characters in the source. |
| 460 */ |
| 461 CharacterReader _reader; |
| 462 |
| 463 /** |
| 389 * The error listener that will be informed of any errors that are found durin
g the scan. | 464 * The error listener that will be informed of any errors that are found durin
g the scan. |
| 390 */ | 465 */ |
| 391 AnalysisErrorListener _errorListener; | 466 AnalysisErrorListener _errorListener; |
| 392 | 467 |
| 393 /** | 468 /** |
| 394 * The token pointing to the head of the linked list of tokens. | 469 * The token pointing to the head of the linked list of tokens. |
| 395 */ | 470 */ |
| 396 Token _tokens; | 471 Token _tokens; |
| 397 | 472 |
| 398 /** | 473 /** |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 | 508 |
| 434 /** | 509 /** |
| 435 * A flag indicating whether any unmatched groups were found during the parse. | 510 * A flag indicating whether any unmatched groups were found during the parse. |
| 436 */ | 511 */ |
| 437 bool _hasUnmatchedGroups2 = false; | 512 bool _hasUnmatchedGroups2 = false; |
| 438 | 513 |
| 439 /** | 514 /** |
| 440 * Initialize a newly created scanner. | 515 * Initialize a newly created scanner. |
| 441 * | 516 * |
| 442 * @param source the source being scanned | 517 * @param source the source being scanned |
| 518 * @param reader the character reader used to read the characters in the sourc
e |
| 443 * @param errorListener the error listener that will be informed of any errors
that are found | 519 * @param errorListener the error listener that will be informed of any errors
that are found |
| 444 */ | 520 */ |
| 445 AbstractScanner(Source source, AnalysisErrorListener errorListener) { | 521 Scanner(Source source, CharacterReader reader, AnalysisErrorListener errorList
ener) { |
| 446 this.source = source; | 522 this.source = source; |
| 523 this._reader = reader; |
| 447 this._errorListener = errorListener; | 524 this._errorListener = errorListener; |
| 448 _tokens = new Token(TokenType.EOF, -1); | 525 _tokens = new Token(TokenType.EOF, -1); |
| 449 _tokens.setNext(_tokens); | 526 _tokens.setNext(_tokens); |
| 450 _tail = _tokens; | 527 _tail = _tokens; |
| 451 _tokenStart = -1; | 528 _tokenStart = -1; |
| 452 _lineStarts.add(0); | 529 _lineStarts.add(0); |
| 453 } | 530 } |
| 454 | 531 |
| 455 /** | 532 /** |
| 456 * Return an array containing the offsets of the first character of each line
in the source code. | 533 * Return an array containing the offsets of the first character of each line
in the source code. |
| 457 * | 534 * |
| 458 * @return an array containing the offsets of the first character of each line
in the source code | 535 * @return an array containing the offsets of the first character of each line
in the source code |
| 459 */ | 536 */ |
| 460 List<int> get lineStarts => _lineStarts; | 537 List<int> get lineStarts => _lineStarts; |
| 461 | 538 |
| 462 /** | 539 /** |
| 463 * Return the current offset relative to the beginning of the file. Return the
initial offset if | |
| 464 * the scanner has not yet scanned the source code, and one (1) past the end o
f the source code if | |
| 465 * the source code has been scanned. | |
| 466 * | |
| 467 * @return the current offset of the scanner in the source | |
| 468 */ | |
| 469 int get offset; | |
| 470 | |
| 471 /** | |
| 472 * Return `true` if any unmatched groups were found during the parse. | 540 * Return `true` if any unmatched groups were found during the parse. |
| 473 * | 541 * |
| 474 * @return `true` if any unmatched groups were found during the parse | 542 * @return `true` if any unmatched groups were found during the parse |
| 475 */ | 543 */ |
| 476 bool hasUnmatchedGroups() => _hasUnmatchedGroups2; | 544 bool hasUnmatchedGroups() => _hasUnmatchedGroups2; |
| 477 | 545 |
| 478 /** | 546 /** |
| 547 * Record that the source begins on the given line and column at the current o
ffset as given by |
| 548 * the reader. The line starts for lines before the given line will not be cor
rect. |
| 549 * |
| 550 * This method must be invoked at most one time and must be invoked before sca
nning begins. The |
| 551 * values provided must be sensible. The results are undefined if these condit
ions are violated. |
| 552 * |
| 553 * @param line the one-based index of the line containing the first character
of the source |
| 554 * @param column the one-based index of the column in which the first characte
r of the source |
| 555 * occurs |
| 556 */ |
| 557 void setSourceStart(int line, int column) { |
| 558 int offset = _reader.offset; |
| 559 if (line < 1 || column < 1 || offset < 0 || (line + column - 2) >= offset) { |
| 560 return; |
| 561 } |
| 562 for (int i = 2; i < line; i++) { |
| 563 _lineStarts.add(1); |
| 564 } |
| 565 _lineStarts.add(offset - column + 1); |
| 566 } |
| 567 |
| 568 /** |
| 479 * Scan the source code to produce a list of tokens representing the source. | 569 * Scan the source code to produce a list of tokens representing the source. |
| 480 * | 570 * |
| 481 * @return the first token in the list of tokens that were produced | 571 * @return the first token in the list of tokens that were produced |
| 482 */ | 572 */ |
| 483 Token tokenize() { | 573 Token tokenize() { |
| 484 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi
ne.AbstractScanner.tokenize"); | 574 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi
ne.AbstractScanner.tokenize"); |
| 485 int tokenCounter = 0; | 575 int tokenCounter = 0; |
| 486 try { | 576 try { |
| 487 int next = advance(); | 577 int next = _reader.advance(); |
| 488 while (next != -1) { | 578 while (next != -1) { |
| 489 tokenCounter++; | 579 tokenCounter++; |
| 490 next = bigSwitch(next); | 580 next = bigSwitch(next); |
| 491 } | 581 } |
| 492 appendEofToken(); | 582 appendEofToken(); |
| 493 instrumentation.metric2("tokensCount", tokenCounter); | 583 instrumentation.metric2("tokensCount", tokenCounter); |
| 494 return firstToken(); | 584 return firstToken(); |
| 495 } finally { | 585 } finally { |
| 496 instrumentation.log2(2); | 586 instrumentation.log2(2); |
| 497 } | 587 } |
| 498 } | 588 } |
| 499 | 589 |
| 500 /** | 590 /** |
| 501 * Advance the current position and return the character at the new current po
sition. | |
| 502 * | |
| 503 * @return the character at the new current position | |
| 504 */ | |
| 505 int advance(); | |
| 506 | |
| 507 /** | |
| 508 * Return the substring of the source code between the start offset and the mo
dified current | |
| 509 * position. The current position is modified by adding the end delta. | |
| 510 * | |
| 511 * @param start the offset to the beginning of the string, relative to the sta
rt of the file | |
| 512 * @param endDelta the number of character after the current location to be in
cluded in the | |
| 513 * string, or the number of characters before the current location to
be excluded if the | |
| 514 * offset is negative | |
| 515 * @return the specified substring of the source code | |
| 516 */ | |
| 517 String getString(int start, int endDelta); | |
| 518 | |
| 519 /** | |
| 520 * Return the character at the current position without changing the current p
osition. | |
| 521 * | |
| 522 * @return the character at the current position | |
| 523 */ | |
| 524 int peek(); | |
| 525 | |
| 526 /** | |
| 527 * Record the fact that we are at the beginning of a new line in the source. | 591 * Record the fact that we are at the beginning of a new line in the source. |
| 528 */ | 592 */ |
| 529 void recordStartOfLine() { | 593 void recordStartOfLine() { |
| 530 _lineStarts.add(offset); | 594 _lineStarts.add(_reader.offset); |
| 531 } | 595 } |
| 532 void appendBeginToken(TokenType type) { | 596 void appendBeginToken(TokenType type) { |
| 533 BeginToken token; | 597 BeginToken token; |
| 534 if (_firstComment == null) { | 598 if (_firstComment == null) { |
| 535 token = new BeginToken(type, _tokenStart); | 599 token = new BeginToken(type, _tokenStart); |
| 536 } else { | 600 } else { |
| 537 token = new BeginTokenWithComment(type, _tokenStart, _firstComment); | 601 token = new BeginTokenWithComment(type, _tokenStart, _firstComment); |
| 538 _firstComment = null; | 602 _firstComment = null; |
| 539 _lastComment = null; | 603 _lastComment = null; |
| 540 } | 604 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 564 BeginToken begin = _groupingStack[_stackEnd]; | 628 BeginToken begin = _groupingStack[_stackEnd]; |
| 565 if (identical(begin.type, beginType)) { | 629 if (identical(begin.type, beginType)) { |
| 566 begin.endToken = token; | 630 begin.endToken = token; |
| 567 _groupingStack.removeAt(_stackEnd--); | 631 _groupingStack.removeAt(_stackEnd--); |
| 568 } | 632 } |
| 569 } | 633 } |
| 570 } | 634 } |
| 571 void appendEofToken() { | 635 void appendEofToken() { |
| 572 Token eofToken; | 636 Token eofToken; |
| 573 if (_firstComment == null) { | 637 if (_firstComment == null) { |
| 574 eofToken = new Token(TokenType.EOF, offset + 1); | 638 eofToken = new Token(TokenType.EOF, _reader.offset + 1); |
| 575 } else { | 639 } else { |
| 576 eofToken = new TokenWithComment(TokenType.EOF, offset + 1, _firstComment); | 640 eofToken = new TokenWithComment(TokenType.EOF, _reader.offset + 1, _firstC
omment); |
| 577 _firstComment = null; | 641 _firstComment = null; |
| 578 _lastComment = null; | 642 _lastComment = null; |
| 579 } | 643 } |
| 580 eofToken.setNext(eofToken); | 644 eofToken.setNext(eofToken); |
| 581 _tail = _tail.setNext(eofToken); | 645 _tail = _tail.setNext(eofToken); |
| 582 if (_stackEnd >= 0) { | 646 if (_stackEnd >= 0) { |
| 583 _hasUnmatchedGroups2 = true; | 647 _hasUnmatchedGroups2 = true; |
| 584 } | 648 } |
| 585 } | 649 } |
| 586 void appendKeywordToken(Keyword keyword) { | 650 void appendKeywordToken(Keyword keyword) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 void appendToken2(TokenType type, int offset) { | 686 void appendToken2(TokenType type, int offset) { |
| 623 if (_firstComment == null) { | 687 if (_firstComment == null) { |
| 624 _tail = _tail.setNext(new Token(type, offset)); | 688 _tail = _tail.setNext(new Token(type, offset)); |
| 625 } else { | 689 } else { |
| 626 _tail = _tail.setNext(new TokenWithComment(type, offset, _firstComment)); | 690 _tail = _tail.setNext(new TokenWithComment(type, offset, _firstComment)); |
| 627 _firstComment = null; | 691 _firstComment = null; |
| 628 _lastComment = null; | 692 _lastComment = null; |
| 629 } | 693 } |
| 630 } | 694 } |
| 631 void beginToken() { | 695 void beginToken() { |
| 632 _tokenStart = offset; | 696 _tokenStart = _reader.offset; |
| 633 } | 697 } |
| 634 int bigSwitch(int next) { | 698 int bigSwitch(int next) { |
| 635 beginToken(); | 699 beginToken(); |
| 636 if (next == 0xD) { | 700 if (next == 0xD) { |
| 637 next = advance(); | 701 next = _reader.advance(); |
| 638 if (next == 0xA) { | 702 if (next == 0xA) { |
| 639 next = advance(); | 703 next = _reader.advance(); |
| 640 } | 704 } |
| 641 recordStartOfLine(); | 705 recordStartOfLine(); |
| 642 return next; | 706 return next; |
| 643 } else if (next == 0xA) { | 707 } else if (next == 0xA) { |
| 644 next = advance(); | 708 next = _reader.advance(); |
| 645 recordStartOfLine(); | 709 recordStartOfLine(); |
| 646 return next; | 710 return next; |
| 647 } else if (next == 0x9 || next == 0x20) { | 711 } else if (next == 0x9 || next == 0x20) { |
| 648 return advance(); | 712 return _reader.advance(); |
| 649 } | 713 } |
| 650 if (next == 0x72) { | 714 if (next == 0x72) { |
| 651 int peek = this.peek(); | 715 int peek = _reader.peek(); |
| 652 if (peek == 0x22 || peek == 0x27) { | 716 if (peek == 0x22 || peek == 0x27) { |
| 653 int start = offset; | 717 int start = _reader.offset; |
| 654 return tokenizeString(advance(), start, true); | 718 return tokenizeString(_reader.advance(), start, true); |
| 655 } | 719 } |
| 656 } | 720 } |
| 657 if (0x61 <= next && next <= 0x7A) { | 721 if (0x61 <= next && next <= 0x7A) { |
| 658 return tokenizeKeywordOrIdentifier(next, true); | 722 return tokenizeKeywordOrIdentifier(next, true); |
| 659 } | 723 } |
| 660 if ((0x41 <= next && next <= 0x5A) || next == 0x5F || next == 0x24) { | 724 if ((0x41 <= next && next <= 0x5A) || next == 0x5F || next == 0x24) { |
| 661 return tokenizeIdentifier(next, offset, true); | 725 return tokenizeIdentifier(next, _reader.offset, true); |
| 662 } | 726 } |
| 663 if (next == 0x3C) { | 727 if (next == 0x3C) { |
| 664 return tokenizeLessThan(next); | 728 return tokenizeLessThan(next); |
| 665 } | 729 } |
| 666 if (next == 0x3E) { | 730 if (next == 0x3E) { |
| 667 return tokenizeGreaterThan(next); | 731 return tokenizeGreaterThan(next); |
| 668 } | 732 } |
| 669 if (next == 0x3D) { | 733 if (next == 0x3D) { |
| 670 return tokenizeEquals(next); | 734 return tokenizeEquals(next); |
| 671 } | 735 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 694 return tokenizeCaret(next); | 758 return tokenizeCaret(next); |
| 695 } | 759 } |
| 696 if (next == 0x5B) { | 760 if (next == 0x5B) { |
| 697 return tokenizeOpenSquareBracket(next); | 761 return tokenizeOpenSquareBracket(next); |
| 698 } | 762 } |
| 699 if (next == 0x7E) { | 763 if (next == 0x7E) { |
| 700 return tokenizeTilde(next); | 764 return tokenizeTilde(next); |
| 701 } | 765 } |
| 702 if (next == 0x5C) { | 766 if (next == 0x5C) { |
| 703 appendToken(TokenType.BACKSLASH); | 767 appendToken(TokenType.BACKSLASH); |
| 704 return advance(); | 768 return _reader.advance(); |
| 705 } | 769 } |
| 706 if (next == 0x23) { | 770 if (next == 0x23) { |
| 707 return tokenizeTag(next); | 771 return tokenizeTag(next); |
| 708 } | 772 } |
| 709 if (next == 0x28) { | 773 if (next == 0x28) { |
| 710 appendBeginToken(TokenType.OPEN_PAREN); | 774 appendBeginToken(TokenType.OPEN_PAREN); |
| 711 return advance(); | 775 return _reader.advance(); |
| 712 } | 776 } |
| 713 if (next == 0x29) { | 777 if (next == 0x29) { |
| 714 appendEndToken(TokenType.CLOSE_PAREN, TokenType.OPEN_PAREN); | 778 appendEndToken(TokenType.CLOSE_PAREN, TokenType.OPEN_PAREN); |
| 715 return advance(); | 779 return _reader.advance(); |
| 716 } | 780 } |
| 717 if (next == 0x2C) { | 781 if (next == 0x2C) { |
| 718 appendToken(TokenType.COMMA); | 782 appendToken(TokenType.COMMA); |
| 719 return advance(); | 783 return _reader.advance(); |
| 720 } | 784 } |
| 721 if (next == 0x3A) { | 785 if (next == 0x3A) { |
| 722 appendToken(TokenType.COLON); | 786 appendToken(TokenType.COLON); |
| 723 return advance(); | 787 return _reader.advance(); |
| 724 } | 788 } |
| 725 if (next == 0x3B) { | 789 if (next == 0x3B) { |
| 726 appendToken(TokenType.SEMICOLON); | 790 appendToken(TokenType.SEMICOLON); |
| 727 return advance(); | 791 return _reader.advance(); |
| 728 } | 792 } |
| 729 if (next == 0x3F) { | 793 if (next == 0x3F) { |
| 730 appendToken(TokenType.QUESTION); | 794 appendToken(TokenType.QUESTION); |
| 731 return advance(); | 795 return _reader.advance(); |
| 732 } | 796 } |
| 733 if (next == 0x5D) { | 797 if (next == 0x5D) { |
| 734 appendEndToken(TokenType.CLOSE_SQUARE_BRACKET, TokenType.OPEN_SQUARE_BRACK
ET); | 798 appendEndToken(TokenType.CLOSE_SQUARE_BRACKET, TokenType.OPEN_SQUARE_BRACK
ET); |
| 735 return advance(); | 799 return _reader.advance(); |
| 736 } | 800 } |
| 737 if (next == 0x60) { | 801 if (next == 0x60) { |
| 738 appendToken(TokenType.BACKPING); | 802 appendToken(TokenType.BACKPING); |
| 739 return advance(); | 803 return _reader.advance(); |
| 740 } | 804 } |
| 741 if (next == 0x7B) { | 805 if (next == 0x7B) { |
| 742 appendBeginToken(TokenType.OPEN_CURLY_BRACKET); | 806 appendBeginToken(TokenType.OPEN_CURLY_BRACKET); |
| 743 return advance(); | 807 return _reader.advance(); |
| 744 } | 808 } |
| 745 if (next == 0x7D) { | 809 if (next == 0x7D) { |
| 746 appendEndToken(TokenType.CLOSE_CURLY_BRACKET, TokenType.OPEN_CURLY_BRACKET
); | 810 appendEndToken(TokenType.CLOSE_CURLY_BRACKET, TokenType.OPEN_CURLY_BRACKET
); |
| 747 return advance(); | 811 return _reader.advance(); |
| 748 } | 812 } |
| 749 if (next == 0x2F) { | 813 if (next == 0x2F) { |
| 750 return tokenizeSlashOrComment(next); | 814 return tokenizeSlashOrComment(next); |
| 751 } | 815 } |
| 752 if (next == 0x40) { | 816 if (next == 0x40) { |
| 753 appendToken(TokenType.AT); | 817 appendToken(TokenType.AT); |
| 754 return advance(); | 818 return _reader.advance(); |
| 755 } | 819 } |
| 756 if (next == 0x22 || next == 0x27) { | 820 if (next == 0x22 || next == 0x27) { |
| 757 return tokenizeString(next, offset, false); | 821 return tokenizeString(next, _reader.offset, false); |
| 758 } | 822 } |
| 759 if (next == 0x2E) { | 823 if (next == 0x2E) { |
| 760 return tokenizeDotOrNumber(next); | 824 return tokenizeDotOrNumber(next); |
| 761 } | 825 } |
| 762 if (next == 0x30) { | 826 if (next == 0x30) { |
| 763 return tokenizeHexOrNumber(next); | 827 return tokenizeHexOrNumber(next); |
| 764 } | 828 } |
| 765 if (0x31 <= next && next <= 0x39) { | 829 if (0x31 <= next && next <= 0x39) { |
| 766 return tokenizeNumber(next); | 830 return tokenizeNumber(next); |
| 767 } | 831 } |
| 768 if (next == -1) { | 832 if (next == -1) { |
| 769 return -1; | 833 return -1; |
| 770 } | 834 } |
| 771 reportError(ScannerErrorCode.ILLEGAL_CHARACTER, [next]); | 835 reportError(ScannerErrorCode.ILLEGAL_CHARACTER, [next]); |
| 772 return advance(); | 836 return _reader.advance(); |
| 773 } | 837 } |
| 774 | 838 |
| 775 /** | 839 /** |
| 776 * Return the beginning token corresponding to a closing brace that was found
while scanning | 840 * Return the beginning token corresponding to a closing brace that was found
while scanning |
| 777 * inside a string interpolation expression. Tokens that cannot be matched wit
h the closing brace | 841 * inside a string interpolation expression. Tokens that cannot be matched wit
h the closing brace |
| 778 * will be dropped from the stack. | 842 * will be dropped from the stack. |
| 779 * | 843 * |
| 780 * @return the token to be paired with the closing brace | 844 * @return the token to be paired with the closing brace |
| 781 */ | 845 */ |
| 782 BeginToken findTokenMatchingClosingBraceInInterpolationExpression() { | 846 BeginToken findTokenMatchingClosingBraceInInterpolationExpression() { |
| 783 while (_stackEnd >= 0) { | 847 while (_stackEnd >= 0) { |
| 784 BeginToken begin = _groupingStack[_stackEnd]; | 848 BeginToken begin = _groupingStack[_stackEnd]; |
| 785 if (identical(begin.type, TokenType.OPEN_CURLY_BRACKET) || identical(begin
.type, TokenType.STRING_INTERPOLATION_EXPRESSION)) { | 849 if (identical(begin.type, TokenType.OPEN_CURLY_BRACKET) || identical(begin
.type, TokenType.STRING_INTERPOLATION_EXPRESSION)) { |
| 786 return begin; | 850 return begin; |
| 787 } | 851 } |
| 788 _hasUnmatchedGroups2 = true; | 852 _hasUnmatchedGroups2 = true; |
| 789 _groupingStack.removeAt(_stackEnd--); | 853 _groupingStack.removeAt(_stackEnd--); |
| 790 } | 854 } |
| 791 return null; | 855 return null; |
| 792 } | 856 } |
| 793 Token firstToken() => _tokens.next; | 857 Token firstToken() => _tokens.next; |
| 794 | 858 |
| 795 /** | 859 /** |
| 796 * Report an error at the current offset. | 860 * Report an error at the current offset. |
| 797 * | 861 * |
| 798 * @param errorCode the error code indicating the nature of the error | 862 * @param errorCode the error code indicating the nature of the error |
| 799 * @param arguments any arguments needed to complete the error message | 863 * @param arguments any arguments needed to complete the error message |
| 800 */ | 864 */ |
| 801 void reportError(ScannerErrorCode errorCode, List<Object> arguments) { | 865 void reportError(ScannerErrorCode errorCode, List<Object> arguments) { |
| 802 _errorListener.onError(new AnalysisError.con2(source, offset, 1, errorCode,
arguments)); | 866 _errorListener.onError(new AnalysisError.con2(source, _reader.offset, 1, err
orCode, arguments)); |
| 803 } | 867 } |
| 804 int select(int choice, TokenType yesType, TokenType noType) { | 868 int select(int choice, TokenType yesType, TokenType noType) { |
| 805 int next = advance(); | 869 int next = _reader.advance(); |
| 806 if (next == choice) { | 870 if (next == choice) { |
| 807 appendToken(yesType); | 871 appendToken(yesType); |
| 808 return advance(); | 872 return _reader.advance(); |
| 809 } else { | 873 } else { |
| 810 appendToken(noType); | 874 appendToken(noType); |
| 811 return next; | 875 return next; |
| 812 } | 876 } |
| 813 } | 877 } |
| 814 int select2(int choice, TokenType yesType, TokenType noType, int offset) { | 878 int select2(int choice, TokenType yesType, TokenType noType, int offset) { |
| 815 int next = advance(); | 879 int next = _reader.advance(); |
| 816 if (next == choice) { | 880 if (next == choice) { |
| 817 appendToken2(yesType, offset); | 881 appendToken2(yesType, offset); |
| 818 return advance(); | 882 return _reader.advance(); |
| 819 } else { | 883 } else { |
| 820 appendToken2(noType, offset); | 884 appendToken2(noType, offset); |
| 821 return next; | 885 return next; |
| 822 } | 886 } |
| 823 } | 887 } |
| 824 int tokenizeAmpersand(int next) { | 888 int tokenizeAmpersand(int next) { |
| 825 next = advance(); | 889 next = _reader.advance(); |
| 826 if (next == 0x26) { | 890 if (next == 0x26) { |
| 827 appendToken(TokenType.AMPERSAND_AMPERSAND); | 891 appendToken(TokenType.AMPERSAND_AMPERSAND); |
| 828 return advance(); | 892 return _reader.advance(); |
| 829 } else if (next == 0x3D) { | 893 } else if (next == 0x3D) { |
| 830 appendToken(TokenType.AMPERSAND_EQ); | 894 appendToken(TokenType.AMPERSAND_EQ); |
| 831 return advance(); | 895 return _reader.advance(); |
| 832 } else { | 896 } else { |
| 833 appendToken(TokenType.AMPERSAND); | 897 appendToken(TokenType.AMPERSAND); |
| 834 return next; | 898 return next; |
| 835 } | 899 } |
| 836 } | 900 } |
| 837 int tokenizeBar(int next) { | 901 int tokenizeBar(int next) { |
| 838 next = advance(); | 902 next = _reader.advance(); |
| 839 if (next == 0x7C) { | 903 if (next == 0x7C) { |
| 840 appendToken(TokenType.BAR_BAR); | 904 appendToken(TokenType.BAR_BAR); |
| 841 return advance(); | 905 return _reader.advance(); |
| 842 } else if (next == 0x3D) { | 906 } else if (next == 0x3D) { |
| 843 appendToken(TokenType.BAR_EQ); | 907 appendToken(TokenType.BAR_EQ); |
| 844 return advance(); | 908 return _reader.advance(); |
| 845 } else { | 909 } else { |
| 846 appendToken(TokenType.BAR); | 910 appendToken(TokenType.BAR); |
| 847 return next; | 911 return next; |
| 848 } | 912 } |
| 849 } | 913 } |
| 850 int tokenizeCaret(int next) => select(0x3D, TokenType.CARET_EQ, TokenType.CARE
T); | 914 int tokenizeCaret(int next) => select(0x3D, TokenType.CARET_EQ, TokenType.CARE
T); |
| 851 int tokenizeDotOrNumber(int next) { | 915 int tokenizeDotOrNumber(int next) { |
| 852 int start = offset; | 916 int start = _reader.offset; |
| 853 next = advance(); | 917 next = _reader.advance(); |
| 854 if ((0x30 <= next && next <= 0x39)) { | 918 if ((0x30 <= next && next <= 0x39)) { |
| 855 return tokenizeFractionPart(next, start); | 919 return tokenizeFractionPart(next, start); |
| 856 } else if (0x2E == next) { | 920 } else if (0x2E == next) { |
| 857 return select(0x2E, TokenType.PERIOD_PERIOD_PERIOD, TokenType.PERIOD_PERIO
D); | 921 return select(0x2E, TokenType.PERIOD_PERIOD_PERIOD, TokenType.PERIOD_PERIO
D); |
| 858 } else { | 922 } else { |
| 859 appendToken(TokenType.PERIOD); | 923 appendToken(TokenType.PERIOD); |
| 860 return next; | 924 return next; |
| 861 } | 925 } |
| 862 } | 926 } |
| 863 int tokenizeEquals(int next) { | 927 int tokenizeEquals(int next) { |
| 864 next = advance(); | 928 next = _reader.advance(); |
| 865 if (next == 0x3D) { | 929 if (next == 0x3D) { |
| 866 appendToken(TokenType.EQ_EQ); | 930 appendToken(TokenType.EQ_EQ); |
| 867 return advance(); | 931 return _reader.advance(); |
| 868 } else if (next == 0x3E) { | 932 } else if (next == 0x3E) { |
| 869 appendToken(TokenType.FUNCTION); | 933 appendToken(TokenType.FUNCTION); |
| 870 return advance(); | 934 return _reader.advance(); |
| 871 } | 935 } |
| 872 appendToken(TokenType.EQ); | 936 appendToken(TokenType.EQ); |
| 873 return next; | 937 return next; |
| 874 } | 938 } |
| 875 int tokenizeExclamation(int next) { | 939 int tokenizeExclamation(int next) { |
| 876 next = advance(); | 940 next = _reader.advance(); |
| 877 if (next == 0x3D) { | 941 if (next == 0x3D) { |
| 878 appendToken(TokenType.BANG_EQ); | 942 appendToken(TokenType.BANG_EQ); |
| 879 return advance(); | 943 return _reader.advance(); |
| 880 } | 944 } |
| 881 appendToken(TokenType.BANG); | 945 appendToken(TokenType.BANG); |
| 882 return next; | 946 return next; |
| 883 } | 947 } |
| 884 int tokenizeExponent(int next) { | 948 int tokenizeExponent(int next) { |
| 885 if (next == 0x2B || next == 0x2D) { | 949 if (next == 0x2B || next == 0x2D) { |
| 886 next = advance(); | 950 next = _reader.advance(); |
| 887 } | 951 } |
| 888 bool hasDigits = false; | 952 bool hasDigits = false; |
| 889 while (true) { | 953 while (true) { |
| 890 if (0x30 <= next && next <= 0x39) { | 954 if (0x30 <= next && next <= 0x39) { |
| 891 hasDigits = true; | 955 hasDigits = true; |
| 892 } else { | 956 } else { |
| 893 if (!hasDigits) { | 957 if (!hasDigits) { |
| 894 reportError(ScannerErrorCode.MISSING_DIGIT, []); | 958 reportError(ScannerErrorCode.MISSING_DIGIT, []); |
| 895 } | 959 } |
| 896 return next; | 960 return next; |
| 897 } | 961 } |
| 898 next = advance(); | 962 next = _reader.advance(); |
| 899 } | 963 } |
| 900 } | 964 } |
| 901 int tokenizeFractionPart(int next, int start) { | 965 int tokenizeFractionPart(int next, int start) { |
| 902 bool done = false; | 966 bool done = false; |
| 903 bool hasDigit = false; | 967 bool hasDigit = false; |
| 904 LOOP: while (!done) { | 968 LOOP: while (!done) { |
| 905 if (0x30 <= next && next <= 0x39) { | 969 if (0x30 <= next && next <= 0x39) { |
| 906 hasDigit = true; | 970 hasDigit = true; |
| 907 } else if (0x65 == next || 0x45 == next) { | 971 } else if (0x65 == next || 0x45 == next) { |
| 908 hasDigit = true; | 972 hasDigit = true; |
| 909 next = tokenizeExponent(advance()); | 973 next = tokenizeExponent(_reader.advance()); |
| 910 done = true; | 974 done = true; |
| 911 continue LOOP; | 975 continue LOOP; |
| 912 } else { | 976 } else { |
| 913 done = true; | 977 done = true; |
| 914 continue LOOP; | 978 continue LOOP; |
| 915 } | 979 } |
| 916 next = advance(); | 980 next = _reader.advance(); |
| 917 } | 981 } |
| 918 if (!hasDigit) { | 982 if (!hasDigit) { |
| 919 appendStringToken(TokenType.INT, getString(start, -2)); | 983 appendStringToken(TokenType.INT, _reader.getString(start, -2)); |
| 920 if (0x2E == next) { | 984 if (0x2E == next) { |
| 921 return select2(0x2E, TokenType.PERIOD_PERIOD_PERIOD, TokenType.PERIOD_PE
RIOD, offset - 1); | 985 return select2(0x2E, TokenType.PERIOD_PERIOD_PERIOD, TokenType.PERIOD_PE
RIOD, _reader.offset - 1); |
| 922 } | 986 } |
| 923 appendToken2(TokenType.PERIOD, offset - 1); | 987 appendToken2(TokenType.PERIOD, _reader.offset - 1); |
| 924 return bigSwitch(next); | 988 return bigSwitch(next); |
| 925 } | 989 } |
| 926 appendStringToken(TokenType.DOUBLE, getString(start, next < 0 ? 0 : -1)); | 990 appendStringToken(TokenType.DOUBLE, _reader.getString(start, next < 0 ? 0 :
-1)); |
| 927 return next; | 991 return next; |
| 928 } | 992 } |
| 929 int tokenizeGreaterThan(int next) { | 993 int tokenizeGreaterThan(int next) { |
| 930 next = advance(); | 994 next = _reader.advance(); |
| 931 if (0x3D == next) { | 995 if (0x3D == next) { |
| 932 appendToken(TokenType.GT_EQ); | 996 appendToken(TokenType.GT_EQ); |
| 933 return advance(); | 997 return _reader.advance(); |
| 934 } else if (0x3E == next) { | 998 } else if (0x3E == next) { |
| 935 next = advance(); | 999 next = _reader.advance(); |
| 936 if (0x3D == next) { | 1000 if (0x3D == next) { |
| 937 appendToken(TokenType.GT_GT_EQ); | 1001 appendToken(TokenType.GT_GT_EQ); |
| 938 return advance(); | 1002 return _reader.advance(); |
| 939 } else { | 1003 } else { |
| 940 appendToken(TokenType.GT_GT); | 1004 appendToken(TokenType.GT_GT); |
| 941 return next; | 1005 return next; |
| 942 } | 1006 } |
| 943 } else { | 1007 } else { |
| 944 appendToken(TokenType.GT); | 1008 appendToken(TokenType.GT); |
| 945 return next; | 1009 return next; |
| 946 } | 1010 } |
| 947 } | 1011 } |
| 948 int tokenizeHex(int next) { | 1012 int tokenizeHex(int next) { |
| 949 int start = offset - 1; | 1013 int start = _reader.offset - 1; |
| 950 bool hasDigits = false; | 1014 bool hasDigits = false; |
| 951 while (true) { | 1015 while (true) { |
| 952 next = advance(); | 1016 next = _reader.advance(); |
| 953 if ((0x30 <= next && next <= 0x39) || (0x41 <= next && next <= 0x46) || (0
x61 <= next && next <= 0x66)) { | 1017 if ((0x30 <= next && next <= 0x39) || (0x41 <= next && next <= 0x46) || (0
x61 <= next && next <= 0x66)) { |
| 954 hasDigits = true; | 1018 hasDigits = true; |
| 955 } else { | 1019 } else { |
| 956 if (!hasDigits) { | 1020 if (!hasDigits) { |
| 957 reportError(ScannerErrorCode.MISSING_HEX_DIGIT, []); | 1021 reportError(ScannerErrorCode.MISSING_HEX_DIGIT, []); |
| 958 } | 1022 } |
| 959 appendStringToken(TokenType.HEXADECIMAL, getString(start, next < 0 ? 0 :
-1)); | 1023 appendStringToken(TokenType.HEXADECIMAL, _reader.getString(start, next <
0 ? 0 : -1)); |
| 960 return next; | 1024 return next; |
| 961 } | 1025 } |
| 962 } | 1026 } |
| 963 } | 1027 } |
| 964 int tokenizeHexOrNumber(int next) { | 1028 int tokenizeHexOrNumber(int next) { |
| 965 int x = peek(); | 1029 int x = _reader.peek(); |
| 966 if (x == 0x78 || x == 0x58) { | 1030 if (x == 0x78 || x == 0x58) { |
| 967 advance(); | 1031 _reader.advance(); |
| 968 return tokenizeHex(x); | 1032 return tokenizeHex(x); |
| 969 } | 1033 } |
| 970 return tokenizeNumber(next); | 1034 return tokenizeNumber(next); |
| 971 } | 1035 } |
| 972 int tokenizeIdentifier(int next, int start, bool allowDollar) { | 1036 int tokenizeIdentifier(int next, int start, bool allowDollar) { |
| 973 while ((0x61 <= next && next <= 0x7A) || (0x41 <= next && next <= 0x5A) || (
0x30 <= next && next <= 0x39) || next == 0x5F || (next == 0x24 && allowDollar))
{ | 1037 while ((0x61 <= next && next <= 0x7A) || (0x41 <= next && next <= 0x5A) || (
0x30 <= next && next <= 0x39) || next == 0x5F || (next == 0x24 && allowDollar))
{ |
| 974 next = advance(); | 1038 next = _reader.advance(); |
| 975 } | 1039 } |
| 976 appendStringToken(TokenType.IDENTIFIER, getString(start, next < 0 ? 0 : -1))
; | 1040 appendStringToken(TokenType.IDENTIFIER, _reader.getString(start, next < 0 ?
0 : -1)); |
| 977 return next; | 1041 return next; |
| 978 } | 1042 } |
| 979 int tokenizeInterpolatedExpression(int next, int start) { | 1043 int tokenizeInterpolatedExpression(int next, int start) { |
| 980 appendBeginToken(TokenType.STRING_INTERPOLATION_EXPRESSION); | 1044 appendBeginToken(TokenType.STRING_INTERPOLATION_EXPRESSION); |
| 981 next = advance(); | 1045 next = _reader.advance(); |
| 982 while (next != -1) { | 1046 while (next != -1) { |
| 983 if (next == 0x7D) { | 1047 if (next == 0x7D) { |
| 984 BeginToken begin = findTokenMatchingClosingBraceInInterpolationExpressio
n(); | 1048 BeginToken begin = findTokenMatchingClosingBraceInInterpolationExpressio
n(); |
| 985 if (begin == null) { | 1049 if (begin == null) { |
| 986 beginToken(); | 1050 beginToken(); |
| 987 appendToken(TokenType.CLOSE_CURLY_BRACKET); | 1051 appendToken(TokenType.CLOSE_CURLY_BRACKET); |
| 988 next = advance(); | 1052 next = _reader.advance(); |
| 989 beginToken(); | 1053 beginToken(); |
| 990 return next; | 1054 return next; |
| 991 } else if (identical(begin.type, TokenType.OPEN_CURLY_BRACKET)) { | 1055 } else if (identical(begin.type, TokenType.OPEN_CURLY_BRACKET)) { |
| 992 beginToken(); | 1056 beginToken(); |
| 993 appendEndToken(TokenType.CLOSE_CURLY_BRACKET, TokenType.OPEN_CURLY_BRA
CKET); | 1057 appendEndToken(TokenType.CLOSE_CURLY_BRACKET, TokenType.OPEN_CURLY_BRA
CKET); |
| 994 next = advance(); | 1058 next = _reader.advance(); |
| 995 beginToken(); | 1059 beginToken(); |
| 996 } else if (identical(begin.type, TokenType.STRING_INTERPOLATION_EXPRESSI
ON)) { | 1060 } else if (identical(begin.type, TokenType.STRING_INTERPOLATION_EXPRESSI
ON)) { |
| 997 beginToken(); | 1061 beginToken(); |
| 998 appendEndToken(TokenType.CLOSE_CURLY_BRACKET, TokenType.STRING_INTERPO
LATION_EXPRESSION); | 1062 appendEndToken(TokenType.CLOSE_CURLY_BRACKET, TokenType.STRING_INTERPO
LATION_EXPRESSION); |
| 999 next = advance(); | 1063 next = _reader.advance(); |
| 1000 beginToken(); | 1064 beginToken(); |
| 1001 return next; | 1065 return next; |
| 1002 } | 1066 } |
| 1003 } else { | 1067 } else { |
| 1004 next = bigSwitch(next); | 1068 next = bigSwitch(next); |
| 1005 } | 1069 } |
| 1006 } | 1070 } |
| 1007 if (next == -1) { | 1071 if (next == -1) { |
| 1008 return next; | 1072 return next; |
| 1009 } | 1073 } |
| 1010 next = advance(); | 1074 next = _reader.advance(); |
| 1011 beginToken(); | 1075 beginToken(); |
| 1012 return next; | 1076 return next; |
| 1013 } | 1077 } |
| 1014 int tokenizeInterpolatedIdentifier(int next, int start) { | 1078 int tokenizeInterpolatedIdentifier(int next, int start) { |
| 1015 appendStringToken2(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 0); | 1079 appendStringToken2(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 0); |
| 1016 if (((0x41 <= next && next <= 0x5A) || (0x61 <= next && next <= 0x7A) || nex
t == 0x5F)) { | 1080 if (((0x41 <= next && next <= 0x5A) || (0x61 <= next && next <= 0x7A) || nex
t == 0x5F)) { |
| 1017 beginToken(); | 1081 beginToken(); |
| 1018 next = tokenizeKeywordOrIdentifier(next, false); | 1082 next = tokenizeKeywordOrIdentifier(next, false); |
| 1019 } | 1083 } |
| 1020 beginToken(); | 1084 beginToken(); |
| 1021 return next; | 1085 return next; |
| 1022 } | 1086 } |
| 1023 int tokenizeKeywordOrIdentifier(int next, bool allowDollar) { | 1087 int tokenizeKeywordOrIdentifier(int next, bool allowDollar) { |
| 1024 KeywordState state = KeywordState.KEYWORD_STATE; | 1088 KeywordState state = KeywordState.KEYWORD_STATE; |
| 1025 int start = offset; | 1089 int start = _reader.offset; |
| 1026 while (state != null && 0x61 <= next && next <= 0x7A) { | 1090 while (state != null && 0x61 <= next && next <= 0x7A) { |
| 1027 state = state.next(next as int); | 1091 state = state.next(next as int); |
| 1028 next = advance(); | 1092 next = _reader.advance(); |
| 1029 } | 1093 } |
| 1030 if (state == null || state.keyword() == null) { | 1094 if (state == null || state.keyword() == null) { |
| 1031 return tokenizeIdentifier(next, start, allowDollar); | 1095 return tokenizeIdentifier(next, start, allowDollar); |
| 1032 } | 1096 } |
| 1033 if ((0x41 <= next && next <= 0x5A) || (0x30 <= next && next <= 0x39) || next
== 0x5F || next == 0x24) { | 1097 if ((0x41 <= next && next <= 0x5A) || (0x30 <= next && next <= 0x39) || next
== 0x5F || next == 0x24) { |
| 1034 return tokenizeIdentifier(next, start, allowDollar); | 1098 return tokenizeIdentifier(next, start, allowDollar); |
| 1035 } else if (next < 128) { | 1099 } else if (next < 128) { |
| 1036 appendKeywordToken(state.keyword()); | 1100 appendKeywordToken(state.keyword()); |
| 1037 return next; | 1101 return next; |
| 1038 } else { | 1102 } else { |
| 1039 return tokenizeIdentifier(next, start, allowDollar); | 1103 return tokenizeIdentifier(next, start, allowDollar); |
| 1040 } | 1104 } |
| 1041 } | 1105 } |
| 1042 int tokenizeLessThan(int next) { | 1106 int tokenizeLessThan(int next) { |
| 1043 next = advance(); | 1107 next = _reader.advance(); |
| 1044 if (0x3D == next) { | 1108 if (0x3D == next) { |
| 1045 appendToken(TokenType.LT_EQ); | 1109 appendToken(TokenType.LT_EQ); |
| 1046 return advance(); | 1110 return _reader.advance(); |
| 1047 } else if (0x3C == next) { | 1111 } else if (0x3C == next) { |
| 1048 return select(0x3D, TokenType.LT_LT_EQ, TokenType.LT_LT); | 1112 return select(0x3D, TokenType.LT_LT_EQ, TokenType.LT_LT); |
| 1049 } else { | 1113 } else { |
| 1050 appendToken(TokenType.LT); | 1114 appendToken(TokenType.LT); |
| 1051 return next; | 1115 return next; |
| 1052 } | 1116 } |
| 1053 } | 1117 } |
| 1054 int tokenizeMinus(int next) { | 1118 int tokenizeMinus(int next) { |
| 1055 next = advance(); | 1119 next = _reader.advance(); |
| 1056 if (next == 0x2D) { | 1120 if (next == 0x2D) { |
| 1057 appendToken(TokenType.MINUS_MINUS); | 1121 appendToken(TokenType.MINUS_MINUS); |
| 1058 return advance(); | 1122 return _reader.advance(); |
| 1059 } else if (next == 0x3D) { | 1123 } else if (next == 0x3D) { |
| 1060 appendToken(TokenType.MINUS_EQ); | 1124 appendToken(TokenType.MINUS_EQ); |
| 1061 return advance(); | 1125 return _reader.advance(); |
| 1062 } else { | 1126 } else { |
| 1063 appendToken(TokenType.MINUS); | 1127 appendToken(TokenType.MINUS); |
| 1064 return next; | 1128 return next; |
| 1065 } | 1129 } |
| 1066 } | 1130 } |
| 1067 int tokenizeMultiLineComment(int next) { | 1131 int tokenizeMultiLineComment(int next) { |
| 1068 int nesting = 1; | 1132 int nesting = 1; |
| 1069 next = advance(); | 1133 next = _reader.advance(); |
| 1070 while (true) { | 1134 while (true) { |
| 1071 if (-1 == next) { | 1135 if (-1 == next) { |
| 1072 reportError(ScannerErrorCode.UNTERMINATED_MULTI_LINE_COMMENT, []); | 1136 reportError(ScannerErrorCode.UNTERMINATED_MULTI_LINE_COMMENT, []); |
| 1073 appendCommentToken(TokenType.MULTI_LINE_COMMENT, getString(_tokenStart,
0)); | 1137 appendCommentToken(TokenType.MULTI_LINE_COMMENT, _reader.getString(_toke
nStart, 0)); |
| 1074 return next; | 1138 return next; |
| 1075 } else if (0x2A == next) { | 1139 } else if (0x2A == next) { |
| 1076 next = advance(); | 1140 next = _reader.advance(); |
| 1077 if (0x2F == next) { | 1141 if (0x2F == next) { |
| 1078 --nesting; | 1142 --nesting; |
| 1079 if (0 == nesting) { | 1143 if (0 == nesting) { |
| 1080 appendCommentToken(TokenType.MULTI_LINE_COMMENT, getString(_tokenSta
rt, 0)); | 1144 appendCommentToken(TokenType.MULTI_LINE_COMMENT, _reader.getString(_
tokenStart, 0)); |
| 1081 return advance(); | 1145 return _reader.advance(); |
| 1082 } else { | 1146 } else { |
| 1083 next = advance(); | 1147 next = _reader.advance(); |
| 1084 } | 1148 } |
| 1085 } | 1149 } |
| 1086 } else if (0x2F == next) { | 1150 } else if (0x2F == next) { |
| 1087 next = advance(); | 1151 next = _reader.advance(); |
| 1088 if (0x2A == next) { | 1152 if (0x2A == next) { |
| 1089 next = advance(); | 1153 next = _reader.advance(); |
| 1090 ++nesting; | 1154 ++nesting; |
| 1091 } | 1155 } |
| 1092 } else if (next == 0xD) { | 1156 } else if (next == 0xD) { |
| 1093 next = advance(); | 1157 next = _reader.advance(); |
| 1094 if (next == 0xA) { | 1158 if (next == 0xA) { |
| 1095 next = advance(); | 1159 next = _reader.advance(); |
| 1096 } | 1160 } |
| 1097 recordStartOfLine(); | 1161 recordStartOfLine(); |
| 1098 } else if (next == 0xA) { | 1162 } else if (next == 0xA) { |
| 1099 recordStartOfLine(); | 1163 recordStartOfLine(); |
| 1100 next = advance(); | 1164 next = _reader.advance(); |
| 1101 } else { | 1165 } else { |
| 1102 next = advance(); | 1166 next = _reader.advance(); |
| 1103 } | 1167 } |
| 1104 } | 1168 } |
| 1105 } | 1169 } |
| 1106 int tokenizeMultiLineRawString(int quoteChar, int start) { | 1170 int tokenizeMultiLineRawString(int quoteChar, int start) { |
| 1107 int next = advance(); | 1171 int next = _reader.advance(); |
| 1108 outer: while (next != -1) { | 1172 outer: while (next != -1) { |
| 1109 while (next != quoteChar) { | 1173 while (next != quoteChar) { |
| 1110 next = advance(); | 1174 next = _reader.advance(); |
| 1111 if (next == -1) { | 1175 if (next == -1) { |
| 1112 break outer; | 1176 break outer; |
| 1113 } else if (next == 0xD) { | 1177 } else if (next == 0xD) { |
| 1114 next = advance(); | 1178 next = _reader.advance(); |
| 1115 if (next == 0xA) { | 1179 if (next == 0xA) { |
| 1116 next = advance(); | 1180 next = _reader.advance(); |
| 1117 } | 1181 } |
| 1118 recordStartOfLine(); | 1182 recordStartOfLine(); |
| 1119 } else if (next == 0xA) { | 1183 } else if (next == 0xA) { |
| 1120 recordStartOfLine(); | 1184 recordStartOfLine(); |
| 1121 next = advance(); | 1185 next = _reader.advance(); |
| 1122 } | 1186 } |
| 1123 } | 1187 } |
| 1124 next = advance(); | 1188 next = _reader.advance(); |
| 1125 if (next == quoteChar) { | 1189 if (next == quoteChar) { |
| 1126 next = advance(); | 1190 next = _reader.advance(); |
| 1127 if (next == quoteChar) { | 1191 if (next == quoteChar) { |
| 1128 appendStringToken(TokenType.STRING, getString(start, 0)); | 1192 appendStringToken(TokenType.STRING, _reader.getString(start, 0)); |
| 1129 return advance(); | 1193 return _reader.advance(); |
| 1130 } | 1194 } |
| 1131 } | 1195 } |
| 1132 } | 1196 } |
| 1133 reportError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, []); | 1197 reportError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, []); |
| 1134 appendStringToken(TokenType.STRING, getString(start, 0)); | 1198 appendStringToken(TokenType.STRING, _reader.getString(start, 0)); |
| 1135 return advance(); | 1199 return _reader.advance(); |
| 1136 } | 1200 } |
| 1137 int tokenizeMultiLineString(int quoteChar, int start, bool raw) { | 1201 int tokenizeMultiLineString(int quoteChar, int start, bool raw) { |
| 1138 if (raw) { | 1202 if (raw) { |
| 1139 return tokenizeMultiLineRawString(quoteChar, start); | 1203 return tokenizeMultiLineRawString(quoteChar, start); |
| 1140 } | 1204 } |
| 1141 int next = advance(); | 1205 int next = _reader.advance(); |
| 1142 while (next != -1) { | 1206 while (next != -1) { |
| 1143 if (next == 0x24) { | 1207 if (next == 0x24) { |
| 1144 appendStringToken(TokenType.STRING, getString(start, -1)); | 1208 appendStringToken(TokenType.STRING, _reader.getString(start, -1)); |
| 1145 beginToken(); | 1209 beginToken(); |
| 1146 next = tokenizeStringInterpolation(start); | 1210 next = tokenizeStringInterpolation(start); |
| 1147 start = offset; | 1211 start = _reader.offset; |
| 1148 continue; | 1212 continue; |
| 1149 } | 1213 } |
| 1150 if (next == quoteChar) { | 1214 if (next == quoteChar) { |
| 1151 next = advance(); | 1215 next = _reader.advance(); |
| 1152 if (next == quoteChar) { | 1216 if (next == quoteChar) { |
| 1153 next = advance(); | 1217 next = _reader.advance(); |
| 1154 if (next == quoteChar) { | 1218 if (next == quoteChar) { |
| 1155 appendStringToken(TokenType.STRING, getString(start, 0)); | 1219 appendStringToken(TokenType.STRING, _reader.getString(start, 0)); |
| 1156 return advance(); | 1220 return _reader.advance(); |
| 1157 } | 1221 } |
| 1158 } | 1222 } |
| 1159 continue; | 1223 continue; |
| 1160 } | 1224 } |
| 1161 if (next == 0x5C) { | 1225 if (next == 0x5C) { |
| 1162 next = advance(); | 1226 next = _reader.advance(); |
| 1163 if (next == -1) { | 1227 if (next == -1) { |
| 1164 break; | 1228 break; |
| 1165 } | 1229 } |
| 1166 bool missingCharacter = false; | 1230 bool missingCharacter = false; |
| 1167 if (next == 0xD) { | 1231 if (next == 0xD) { |
| 1168 missingCharacter = true; | 1232 missingCharacter = true; |
| 1169 next = advance(); | 1233 next = _reader.advance(); |
| 1170 if (next == 0xA) { | 1234 if (next == 0xA) { |
| 1171 next = advance(); | 1235 next = _reader.advance(); |
| 1172 } | 1236 } |
| 1173 recordStartOfLine(); | 1237 recordStartOfLine(); |
| 1174 } else if (next == 0xA) { | 1238 } else if (next == 0xA) { |
| 1175 missingCharacter = true; | 1239 missingCharacter = true; |
| 1176 recordStartOfLine(); | 1240 recordStartOfLine(); |
| 1177 next = advance(); | 1241 next = _reader.advance(); |
| 1178 } else { | 1242 } else { |
| 1179 next = advance(); | 1243 next = _reader.advance(); |
| 1180 } | 1244 } |
| 1181 if (missingCharacter) { | 1245 if (missingCharacter) { |
| 1182 _errorListener.onError(new AnalysisError.con2(source, offset - 1, 1, S
cannerErrorCode.CHARACTER_EXPECTED_AFTER_SLASH, [])); | 1246 _errorListener.onError(new AnalysisError.con2(source, _reader.offset -
1, 1, ScannerErrorCode.CHARACTER_EXPECTED_AFTER_SLASH, [])); |
| 1183 } | 1247 } |
| 1184 } else if (next == 0xD) { | 1248 } else if (next == 0xD) { |
| 1185 next = advance(); | 1249 next = _reader.advance(); |
| 1186 if (next == 0xA) { | 1250 if (next == 0xA) { |
| 1187 next = advance(); | 1251 next = _reader.advance(); |
| 1188 } | 1252 } |
| 1189 recordStartOfLine(); | 1253 recordStartOfLine(); |
| 1190 } else if (next == 0xA) { | 1254 } else if (next == 0xA) { |
| 1191 recordStartOfLine(); | 1255 recordStartOfLine(); |
| 1192 next = advance(); | 1256 next = _reader.advance(); |
| 1193 } else { | 1257 } else { |
| 1194 next = advance(); | 1258 next = _reader.advance(); |
| 1195 } | 1259 } |
| 1196 } | 1260 } |
| 1197 reportError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, []); | 1261 reportError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, []); |
| 1198 appendStringToken(TokenType.STRING, getString(start, 0)); | 1262 appendStringToken(TokenType.STRING, _reader.getString(start, 0)); |
| 1199 return advance(); | 1263 return _reader.advance(); |
| 1200 } | 1264 } |
| 1201 int tokenizeMultiply(int next) => select(0x3D, TokenType.STAR_EQ, TokenType.ST
AR); | 1265 int tokenizeMultiply(int next) => select(0x3D, TokenType.STAR_EQ, TokenType.ST
AR); |
| 1202 int tokenizeNumber(int next) { | 1266 int tokenizeNumber(int next) { |
| 1203 int start = offset; | 1267 int start = _reader.offset; |
| 1204 while (true) { | 1268 while (true) { |
| 1205 next = advance(); | 1269 next = _reader.advance(); |
| 1206 if (0x30 <= next && next <= 0x39) { | 1270 if (0x30 <= next && next <= 0x39) { |
| 1207 continue; | 1271 continue; |
| 1208 } else if (next == 0x2E) { | 1272 } else if (next == 0x2E) { |
| 1209 return tokenizeFractionPart(advance(), start); | 1273 return tokenizeFractionPart(_reader.advance(), start); |
| 1210 } else if (next == 0x65 || next == 0x45) { | 1274 } else if (next == 0x65 || next == 0x45) { |
| 1211 return tokenizeFractionPart(next, start); | 1275 return tokenizeFractionPart(next, start); |
| 1212 } else { | 1276 } else { |
| 1213 appendStringToken(TokenType.INT, getString(start, next < 0 ? 0 : -1)); | 1277 appendStringToken(TokenType.INT, _reader.getString(start, next < 0 ? 0 :
-1)); |
| 1214 return next; | 1278 return next; |
| 1215 } | 1279 } |
| 1216 } | 1280 } |
| 1217 } | 1281 } |
| 1218 int tokenizeOpenSquareBracket(int next) { | 1282 int tokenizeOpenSquareBracket(int next) { |
| 1219 next = advance(); | 1283 next = _reader.advance(); |
| 1220 if (next == 0x5D) { | 1284 if (next == 0x5D) { |
| 1221 return select(0x3D, TokenType.INDEX_EQ, TokenType.INDEX); | 1285 return select(0x3D, TokenType.INDEX_EQ, TokenType.INDEX); |
| 1222 } else { | 1286 } else { |
| 1223 appendBeginToken(TokenType.OPEN_SQUARE_BRACKET); | 1287 appendBeginToken(TokenType.OPEN_SQUARE_BRACKET); |
| 1224 return next; | 1288 return next; |
| 1225 } | 1289 } |
| 1226 } | 1290 } |
| 1227 int tokenizePercent(int next) => select(0x3D, TokenType.PERCENT_EQ, TokenType.
PERCENT); | 1291 int tokenizePercent(int next) => select(0x3D, TokenType.PERCENT_EQ, TokenType.
PERCENT); |
| 1228 int tokenizePlus(int next) { | 1292 int tokenizePlus(int next) { |
| 1229 next = advance(); | 1293 next = _reader.advance(); |
| 1230 if (0x2B == next) { | 1294 if (0x2B == next) { |
| 1231 appendToken(TokenType.PLUS_PLUS); | 1295 appendToken(TokenType.PLUS_PLUS); |
| 1232 return advance(); | 1296 return _reader.advance(); |
| 1233 } else if (0x3D == next) { | 1297 } else if (0x3D == next) { |
| 1234 appendToken(TokenType.PLUS_EQ); | 1298 appendToken(TokenType.PLUS_EQ); |
| 1235 return advance(); | 1299 return _reader.advance(); |
| 1236 } else { | 1300 } else { |
| 1237 appendToken(TokenType.PLUS); | 1301 appendToken(TokenType.PLUS); |
| 1238 return next; | 1302 return next; |
| 1239 } | 1303 } |
| 1240 } | 1304 } |
| 1241 int tokenizeSingleLineComment(int next) { | 1305 int tokenizeSingleLineComment(int next) { |
| 1242 while (true) { | 1306 while (true) { |
| 1243 next = advance(); | 1307 next = _reader.advance(); |
| 1244 if (-1 == next) { | 1308 if (-1 == next) { |
| 1245 appendCommentToken(TokenType.SINGLE_LINE_COMMENT, getString(_tokenStart,
0)); | 1309 appendCommentToken(TokenType.SINGLE_LINE_COMMENT, _reader.getString(_tok
enStart, 0)); |
| 1246 return next; | 1310 return next; |
| 1247 } else if (0xA == next || 0xD == next) { | 1311 } else if (0xA == next || 0xD == next) { |
| 1248 appendCommentToken(TokenType.SINGLE_LINE_COMMENT, getString(_tokenStart,
-1)); | 1312 appendCommentToken(TokenType.SINGLE_LINE_COMMENT, _reader.getString(_tok
enStart, -1)); |
| 1249 return next; | 1313 return next; |
| 1250 } | 1314 } |
| 1251 } | 1315 } |
| 1252 } | 1316 } |
| 1253 int tokenizeSingleLineRawString(int next, int quoteChar, int start) { | 1317 int tokenizeSingleLineRawString(int next, int quoteChar, int start) { |
| 1254 next = advance(); | 1318 next = _reader.advance(); |
| 1255 while (next != -1) { | 1319 while (next != -1) { |
| 1256 if (next == quoteChar) { | 1320 if (next == quoteChar) { |
| 1257 appendStringToken(TokenType.STRING, getString(start, 0)); | 1321 appendStringToken(TokenType.STRING, _reader.getString(start, 0)); |
| 1258 return advance(); | 1322 return _reader.advance(); |
| 1259 } else if (next == 0xD || next == 0xA) { | 1323 } else if (next == 0xD || next == 0xA) { |
| 1260 reportError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, []); | 1324 reportError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, []); |
| 1261 appendStringToken(TokenType.STRING, getString(start, 0)); | 1325 appendStringToken(TokenType.STRING, _reader.getString(start, 0)); |
| 1262 return advance(); | 1326 return _reader.advance(); |
| 1263 } | 1327 } |
| 1264 next = advance(); | 1328 next = _reader.advance(); |
| 1265 } | 1329 } |
| 1266 reportError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, []); | 1330 reportError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, []); |
| 1267 appendStringToken(TokenType.STRING, getString(start, 0)); | 1331 appendStringToken(TokenType.STRING, _reader.getString(start, 0)); |
| 1268 return advance(); | 1332 return _reader.advance(); |
| 1269 } | 1333 } |
| 1270 int tokenizeSingleLineString(int next, int quoteChar, int start) { | 1334 int tokenizeSingleLineString(int next, int quoteChar, int start) { |
| 1271 while (next != quoteChar) { | 1335 while (next != quoteChar) { |
| 1272 if (next == 0x5C) { | 1336 if (next == 0x5C) { |
| 1273 next = advance(); | 1337 next = _reader.advance(); |
| 1274 } else if (next == 0x24) { | 1338 } else if (next == 0x24) { |
| 1275 appendStringToken(TokenType.STRING, getString(start, -1)); | 1339 appendStringToken(TokenType.STRING, _reader.getString(start, -1)); |
| 1276 beginToken(); | 1340 beginToken(); |
| 1277 next = tokenizeStringInterpolation(start); | 1341 next = tokenizeStringInterpolation(start); |
| 1278 start = offset; | 1342 start = _reader.offset; |
| 1279 continue; | 1343 continue; |
| 1280 } | 1344 } |
| 1281 if (next <= 0xD && (next == 0xA || next == 0xD || next == -1)) { | 1345 if (next <= 0xD && (next == 0xA || next == 0xD || next == -1)) { |
| 1282 reportError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, []); | 1346 reportError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, []); |
| 1283 appendStringToken(TokenType.STRING, getString(start, 0)); | 1347 appendStringToken(TokenType.STRING, _reader.getString(start, 0)); |
| 1284 return advance(); | 1348 return _reader.advance(); |
| 1285 } | 1349 } |
| 1286 next = advance(); | 1350 next = _reader.advance(); |
| 1287 } | 1351 } |
| 1288 appendStringToken(TokenType.STRING, getString(start, 0)); | 1352 appendStringToken(TokenType.STRING, _reader.getString(start, 0)); |
| 1289 return advance(); | 1353 return _reader.advance(); |
| 1290 } | 1354 } |
| 1291 int tokenizeSlashOrComment(int next) { | 1355 int tokenizeSlashOrComment(int next) { |
| 1292 next = advance(); | 1356 next = _reader.advance(); |
| 1293 if (0x2A == next) { | 1357 if (0x2A == next) { |
| 1294 return tokenizeMultiLineComment(next); | 1358 return tokenizeMultiLineComment(next); |
| 1295 } else if (0x2F == next) { | 1359 } else if (0x2F == next) { |
| 1296 return tokenizeSingleLineComment(next); | 1360 return tokenizeSingleLineComment(next); |
| 1297 } else if (0x3D == next) { | 1361 } else if (0x3D == next) { |
| 1298 appendToken(TokenType.SLASH_EQ); | 1362 appendToken(TokenType.SLASH_EQ); |
| 1299 return advance(); | 1363 return _reader.advance(); |
| 1300 } else { | 1364 } else { |
| 1301 appendToken(TokenType.SLASH); | 1365 appendToken(TokenType.SLASH); |
| 1302 return next; | 1366 return next; |
| 1303 } | 1367 } |
| 1304 } | 1368 } |
| 1305 int tokenizeString(int next, int start, bool raw) { | 1369 int tokenizeString(int next, int start, bool raw) { |
| 1306 int quoteChar = next; | 1370 int quoteChar = next; |
| 1307 next = advance(); | 1371 next = _reader.advance(); |
| 1308 if (quoteChar == next) { | 1372 if (quoteChar == next) { |
| 1309 next = advance(); | 1373 next = _reader.advance(); |
| 1310 if (quoteChar == next) { | 1374 if (quoteChar == next) { |
| 1311 return tokenizeMultiLineString(quoteChar, start, raw); | 1375 return tokenizeMultiLineString(quoteChar, start, raw); |
| 1312 } else { | 1376 } else { |
| 1313 appendStringToken(TokenType.STRING, getString(start, -1)); | 1377 appendStringToken(TokenType.STRING, _reader.getString(start, -1)); |
| 1314 return next; | 1378 return next; |
| 1315 } | 1379 } |
| 1316 } | 1380 } |
| 1317 if (raw) { | 1381 if (raw) { |
| 1318 return tokenizeSingleLineRawString(next, quoteChar, start); | 1382 return tokenizeSingleLineRawString(next, quoteChar, start); |
| 1319 } else { | 1383 } else { |
| 1320 return tokenizeSingleLineString(next, quoteChar, start); | 1384 return tokenizeSingleLineString(next, quoteChar, start); |
| 1321 } | 1385 } |
| 1322 } | 1386 } |
| 1323 int tokenizeStringInterpolation(int start) { | 1387 int tokenizeStringInterpolation(int start) { |
| 1324 beginToken(); | 1388 beginToken(); |
| 1325 int next = advance(); | 1389 int next = _reader.advance(); |
| 1326 if (next == 0x7B) { | 1390 if (next == 0x7B) { |
| 1327 return tokenizeInterpolatedExpression(next, start); | 1391 return tokenizeInterpolatedExpression(next, start); |
| 1328 } else { | 1392 } else { |
| 1329 return tokenizeInterpolatedIdentifier(next, start); | 1393 return tokenizeInterpolatedIdentifier(next, start); |
| 1330 } | 1394 } |
| 1331 } | 1395 } |
| 1332 int tokenizeTag(int next) { | 1396 int tokenizeTag(int next) { |
| 1333 if (offset == 0) { | 1397 if (_reader.offset == 0) { |
| 1334 if (peek() == 0x21) { | 1398 if (_reader.peek() == 0x21) { |
| 1335 do { | 1399 do { |
| 1336 next = advance(); | 1400 next = _reader.advance(); |
| 1337 } while (next != 0xA && next != 0xD && next > 0); | 1401 } while (next != 0xA && next != 0xD && next > 0); |
| 1338 appendStringToken(TokenType.SCRIPT_TAG, getString(_tokenStart, 0)); | 1402 appendStringToken(TokenType.SCRIPT_TAG, _reader.getString(_tokenStart, 0
)); |
| 1339 return next; | 1403 return next; |
| 1340 } | 1404 } |
| 1341 } | 1405 } |
| 1342 appendToken(TokenType.HASH); | 1406 appendToken(TokenType.HASH); |
| 1343 return advance(); | 1407 return _reader.advance(); |
| 1344 } | 1408 } |
| 1345 int tokenizeTilde(int next) { | 1409 int tokenizeTilde(int next) { |
| 1346 next = advance(); | 1410 next = _reader.advance(); |
| 1347 if (next == 0x2F) { | 1411 if (next == 0x2F) { |
| 1348 return select(0x3D, TokenType.TILDE_SLASH_EQ, TokenType.TILDE_SLASH); | 1412 return select(0x3D, TokenType.TILDE_SLASH_EQ, TokenType.TILDE_SLASH); |
| 1349 } else { | 1413 } else { |
| 1350 appendToken(TokenType.TILDE); | 1414 appendToken(TokenType.TILDE); |
| 1351 return next; | 1415 return next; |
| 1352 } | 1416 } |
| 1353 } | 1417 } |
| 1354 } | 1418 } |
| 1355 /** | 1419 /** |
| 1356 * Instances of the class `StringToken` represent a token whose value is indepen
dent of it's | 1420 * Instances of the class `StringToken` represent a token whose value is indepen
dent of it's |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1372 * @param value the lexeme represented by this token | 1436 * @param value the lexeme represented by this token |
| 1373 * @param offset the offset from the beginning of the file to the first charac
ter in the token | 1437 * @param offset the offset from the beginning of the file to the first charac
ter in the token |
| 1374 */ | 1438 */ |
| 1375 StringToken(TokenType type, String value, int offset) : super(type, offset) { | 1439 StringToken(TokenType type, String value, int offset) : super(type, offset) { |
| 1376 this._value2 = StringUtilities.intern(value); | 1440 this._value2 = StringUtilities.intern(value); |
| 1377 } | 1441 } |
| 1378 String get lexeme => _value2; | 1442 String get lexeme => _value2; |
| 1379 String value() => _value2; | 1443 String value() => _value2; |
| 1380 } | 1444 } |
| 1381 /** | 1445 /** |
| 1382 * Instances of the class `CharBufferScanner` implement a scanner that reads fro
m a character | |
| 1383 * buffer. The scanning logic is in the superclass. | |
| 1384 * | |
| 1385 * @coverage dart.engine.parser | |
| 1386 */ | |
| 1387 class CharBufferScanner extends AbstractScanner { | |
| 1388 | |
| 1389 /** | |
| 1390 * The buffer from which characters will be read. | |
| 1391 */ | |
| 1392 CharBuffer _buffer; | |
| 1393 | |
| 1394 /** | |
| 1395 * The number of characters in the buffer. | |
| 1396 */ | |
| 1397 int _bufferLength = 0; | |
| 1398 | |
| 1399 /** | |
| 1400 * The index of the last character that was read. | |
| 1401 */ | |
| 1402 int _charOffset = 0; | |
| 1403 | |
| 1404 /** | |
| 1405 * Initialize a newly created scanner to scan the characters in the given char
acter buffer. | |
| 1406 * | |
| 1407 * @param source the source being scanned | |
| 1408 * @param buffer the buffer from which characters will be read | |
| 1409 * @param errorListener the error listener that will be informed of any errors
that are found | |
| 1410 */ | |
| 1411 CharBufferScanner(Source source, CharBuffer buffer, AnalysisErrorListener erro
rListener) : super(source, errorListener) { | |
| 1412 this._buffer = buffer; | |
| 1413 this._bufferLength = buffer.length(); | |
| 1414 this._charOffset = -1; | |
| 1415 } | |
| 1416 int get offset => _charOffset; | |
| 1417 int advance() { | |
| 1418 if (_charOffset + 1 >= _bufferLength) { | |
| 1419 return -1; | |
| 1420 } | |
| 1421 return _buffer.charAt(++_charOffset); | |
| 1422 } | |
| 1423 String getString(int start, int endDelta) => ((_buffer as CharSequence)).subSe
quence(start, _charOffset + 1 + endDelta).toString(); | |
| 1424 int peek() { | |
| 1425 if (_charOffset + 1 >= _buffer.length()) { | |
| 1426 return -1; | |
| 1427 } | |
| 1428 return _buffer.charAt(_charOffset + 1); | |
| 1429 } | |
| 1430 } | |
| 1431 /** | |
| 1432 * Instances of the class `TokenWithComment` represent a normal token that is pr
eceded by | 1446 * Instances of the class `TokenWithComment` represent a normal token that is pr
eceded by |
| 1433 * comments. | 1447 * comments. |
| 1434 * | 1448 * |
| 1435 * @coverage dart.engine.parser | 1449 * @coverage dart.engine.parser |
| 1436 */ | 1450 */ |
| 1437 class TokenWithComment extends Token { | 1451 class TokenWithComment extends Token { |
| 1438 | 1452 |
| 1439 /** | 1453 /** |
| 1440 * The first comment in the list of comments that precede this token. | 1454 * The first comment in the list of comments that precede this token. |
| 1441 */ | 1455 */ |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1576 | 1590 |
| 1577 /** | 1591 /** |
| 1578 * Return the value of this token. For keyword tokens, this is the keyword ass
ociated with the | 1592 * Return the value of this token. For keyword tokens, this is the keyword ass
ociated with the |
| 1579 * token, for other tokens it is the lexeme associated with the token. | 1593 * token, for other tokens it is the lexeme associated with the token. |
| 1580 * | 1594 * |
| 1581 * @return the value of this token | 1595 * @return the value of this token |
| 1582 */ | 1596 */ |
| 1583 Object value() => type.lexeme; | 1597 Object value() => type.lexeme; |
| 1584 } | 1598 } |
| 1585 /** | 1599 /** |
| 1586 * Instances of the class `StringScanner` implement a scanner that reads from a
string. The | 1600 * The interface `CharacterReader` |
| 1587 * scanning logic is in the superclass. | |
| 1588 * | |
| 1589 * @coverage dart.engine.parser | |
| 1590 */ | 1601 */ |
| 1591 class StringScanner extends AbstractScanner { | 1602 abstract class CharacterReader { |
| 1592 | 1603 |
| 1593 /** | 1604 /** |
| 1594 * The offset from the beginning of the file to the beginning of the source be
ing scanned. | 1605 * Advance the current position and return the character at the new current po
sition. |
| 1606 * |
| 1607 * @return the character at the new current position |
| 1595 */ | 1608 */ |
| 1596 int _offsetDelta = 0; | 1609 int advance(); |
| 1597 | 1610 |
| 1598 /** | 1611 /** |
| 1599 * The string from which characters will be read. | 1612 * Return the current offset relative to the beginning of the source. Return t
he initial offset if |
| 1613 * the scanner has not yet scanned the source code, and one (1) past the end o
f the source code if |
| 1614 * the entire source code has been scanned. |
| 1615 * |
| 1616 * @return the current offset of the scanner in the source |
| 1600 */ | 1617 */ |
| 1601 String _string; | 1618 int get offset; |
| 1602 | 1619 |
| 1603 /** | 1620 /** |
| 1604 * The number of characters in the string. | 1621 * Return the substring of the source code between the start offset and the mo
dified current |
| 1622 * position. The current position is modified by adding the end delta. |
| 1623 * |
| 1624 * @param start the offset to the beginning of the string, relative to the sta
rt of the file |
| 1625 * @param endDelta the number of characters after the current location to be i
ncluded in the |
| 1626 * string, or the number of characters before the current location to
be excluded if the |
| 1627 * offset is negative |
| 1628 * @return the specified substring of the source code |
| 1605 */ | 1629 */ |
| 1606 int _stringLength = 0; | 1630 String getString(int start, int endDelta); |
| 1607 | 1631 |
| 1608 /** | 1632 /** |
| 1609 * The index, relative to the string, of the last character that was read. | 1633 * Return the character at the current position without changing the current p
osition. |
| 1634 * |
| 1635 * @return the character at the current position |
| 1610 */ | 1636 */ |
| 1611 int _charOffset = 0; | 1637 int peek(); |
| 1612 | |
| 1613 /** | |
| 1614 * Initialize a newly created scanner to scan the characters in the given stri
ng. | |
| 1615 * | |
| 1616 * @param source the source being scanned | |
| 1617 * @param string the string from which characters will be read | |
| 1618 * @param errorListener the error listener that will be informed of any errors
that are found | |
| 1619 */ | |
| 1620 StringScanner(Source source, String string, AnalysisErrorListener errorListene
r) : super(source, errorListener) { | |
| 1621 this._offsetDelta = 0; | |
| 1622 this._string = string; | |
| 1623 this._stringLength = string.length; | |
| 1624 this._charOffset = -1; | |
| 1625 } | |
| 1626 int get offset => _offsetDelta + _charOffset; | |
| 1627 | |
| 1628 /** | |
| 1629 * Record that the source begins on the given line and column at the given off
set. The line starts | |
| 1630 * for lines before the given line will not be correct. | |
| 1631 * | |
| 1632 * This method must be invoked at most one time and must be invoked before sca
nning begins. The | |
| 1633 * values provided must be sensible. The results are undefined if these condit
ions are violated. | |
| 1634 * | |
| 1635 * @param line the one-based index of the line containing the first character
of the source | |
| 1636 * @param column the one-based index of the column in which the first characte
r of the source | |
| 1637 * occurs | |
| 1638 * @param offset the zero-based offset from the beginning of the larger contex
t to the first | |
| 1639 * character of the source | |
| 1640 */ | |
| 1641 void setSourceStart(int line, int column, int offset) { | |
| 1642 if (line < 1 || column < 1 || offset < 0 || (line + column - 2) >= offset) { | |
| 1643 return; | |
| 1644 } | |
| 1645 _offsetDelta = 1; | |
| 1646 for (int i = 2; i < line; i++) { | |
| 1647 recordStartOfLine(); | |
| 1648 } | |
| 1649 _offsetDelta = offset - column + 1; | |
| 1650 recordStartOfLine(); | |
| 1651 _offsetDelta = offset; | |
| 1652 } | |
| 1653 int advance() { | |
| 1654 if (_charOffset + 1 >= _stringLength) { | |
| 1655 return -1; | |
| 1656 } | |
| 1657 return _string.codeUnitAt(++_charOffset); | |
| 1658 } | |
| 1659 String getString(int start, int endDelta) => _string.substring(start - _offset
Delta, _charOffset + 1 + endDelta); | |
| 1660 int peek() { | |
| 1661 if (_charOffset + 1 >= _string.length) { | |
| 1662 return -1; | |
| 1663 } | |
| 1664 return _string.codeUnitAt(_charOffset + 1); | |
| 1665 } | |
| 1666 } | 1638 } |
| 1667 /** | 1639 /** |
| 1668 * Instances of the class `BeginTokenWithComment` represent a begin token that i
s preceded by | 1640 * Instances of the class `BeginTokenWithComment` represent a begin token that i
s preceded by |
| 1669 * comments. | 1641 * comments. |
| 1670 * | 1642 * |
| 1671 * @coverage dart.engine.parser | 1643 * @coverage dart.engine.parser |
| 1672 */ | 1644 */ |
| 1673 class BeginTokenWithComment extends BeginToken { | 1645 class BeginTokenWithComment extends BeginToken { |
| 1674 | 1646 |
| 1675 /** | 1647 /** |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2137 * Return `true` if this token type represents an operator that can be defined
by users. | 2109 * Return `true` if this token type represents an operator that can be defined
by users. |
| 2138 * | 2110 * |
| 2139 * @return `true` if this token type represents an operator that can be define
d by users | 2111 * @return `true` if this token type represents an operator that can be define
d by users |
| 2140 */ | 2112 */ |
| 2141 bool get isUserDefinableOperator => identical(lexeme, "==") || identical(lexem
e, "~") || identical(lexeme, "[]") || identical(lexeme, "[]=") || identical(lexe
me, "*") || identical(lexeme, "/") || identical(lexeme, "%") || identical(lexeme
, "~/") || identical(lexeme, "+") || identical(lexeme, "-") || identical(lexeme,
"<<") || identical(lexeme, ">>") || identical(lexeme, ">=") || identical(lexeme
, ">") || identical(lexeme, "<=") || identical(lexeme, "<") || identical(lexeme,
"&") || identical(lexeme, "^") || identical(lexeme, "|"); | 2113 bool get isUserDefinableOperator => identical(lexeme, "==") || identical(lexem
e, "~") || identical(lexeme, "[]") || identical(lexeme, "[]=") || identical(lexe
me, "*") || identical(lexeme, "/") || identical(lexeme, "%") || identical(lexeme
, "~/") || identical(lexeme, "+") || identical(lexeme, "-") || identical(lexeme,
"<<") || identical(lexeme, ">>") || identical(lexeme, ">=") || identical(lexeme
, ">") || identical(lexeme, "<=") || identical(lexeme, "<") || identical(lexeme,
"&") || identical(lexeme, "^") || identical(lexeme, "|"); |
| 2142 } | 2114 } |
| 2143 class TokenType_EOF extends TokenType { | 2115 class TokenType_EOF extends TokenType { |
| 2144 TokenType_EOF(String name, int ordinal, TokenClass arg0, String arg1) : super.
con2(name, ordinal, arg0, arg1); | 2116 TokenType_EOF(String name, int ordinal, TokenClass arg0, String arg1) : super.
con2(name, ordinal, arg0, arg1); |
| 2145 String toString() => "-eof-"; | 2117 String toString() => "-eof-"; |
| 2146 } | 2118 } |
| OLD | NEW |