| 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 interface Scanner { | 5 interface Scanner { |
| 6 Token tokenize(); | 6 Token tokenize(); |
| 7 } | 7 } |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Common base class for a Dart scanner. | 10 * Common base class for a Dart scanner. |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 appendPrecedenceToken(TILDE_INFO); | 292 appendPrecedenceToken(TILDE_INFO); |
| 293 return next; | 293 return next; |
| 294 } | 294 } |
| 295 } | 295 } |
| 296 | 296 |
| 297 int tokenizeOpenSquareBracket(int next) { | 297 int tokenizeOpenSquareBracket(int next) { |
| 298 // [ [] []= | 298 // [ [] []= |
| 299 next = advance(); | 299 next = advance(); |
| 300 if (next === $CLOSE_SQUARE_BRACKET) { | 300 if (next === $CLOSE_SQUARE_BRACKET) { |
| 301 Token token = previousToken(); | 301 Token token = previousToken(); |
| 302 if (token is KeywordToken && token.value == Keyword.OPERATOR) { | 302 if (token is KeywordToken && token.value.stringValue === 'operator') { |
| 303 return select($EQ, INDEX_EQ_INFO, INDEX_INFO); | 303 return select($EQ, INDEX_EQ_INFO, INDEX_INFO); |
| 304 } | 304 } |
| 305 } | 305 } |
| 306 appendBeginGroup(OPEN_SQUARE_BRACKET_INFO, "["); | 306 appendBeginGroup(OPEN_SQUARE_BRACKET_INFO, "["); |
| 307 return next; | 307 return next; |
| 308 } | 308 } |
| 309 | 309 |
| 310 int tokenizeCaret(int next) { | 310 int tokenizeCaret(int next) { |
| 311 // ^ ^= | 311 // ^ ^= |
| 312 return select($EQ, CARET_EQ_INFO, CARET_INFO); | 312 return select($EQ, CARET_EQ_INFO, CARET_INFO); |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 } else if (next < 128) { | 638 } else if (next < 128) { |
| 639 appendKeywordToken(state.keyword); | 639 appendKeywordToken(state.keyword); |
| 640 return next; | 640 return next; |
| 641 } else { | 641 } else { |
| 642 return tokenizeIdentifier(next, start, allowDollar); | 642 return tokenizeIdentifier(next, start, allowDollar); |
| 643 } | 643 } |
| 644 } | 644 } |
| 645 | 645 |
| 646 int tokenizeIdentifier(int next, int start, bool allowDollar) { | 646 int tokenizeIdentifier(int next, int start, bool allowDollar) { |
| 647 bool isAscii = true; | 647 bool isAscii = true; |
| 648 bool isDynamicBuiltIn = false; |
| 649 |
| 650 if (next === $D) { |
| 651 next = advance(); |
| 652 if (next === $y) { |
| 653 next = advance(); |
| 654 if (next === $n) { |
| 655 next = advance(); |
| 656 if (next === $a) { |
| 657 next = advance(); |
| 658 if (next === $m) { |
| 659 next = advance(); |
| 660 if (next === $i) { |
| 661 next = advance(); |
| 662 if (next === $c) { |
| 663 isDynamicBuiltIn = true; |
| 664 next = advance(); |
| 665 } |
| 666 } |
| 667 } |
| 668 } |
| 669 } |
| 670 } |
| 671 } |
| 672 |
| 648 while (true) { | 673 while (true) { |
| 649 if (($a <= next && next <= $z) || | 674 if (($a <= next && next <= $z) || |
| 650 ($A <= next && next <= $Z) || | 675 ($A <= next && next <= $Z) || |
| 651 ($0 <= next && next <= $9) || | 676 ($0 <= next && next <= $9) || |
| 652 next === $_ || | 677 next === $_ || |
| 653 (next === $$ && allowDollar)) { | 678 (next === $$ && allowDollar)) { |
| 679 isDynamicBuiltIn = false; |
| 654 next = advance(); | 680 next = advance(); |
| 655 } else if (next < 128) { | 681 } else if (next < 128) { |
| 656 // Identifier ends here. | 682 // Identifier ends here. |
| 657 if (start == byteOffset) { | 683 if (start == byteOffset) { |
| 658 throw new MalformedInputException("expected identifier not found", | 684 throw new MalformedInputException("expected identifier not found", |
| 659 charOffset); | 685 charOffset); |
| 660 } | 686 } |
| 661 if (isAscii) { | 687 if (isDynamicBuiltIn) { |
| 688 appendKeywordToken(Keyword.DYNAMIC); |
| 689 } else if (isAscii) { |
| 662 appendByteStringToken(IDENTIFIER_INFO, asciiString(start, 0)); | 690 appendByteStringToken(IDENTIFIER_INFO, asciiString(start, 0)); |
| 663 } else { | 691 } else { |
| 664 appendByteStringToken(IDENTIFIER_INFO, utf8String(start, -1)); | 692 appendByteStringToken(IDENTIFIER_INFO, utf8String(start, -1)); |
| 665 } | 693 } |
| 666 return next; | 694 return next; |
| 667 } else { | 695 } else { |
| 696 isDynamicBuiltIn = false; |
| 668 int nonAsciiStart = byteOffset; | 697 int nonAsciiStart = byteOffset; |
| 669 do { | 698 do { |
| 670 next = nextByte(); | 699 next = nextByte(); |
| 671 } while (next > 127); | 700 } while (next > 127); |
| 672 String string = utf8String(nonAsciiStart, -1).slowToString(); | 701 String string = utf8String(nonAsciiStart, -1).slowToString(); |
| 673 isAscii = false; | 702 isAscii = false; |
| 674 int byteLength = nonAsciiStart - byteOffset; | 703 int byteLength = nonAsciiStart - byteOffset; |
| 675 addToCharOffset(string.length - byteLength); | 704 addToCharOffset(string.length - byteLength); |
| 676 } | 705 } |
| 677 } | 706 } |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 charOffset); | 861 charOffset); |
| 833 } | 862 } |
| 834 } | 863 } |
| 835 | 864 |
| 836 class MalformedInputException { | 865 class MalformedInputException { |
| 837 final String message; | 866 final String message; |
| 838 final position; | 867 final position; |
| 839 MalformedInputException(this.message, this.position); | 868 MalformedInputException(this.message, this.position); |
| 840 toString() => message; | 869 toString() => message; |
| 841 } | 870 } |
| OLD | NEW |