OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 engine.scanner; | 5 library engine.scanner; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'error.dart'; | 9 import 'error.dart'; |
10 import 'java_engine.dart'; | 10 import 'java_engine.dart'; |
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 * empty. | 716 * empty. |
717 */ | 717 */ |
718 int _stackEnd = -1; | 718 int _stackEnd = -1; |
719 | 719 |
720 /** | 720 /** |
721 * A flag indicating whether any unmatched groups were found during the parse. | 721 * A flag indicating whether any unmatched groups were found during the parse. |
722 */ | 722 */ |
723 bool _hasUnmatchedGroups = false; | 723 bool _hasUnmatchedGroups = false; |
724 | 724 |
725 /** | 725 /** |
726 * A flag indicating whether null-aware operators ('?.', '??', and '??=') | |
727 * should be tokenized. | |
728 */ | |
729 bool enableNullAwareOperators = false; | |
730 | |
731 /** | |
732 * Initialize a newly created scanner to scan characters from the given | 726 * Initialize a newly created scanner to scan characters from the given |
733 * [source]. The given character [_reader] will be used to read the characters | 727 * [source]. The given character [_reader] will be used to read the characters |
734 * in the source. The given [_errorListener] will be informed of any errors | 728 * in the source. The given [_errorListener] will be informed of any errors |
735 * that are found. | 729 * that are found. |
736 */ | 730 */ |
737 Scanner(this.source, this._reader, this._errorListener) { | 731 Scanner(this.source, this._reader, this._errorListener) { |
738 _tokens = new Token(TokenType.EOF, -1); | 732 _tokens = new Token(TokenType.EOF, -1); |
739 _tokens.setNext(_tokens); | 733 _tokens.setNext(_tokens); |
740 _tail = _tokens; | 734 _tail = _tokens; |
741 _tokenStart = -1; | 735 _tokenStart = -1; |
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1657 return _reader.advance(); | 1651 return _reader.advance(); |
1658 } else { | 1652 } else { |
1659 _appendTokenOfType(TokenType.PLUS); | 1653 _appendTokenOfType(TokenType.PLUS); |
1660 return next; | 1654 return next; |
1661 } | 1655 } |
1662 } | 1656 } |
1663 | 1657 |
1664 int _tokenizeQuestion() { | 1658 int _tokenizeQuestion() { |
1665 // ? ?. ?? ??= | 1659 // ? ?. ?? ??= |
1666 int next = _reader.advance(); | 1660 int next = _reader.advance(); |
1667 if (enableNullAwareOperators && next == 0x2E) { | 1661 if (next == 0x2E) { |
1668 // '.' | 1662 // '.' |
1669 _appendTokenOfType(TokenType.QUESTION_PERIOD); | 1663 _appendTokenOfType(TokenType.QUESTION_PERIOD); |
1670 return _reader.advance(); | 1664 return _reader.advance(); |
1671 } else if (enableNullAwareOperators && next == 0x3F) { | 1665 } else if (next == 0x3F) { |
1672 // '?' | 1666 // '?' |
1673 next = _reader.advance(); | 1667 next = _reader.advance(); |
1674 if (next == 0x3D) { | 1668 if (next == 0x3D) { |
1675 // '=' | 1669 // '=' |
1676 _appendTokenOfType(TokenType.QUESTION_QUESTION_EQ); | 1670 _appendTokenOfType(TokenType.QUESTION_QUESTION_EQ); |
1677 return _reader.advance(); | 1671 return _reader.advance(); |
1678 } else { | 1672 } else { |
1679 _appendTokenOfType(TokenType.QUESTION_QUESTION); | 1673 _appendTokenOfType(TokenType.QUESTION_QUESTION); |
1680 return next; | 1674 return next; |
1681 } | 1675 } |
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2670 CommentToken get precedingComments => _precedingComment; | 2664 CommentToken get precedingComments => _precedingComment; |
2671 | 2665 |
2672 void set precedingComments(CommentToken comment) { | 2666 void set precedingComments(CommentToken comment) { |
2673 _precedingComment = comment; | 2667 _precedingComment = comment; |
2674 _setCommentParent(_precedingComment); | 2668 _setCommentParent(_precedingComment); |
2675 } | 2669 } |
2676 | 2670 |
2677 @override | 2671 @override |
2678 Token copy() => new TokenWithComment(type, offset, precedingComments); | 2672 Token copy() => new TokenWithComment(type, offset, precedingComments); |
2679 } | 2673 } |
OLD | NEW |