Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: pkg/analyzer/lib/src/generated/scanner.dart

Issue 1434863003: initial generic method comment parsing (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: re-sort members Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 * Initialize a newly created token to represent a token of the given [type] 239 * Initialize a newly created token to represent a token of the given [type]
240 * with the given [value] at the given [offset]. 240 * with the given [value] at the given [offset].
241 */ 241 */
242 CommentToken(TokenType type, String value, int offset) 242 CommentToken(TokenType type, String value, int offset)
243 : super(type, value, offset); 243 : super(type, value, offset);
244 244
245 @override 245 @override
246 CommentToken copy() => new CommentToken(type, _value, offset); 246 CommentToken copy() => new CommentToken(type, _value, offset);
247 } 247 }
248 248
249
249 /** 250 /**
250 * A documentation comment token. 251 * A documentation comment token.
251 */ 252 */
252 class DocumentationCommentToken extends CommentToken { 253 class DocumentationCommentToken extends CommentToken {
253 /** 254 /**
254 * The references embedded within the documentation comment. 255 * The references embedded within the documentation comment.
255 * This list will be empty unless this is a documentation comment that has 256 * This list will be empty unless this is a documentation comment that has
256 * references embedded within it. 257 * references embedded within it.
257 */ 258 */
258 final List<Token> references = <Token>[]; 259 final List<Token> references = <Token>[];
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 * empty. 717 * empty.
717 */ 718 */
718 int _stackEnd = -1; 719 int _stackEnd = -1;
719 720
720 /** 721 /**
721 * A flag indicating whether any unmatched groups were found during the parse. 722 * A flag indicating whether any unmatched groups were found during the parse.
722 */ 723 */
723 bool _hasUnmatchedGroups = false; 724 bool _hasUnmatchedGroups = false;
724 725
725 /** 726 /**
727 * A flag indicating whether to parse generic method comments, of the form
728 * `/*=T*/` and `/*<T>*/`.
729 */
730 bool scanGenericMethodComments = false;
731
732 /**
726 * Initialize a newly created scanner to scan characters from the given 733 * Initialize a newly created scanner to scan characters from the given
727 * [source]. The given character [_reader] will be used to read the characters 734 * [source]. The given character [_reader] will be used to read the characters
728 * in the source. The given [_errorListener] will be informed of any errors 735 * in the source. The given [_errorListener] will be informed of any errors
729 * that are found. 736 * that are found.
730 */ 737 */
731 Scanner(this.source, this._reader, this._errorListener) { 738 Scanner(this.source, this._reader, this._errorListener) {
732 _tokens = new Token(TokenType.EOF, -1); 739 _tokens = new Token(TokenType.EOF, -1);
733 _tokens.setNext(_tokens); 740 _tokens.setNext(_tokens);
734 _tail = _tokens; 741 _tail = _tokens;
735 _tokenStart = -1; 742 _tokenStart = -1;
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 token = new BeginTokenWithComment(type, _tokenStart, _firstComment); 1012 token = new BeginTokenWithComment(type, _tokenStart, _firstComment);
1006 _firstComment = null; 1013 _firstComment = null;
1007 _lastComment = null; 1014 _lastComment = null;
1008 } 1015 }
1009 _tail = _tail.setNext(token); 1016 _tail = _tail.setNext(token);
1010 _groupingStack.add(token); 1017 _groupingStack.add(token);
1011 _stackEnd++; 1018 _stackEnd++;
1012 } 1019 }
1013 1020
1014 void _appendCommentToken(TokenType type, String value) { 1021 void _appendCommentToken(TokenType type, String value) {
1015 // Ignore comment tokens if client specified that it doesn't need them. 1022 CommentToken token = null;
1016 if (!_preserveComments) { 1023 TokenType genericComment = _matchGenericMethodCommentType(value);
1024 if (genericComment != null) {
1025 token = new CommentToken(genericComment, value, _tokenStart);
1026 } else if (!_preserveComments) {
1027 // Ignore comment tokens if client specified that it doesn't need them.
1017 return; 1028 return;
1018 }
1019 // OK, remember comment tokens.
1020 CommentToken token;
1021 if (_isDocumentationComment(value)) {
1022 token = new DocumentationCommentToken(type, value, _tokenStart);
1023 } else { 1029 } else {
1024 token = new CommentToken(type, value, _tokenStart); 1030 // OK, remember comment tokens.
1031 if (_isDocumentationComment(value)) {
1032 token = new DocumentationCommentToken(type, value, _tokenStart);
1033 } else {
1034 token = new CommentToken(type, value, _tokenStart);
1035 }
1025 } 1036 }
1026 if (_firstComment == null) { 1037 if (_firstComment == null) {
1027 _firstComment = token; 1038 _firstComment = token;
1028 _lastComment = _firstComment; 1039 _lastComment = _firstComment;
1029 } else { 1040 } else {
1030 _lastComment = _lastComment.setNext(token); 1041 _lastComment = _lastComment.setNext(token);
1031 } 1042 }
1032 } 1043 }
1033 1044
1034 void _appendEndToken(TokenType type, TokenType beginType) { 1045 void _appendEndToken(TokenType type, TokenType beginType) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 } 1156 }
1146 // 1157 //
1147 // We should never get to this point because we wouldn't be inside a string 1158 // We should never get to this point because we wouldn't be inside a string
1148 // interpolation expression unless we had previously found the start of the 1159 // interpolation expression unless we had previously found the start of the
1149 // expression. 1160 // expression.
1150 // 1161 //
1151 return null; 1162 return null;
1152 } 1163 }
1153 1164
1154 /** 1165 /**
1166 * Checks if [value] is the start of a generic method type annotation comment.
1167 *
1168 * This can either be of the form `/*<T>*/` or `/*=T*/`. The token type is
1169 * returned, or null if it was not a generic method comment.
1170 */
1171 TokenType _matchGenericMethodCommentType(String value) {
1172 if (scanGenericMethodComments) {
1173 // Match /*< and >*/
1174 if (StringUtilities.startsWith3(value, 0, 0x2F, 0x2A, 0x3C) &&
1175 StringUtilities.endsWith3(value, 0x3E, 0x2A, 0x2F)) {
1176 return TokenType.GENERIC_METHOD_TYPE_LIST;
1177 }
1178 // Match /*=
1179 if (StringUtilities.startsWith3(value, 0, 0x2F, 0x2A, 0x3D)) {
1180 return TokenType.GENERIC_METHOD_TYPE_ASSIGN;
1181 }
1182 }
1183 return null;
1184 }
1185
1186 /**
1155 * Report an error at the current offset. The [errorCode] is the error code 1187 * Report an error at the current offset. The [errorCode] is the error code
1156 * indicating the nature of the error. The [arguments] are any arguments 1188 * indicating the nature of the error. The [arguments] are any arguments
1157 * needed to complete the error message 1189 * needed to complete the error message
1158 */ 1190 */
1159 void _reportError(ScannerErrorCode errorCode, [List<Object> arguments]) { 1191 void _reportError(ScannerErrorCode errorCode, [List<Object> arguments]) {
1160 _errorListener.onError( 1192 _errorListener.onError(
1161 new AnalysisError(source, _reader.offset, 1, errorCode, arguments)); 1193 new AnalysisError(source, _reader.offset, 1, errorCode, arguments));
1162 } 1194 }
1163 1195
1164 int _select(int choice, TokenType yesType, TokenType noType) { 1196 int _select(int choice, TokenType yesType, TokenType noType) {
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after
2050 * Return the next token in the token stream. 2082 * Return the next token in the token stream.
2051 */ 2083 */
2052 Token get next => _next; 2084 Token get next => _next;
2053 2085
2054 /** 2086 /**
2055 * Return the first comment in the list of comments that precede this token, 2087 * Return the first comment in the list of comments that precede this token,
2056 * or `null` if there are no comments preceding this token. Additional 2088 * or `null` if there are no comments preceding this token. Additional
2057 * comments can be reached by following the token stream using [next] until 2089 * comments can be reached by following the token stream using [next] until
2058 * `null` is returned. 2090 * `null` is returned.
2059 * 2091 *
2060 * For example, if the original contents were "/* one */ /* two */ id", then 2092 * For example, if the original contents were `/* one */ /* two */ id`, then
2061 * the first preceding comment token will have a lexeme of "/* one */" and 2093 * the first preceding comment token will have a lexeme of `/* one */` and
2062 * the next comment token will have a lexeme of "/* two */". 2094 * the next comment token will have a lexeme of `/* two */`.
2063 */ 2095 */
2064 CommentToken get precedingComments => null; 2096 CommentToken get precedingComments => null;
2065 2097
2066 /** 2098 /**
2067 * Apply (add) the given [delta] to this token's offset. 2099 * Apply (add) the given [delta] to this token's offset.
2068 */ 2100 */
2069 void applyDelta(int delta) { 2101 void applyDelta(int delta) {
2070 offset += delta; 2102 offset += delta;
2071 } 2103 }
2072 2104
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
2494 2526
2495 static const TokenType BACKPING = 2527 static const TokenType BACKPING =
2496 const TokenType('BACKPING', TokenClass.NO_CLASS, "`"); 2528 const TokenType('BACKPING', TokenClass.NO_CLASS, "`");
2497 2529
2498 static const TokenType BACKSLASH = 2530 static const TokenType BACKSLASH =
2499 const TokenType('BACKSLASH', TokenClass.NO_CLASS, "\\"); 2531 const TokenType('BACKSLASH', TokenClass.NO_CLASS, "\\");
2500 2532
2501 static const TokenType PERIOD_PERIOD_PERIOD = 2533 static const TokenType PERIOD_PERIOD_PERIOD =
2502 const TokenType('PERIOD_PERIOD_PERIOD', TokenClass.NO_CLASS, "..."); 2534 const TokenType('PERIOD_PERIOD_PERIOD', TokenClass.NO_CLASS, "...");
2503 2535
2536 static const TokenType GENERIC_METHOD_TYPE_LIST =
2537 const TokenType('GENERIC_METHOD_TYPE_LIST');
2538
2539 static const TokenType GENERIC_METHOD_TYPE_ASSIGN =
2540 const TokenType('GENERIC_METHOD_TYPE_ASSIGN');
2541
2504 /** 2542 /**
2505 * The class of the token. 2543 * The class of the token.
2506 */ 2544 */
2507 final TokenClass _tokenClass; 2545 final TokenClass _tokenClass;
2508 2546
2509 /** 2547 /**
2510 * The name of the token type. 2548 * The name of the token type.
2511 */ 2549 */
2512 final String name; 2550 final String name;
2513 2551
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
2662 CommentToken get precedingComments => _precedingComment; 2700 CommentToken get precedingComments => _precedingComment;
2663 2701
2664 void set precedingComments(CommentToken comment) { 2702 void set precedingComments(CommentToken comment) {
2665 _precedingComment = comment; 2703 _precedingComment = comment;
2666 _setCommentParent(_precedingComment); 2704 _setCommentParent(_precedingComment);
2667 } 2705 }
2668 2706
2669 @override 2707 @override
2670 Token copy() => new TokenWithComment(type, offset, precedingComments); 2708 Token copy() => new TokenWithComment(type, offset, precedingComments);
2671 } 2709 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | pkg/analyzer/test/generated/parser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698