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

Side by Side Diff: pkg/front_end/lib/src/fasta/scanner/token.dart

Issue 2762103003: fasta.BeginGroupToken implement analyzer.BeginToken (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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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.scanner.token; 5 library fasta.scanner.token;
6 6
7 import '../../scanner/token.dart' as analyzer; 7 import '../../scanner/token.dart' as analyzer;
8 8
9 import 'keyword.dart' show Keyword; 9 import 'keyword.dart' show Keyword;
10 10
11 import 'precedence.dart' show BAD_INPUT_INFO, EOF_INFO, PrecedenceInfo; 11 import 'precedence.dart'
12 show
13 AS_INFO,
14 BAD_INPUT_INFO,
15 EOF_INFO,
16 IDENTIFIER_INFO,
17 IS_INFO,
18 KEYWORD_INFO,
19 MULTI_LINE_COMMENT_INFO,
20 SINGLE_LINE_COMMENT_INFO,
21 PrecedenceInfo;
12 22
13 import 'token_constants.dart' show IDENTIFIER_TOKEN; 23 import 'token_constants.dart' show IDENTIFIER_TOKEN;
14 24
15 import 'string_canonicalizer.dart'; 25 import 'string_canonicalizer.dart';
16 26
17 /** 27 /**
18 * A token that doubles as a linked list. 28 * A token that doubles as a linked list.
19 */ 29 */
20 abstract class Token implements analyzer.TokenWithComment { 30 abstract class Token implements analyzer.TokenWithComment {
21 /** 31 /**
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 148
139 bool get isBuiltInIdentifier => false; 149 bool get isBuiltInIdentifier => false;
140 150
141 @override 151 @override
142 bool get isOperator => info.isOperator; 152 bool get isOperator => info.isOperator;
143 153
144 @override 154 @override
145 bool get isUserDefinableOperator => info.isUserDefinableOperator; 155 bool get isUserDefinableOperator => info.isUserDefinableOperator;
146 156
147 @override 157 @override
148 analyzer.TokenType get type => info; 158 analyzer.TokenType get type {
159 // Analyzer has a different concept of what is a Keyword type.
160 return info == AS_INFO || info == IS_INFO ? KEYWORD_INFO : info;
161 }
149 162
150 @override 163 @override
151 int get offset => charOffset; 164 int get offset => charOffset;
152 165
153 @override 166 @override
154 set offset(int newOffset) { 167 set offset(int newOffset) {
155 charOffset = newOffset; 168 charOffset = newOffset;
156 } 169 }
157 170
158 @override 171 @override
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 @override 271 @override
259 Token copyWithoutComments() => new SymbolToken(info, charOffset); 272 Token copyWithoutComments() => new SymbolToken(info, charOffset);
260 } 273 }
261 274
262 /** 275 /**
263 * A [BeginGroupToken] represents a symbol that may be the beginning of 276 * A [BeginGroupToken] represents a symbol that may be the beginning of
264 * a pair of brackets, i.e., ( { [ < or ${ 277 * a pair of brackets, i.e., ( { [ < or ${
265 * The [endGroup] token points to the matching closing bracked in case 278 * The [endGroup] token points to the matching closing bracked in case
266 * it can be identified during scanning. 279 * it can be identified during scanning.
267 */ 280 */
268 class BeginGroupToken extends SymbolToken { 281 class BeginGroupToken extends SymbolToken implements analyzer.BeginToken {
269 Token endGroup; 282 Token endGroup;
270 283
271 BeginGroupToken(PrecedenceInfo info, int charOffset) 284 BeginGroupToken(PrecedenceInfo info, int charOffset)
272 : super(info, charOffset); 285 : super(info, charOffset);
286
287 @override
288 analyzer.Token get endToken => endGroup;
289
290 @override
291 void set endToken(analyzer.Token token) {
292 endGroup = token as Token;
Paul Berry 2017/03/21 14:16:01 This cast shouldn't be required now that the dynam
danrubel 2017/03/21 15:49:24 Done.
293 }
273 } 294 }
274 295
275 /** 296 /**
276 * A keyword token. 297 * A keyword token.
277 */ 298 */
278 class KeywordToken extends Token { 299 class KeywordToken extends Token {
279 final Keyword keyword; 300 final Keyword keyword;
280 301
281 KeywordToken(this.keyword, int charOffset) : super(charOffset); 302 KeywordToken(this.keyword, int charOffset) : super(charOffset);
282 303
(...skipping 12 matching lines...) Expand all
295 // fixed. 316 // fixed.
296 return keyword.isBuiltIn || identical("deferred", lexeme); 317 return keyword.isBuiltIn || identical("deferred", lexeme);
297 } 318 }
298 319
299 String toString() => "KeywordToken($lexeme)"; 320 String toString() => "KeywordToken($lexeme)";
300 321
301 @override 322 @override
302 Token copyWithoutComments() => new KeywordToken(keyword, charOffset); 323 Token copyWithoutComments() => new KeywordToken(keyword, charOffset);
303 324
304 @override 325 @override
305 Object value() => keyword; 326 Object value() {
327 // Analyzer has different set of keyword tokens
328 // TODO(danrubel): Remove special case for "deferred" once dartbug.com/29069
329 // is fixed.
330 return isPseudo && !identical("deferred", lexeme) ? lexeme : keyword;
331 }
332
333 @override
334 analyzer.TokenType get type {
335 // Analyzer considers pseudo-keywords to be identifiers
336 // TODO(danrubel): Remove special case for "deferred" once dartbug.com/29069
337 // is fixed.
338 return isPseudo && !identical("deferred", lexeme)
339 ? IDENTIFIER_INFO
340 : KEYWORD_INFO;
341 }
306 } 342 }
307 343
308 /** 344 /**
309 * A String-valued token. Represents identifiers, string literals, 345 * A String-valued token. Represents identifiers, string literals,
310 * number literals, comments, and error tokens, using the corresponding 346 * number literals, comments, and error tokens, using the corresponding
311 * precedence info. 347 * precedence info.
312 */ 348 */
313 class StringToken extends Token implements analyzer.StringToken { 349 class StringToken extends Token implements analyzer.StringToken {
314 /** 350 /**
315 * The length threshold above which substring tokens are computed lazily. 351 * The length threshold above which substring tokens are computed lazily.
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 identical(value, "<=") || 628 identical(value, "<=") ||
593 identical(value, "<") || 629 identical(value, "<") ||
594 identical(value, "&") || 630 identical(value, "&") ||
595 identical(value, "^") || 631 identical(value, "^") ||
596 identical(value, "|"); 632 identical(value, "|");
597 } 633 }
598 634
599 bool isTernaryOperator(String value) => identical(value, "[]="); 635 bool isTernaryOperator(String value) => identical(value, "[]=");
600 636
601 bool isMinusOperator(String value) => identical(value, "-"); 637 bool isMinusOperator(String value) => identical(value, "-");
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/fasta/token_utils.dart ('k') | pkg/front_end/test/precedence_info_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698