| 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 'instrumentation.dart'; | 10 import 'instrumentation.dart'; |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 /** | 232 /** |
| 233 * A `CommentToken` is a token representing a comment. | 233 * A `CommentToken` is a token representing a comment. |
| 234 */ | 234 */ |
| 235 class CommentToken extends StringToken { | 235 class CommentToken extends StringToken { |
| 236 /** | 236 /** |
| 237 * The [Token] that contains this comment. | 237 * The [Token] that contains this comment. |
| 238 */ | 238 */ |
| 239 Token parent; | 239 Token parent; |
| 240 | 240 |
| 241 /** | 241 /** |
| 242 * Initialize a newly created token to represent a token of the given [type] |
| 243 * with the given [value] at the given [offset]. |
| 244 */ |
| 245 CommentToken(TokenType type, String value, int offset) |
| 246 : super(type, value, offset); |
| 247 |
| 248 @override |
| 249 CommentToken copy() => new CommentToken(type, _value, offset); |
| 250 } |
| 251 |
| 252 /** |
| 253 * A documentation comment token. |
| 254 */ |
| 255 class DocumentationCommentToken extends CommentToken { |
| 256 /** |
| 242 * The references embedded within the documentation comment. | 257 * The references embedded within the documentation comment. |
| 243 * This list will be empty unless this is a documentation comment that has | 258 * This list will be empty unless this is a documentation comment that has |
| 244 * references embedded within it. | 259 * references embedded within it. |
| 245 */ | 260 */ |
| 246 final List<Token> references = <Token>[]; | 261 final List<Token> references = <Token>[]; |
| 247 | 262 |
| 248 /** | 263 /** |
| 249 * Initialize a newly created token to represent a token of the given [type] | 264 * Initialize a newly created token to represent a token of the given [type] |
| 250 * with the given [value] at the given [offset]. | 265 * with the given [value] at the given [offset]. |
| 251 */ | 266 */ |
| 252 CommentToken(TokenType type, String value, int offset) | 267 DocumentationCommentToken(TokenType type, String value, int offset) |
| 253 : super(type, value, offset); | 268 : super(type, value, offset); |
| 254 | 269 |
| 255 @override | 270 @override |
| 256 CommentToken copy() => new CommentToken(type, _value, offset); | 271 CommentToken copy() => new DocumentationCommentToken(type, _value, offset); |
| 257 } | 272 } |
| 258 | 273 |
| 259 /** | 274 /** |
| 260 * The enumeration `Keyword` defines the keywords in the Dart programming | 275 * The enumeration `Keyword` defines the keywords in the Dart programming |
| 261 * language. | 276 * language. |
| 262 */ | 277 */ |
| 263 class Keyword { | 278 class Keyword { |
| 264 static const Keyword ASSERT = const Keyword('ASSERT', "assert"); | 279 static const Keyword ASSERT = const Keyword('ASSERT', "assert"); |
| 265 | 280 |
| 266 static const Keyword BREAK = const Keyword('BREAK', "break"); | 281 static const Keyword BREAK = const Keyword('BREAK', "break"); |
| (...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 _groupingStack.add(token); | 1004 _groupingStack.add(token); |
| 990 _stackEnd++; | 1005 _stackEnd++; |
| 991 } | 1006 } |
| 992 | 1007 |
| 993 void _appendCommentToken(TokenType type, String value) { | 1008 void _appendCommentToken(TokenType type, String value) { |
| 994 // Ignore comment tokens if client specified that it doesn't need them. | 1009 // Ignore comment tokens if client specified that it doesn't need them. |
| 995 if (!_preserveComments) { | 1010 if (!_preserveComments) { |
| 996 return; | 1011 return; |
| 997 } | 1012 } |
| 998 // OK, remember comment tokens. | 1013 // OK, remember comment tokens. |
| 1014 CommentToken token; |
| 1015 if (_isDocumentationComment(value)) { |
| 1016 token = new DocumentationCommentToken(type, value, _tokenStart); |
| 1017 } else { |
| 1018 token = new CommentToken(type, value, _tokenStart); |
| 1019 } |
| 999 if (_firstComment == null) { | 1020 if (_firstComment == null) { |
| 1000 _firstComment = new CommentToken(type, value, _tokenStart); | 1021 _firstComment = token; |
| 1001 _lastComment = _firstComment; | 1022 _lastComment = _firstComment; |
| 1002 } else { | 1023 } else { |
| 1003 _lastComment = | 1024 _lastComment = _lastComment.setNext(token); |
| 1004 _lastComment.setNext(new CommentToken(type, value, _tokenStart)); | |
| 1005 } | 1025 } |
| 1006 } | 1026 } |
| 1007 | 1027 |
| 1008 void _appendEndToken(TokenType type, TokenType beginType) { | 1028 void _appendEndToken(TokenType type, TokenType beginType) { |
| 1009 Token token; | 1029 Token token; |
| 1010 if (_firstComment == null) { | 1030 if (_firstComment == null) { |
| 1011 token = new Token(type, _tokenStart); | 1031 token = new Token(type, _tokenStart); |
| 1012 } else { | 1032 } else { |
| 1013 token = new TokenWithComment(type, _tokenStart, _firstComment); | 1033 token = new TokenWithComment(type, _tokenStart, _firstComment); |
| 1014 _firstComment = null; | 1034 _firstComment = null; |
| (...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1773 int _tokenizeTilde(int next) { | 1793 int _tokenizeTilde(int next) { |
| 1774 // ~ ~/ ~/= | 1794 // ~ ~/ ~/= |
| 1775 next = _reader.advance(); | 1795 next = _reader.advance(); |
| 1776 if (next == 0x2F) { | 1796 if (next == 0x2F) { |
| 1777 return _select(0x3D, TokenType.TILDE_SLASH_EQ, TokenType.TILDE_SLASH); | 1797 return _select(0x3D, TokenType.TILDE_SLASH_EQ, TokenType.TILDE_SLASH); |
| 1778 } else { | 1798 } else { |
| 1779 _appendTokenOfType(TokenType.TILDE); | 1799 _appendTokenOfType(TokenType.TILDE); |
| 1780 return next; | 1800 return next; |
| 1781 } | 1801 } |
| 1782 } | 1802 } |
| 1803 |
| 1804 /** |
| 1805 * Checks if [value] is a single-line or multi-line comment. |
| 1806 */ |
| 1807 static bool _isDocumentationComment(String value) { |
| 1808 return StringUtilities.startsWith3(value, 0, 0x2F, 0x2F, 0x2F) || |
| 1809 StringUtilities.startsWith3(value, 0, 0x2F, 0x2A, 0x2A); |
| 1810 } |
| 1783 } | 1811 } |
| 1784 | 1812 |
| 1785 /** | 1813 /** |
| 1786 * The enumeration `ScannerErrorCode` defines the error codes used for errors | 1814 * The enumeration `ScannerErrorCode` defines the error codes used for errors |
| 1787 * detected by the scanner. | 1815 * detected by the scanner. |
| 1788 */ | 1816 */ |
| 1789 class ScannerErrorCode extends ErrorCode { | 1817 class ScannerErrorCode extends ErrorCode { |
| 1790 static const ScannerErrorCode ILLEGAL_CHARACTER = | 1818 static const ScannerErrorCode ILLEGAL_CHARACTER = |
| 1791 const ScannerErrorCode('ILLEGAL_CHARACTER', "Illegal character {0}"); | 1819 const ScannerErrorCode('ILLEGAL_CHARACTER', "Illegal character {0}"); |
| 1792 | 1820 |
| (...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2620 CommentToken get precedingComments => _precedingComment; | 2648 CommentToken get precedingComments => _precedingComment; |
| 2621 | 2649 |
| 2622 void set precedingComments(CommentToken comment) { | 2650 void set precedingComments(CommentToken comment) { |
| 2623 _precedingComment = comment; | 2651 _precedingComment = comment; |
| 2624 _setCommentParent(_precedingComment); | 2652 _setCommentParent(_precedingComment); |
| 2625 } | 2653 } |
| 2626 | 2654 |
| 2627 @override | 2655 @override |
| 2628 Token copy() => new TokenWithComment(type, offset, precedingComments); | 2656 Token copy() => new TokenWithComment(type, offset, precedingComments); |
| 2629 } | 2657 } |
| OLD | NEW |