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

Side by Side Diff: pkg/front_end/lib/src/fasta/analyzer/token_utils.dart

Issue 2732363002: Add support for documentation comments to most of AstBuilder. (Closed)
Patch Set: Created 3 years, 9 months 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 fasta.analyzer.token_utils; 5 library fasta.analyzer.token_utils;
6 6
7 import '../parser/error_kind.dart' show ErrorKind; 7 import '../parser/error_kind.dart' show ErrorKind;
8 8
9 import '../scanner/error_token.dart' show ErrorToken; 9 import '../scanner/error_token.dart' show ErrorToken;
10 10
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 103
104 /// Handles an error found during [convertTokens]. 104 /// Handles an error found during [convertTokens].
105 /// 105 ///
106 /// Intended to be overridden by derived classes; by default, does nothing. 106 /// Intended to be overridden by derived classes; by default, does nothing.
107 void reportError(analyzer.ScannerErrorCode errorCode, int offset, 107 void reportError(analyzer.ScannerErrorCode errorCode, int offset,
108 List<Object> arguments) {} 108 List<Object> arguments) {}
109 109
110 /// Translates a sequence of fasta comment tokens to the corresponding 110 /// Translates a sequence of fasta comment tokens to the corresponding
111 /// analyzer tokens. 111 /// analyzer tokens.
112 analyzer.CommentToken translateCommentTokens(Token token) { 112 analyzer.CommentToken translateCommentTokens(Token token) {
113 analyzer.CommentToken translateOneComment(Token token) {
114 // TODO(paulberry,ahe): It would be nice if the scanner gave us an
115 // easier way to distinguish between the two types of comment.
116 var type = token.value.startsWith('/*')
117 ? TokenType.MULTI_LINE_COMMENT
118 : TokenType.SINGLE_LINE_COMMENT;
119 return new analyzer.CommentToken(type, token.value, token.charOffset);
120 }
121
122 analyzer.CommentToken head; 113 analyzer.CommentToken head;
123 if (token != null) { 114 if (token != null) {
124 head = translateOneComment(token); 115 head = toAnalyzerCommentToken(token);
125 analyzer.CommentToken tail = head; 116 analyzer.CommentToken tail = head;
126 token = token.next; 117 token = token.next;
127 while (token != null) { 118 while (token != null) {
128 tail = tail.setNext(translateOneComment(token)); 119 tail = tail.setNext(toAnalyzerCommentToken(token));
129 token = token.next; 120 token = token.next;
130 } 121 }
131 } 122 }
132 return head; 123 return head;
133 } 124 }
134 125
135 /// Translates a single fasta non-comment token to the corresponding analyzer 126 /// Translates a single fasta non-comment token to the corresponding analyzer
136 /// token. 127 /// token.
137 /// 128 ///
138 /// [precedingComments] is not `null`, the translated token is pointed to it. 129 /// [precedingComments] is not `null`, the translated token is pointed to it.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 return _makeError( 205 return _makeError(
215 analyzer.ScannerErrorCode.ILLEGAL_CHARACTER, [token.character]); 206 analyzer.ScannerErrorCode.ILLEGAL_CHARACTER, [token.character]);
216 case ErrorKind.UnexpectedDollarInString: 207 case ErrorKind.UnexpectedDollarInString:
217 return null; 208 return null;
218 default: 209 default:
219 throw new UnimplementedError('$errorCode'); 210 throw new UnimplementedError('$errorCode');
220 } 211 }
221 } 212 }
222 } 213 }
223 214
215 /// Converts a single Fasta comment token to an analyzer comment token.
216 analyzer.CommentToken toAnalyzerCommentToken(Token token) {
217 // TODO(paulberry,ahe): It would be nice if the scanner gave us an
218 // easier way to distinguish between the two types of comment.
219 var type = token.value.startsWith('/*')
220 ? TokenType.MULTI_LINE_COMMENT
221 : TokenType.SINGLE_LINE_COMMENT;
222 return new analyzer.CommentToken(type, token.value, token.charOffset);
223 }
224
224 /// Converts a stream of Analyzer tokens (starting with [token] and continuing 225 /// Converts a stream of Analyzer tokens (starting with [token] and continuing
225 /// to EOF) to a stream of Fasta tokens. 226 /// to EOF) to a stream of Fasta tokens.
226 /// 227 ///
227 /// TODO(paulberry): Analyzer tokens do not record error conditions, so a round 228 /// TODO(paulberry): Analyzer tokens do not record error conditions, so a round
228 /// trip through this function and [toAnalyzerTokenStream] will lose error 229 /// trip through this function and [toAnalyzerTokenStream] will lose error
229 /// information. 230 /// information.
230 Token fromAnalyzerTokenStream(analyzer.Token analyzerToken) { 231 Token fromAnalyzerTokenStream(analyzer.Token analyzerToken) {
231 Token tokenHead = new SymbolToken(EOF_INFO, -1); 232 Token tokenHead = new SymbolToken(EOF_INFO, -1);
232 Token tokenTail = tokenHead; 233 Token tokenTail = tokenHead;
233 234
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 case PERIOD_PERIOD_PERIOD_TOKEN: 782 case PERIOD_PERIOD_PERIOD_TOKEN:
782 return TokenType.PERIOD_PERIOD_PERIOD; 783 return TokenType.PERIOD_PERIOD_PERIOD;
783 // case GENERIC_METHOD_TYPE_LIST_TOKEN: 784 // case GENERIC_METHOD_TYPE_LIST_TOKEN:
784 // return TokenType.GENERIC_METHOD_TYPE_LIST; 785 // return TokenType.GENERIC_METHOD_TYPE_LIST;
785 // case GENERIC_METHOD_TYPE_ASSIGN_TOKEN: 786 // case GENERIC_METHOD_TYPE_ASSIGN_TOKEN:
786 // return TokenType.GENERIC_METHOD_TYPE_ASSIGN; 787 // return TokenType.GENERIC_METHOD_TYPE_ASSIGN;
787 default: 788 default:
788 return internalError("Unhandled token ${token.info}"); 789 return internalError("Unhandled token ${token.info}");
789 } 790 }
790 } 791 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698