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

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

Issue 2899043006: cleanup fasta token classes (Closed)
Patch Set: Created 3 years, 7 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 import '../../scanner/token.dart' show Token, TokenType; 8 import '../../scanner/token.dart' show Token, TokenType;
9 9
10 import 'token_constants.dart' show IDENTIFIER_TOKEN; 10 import 'token_constants.dart' show IDENTIFIER_TOKEN;
11 11
12 import 'string_canonicalizer.dart'; 12 import 'string_canonicalizer.dart';
13 13
14 /** 14 /**
15 * A [SymbolToken] represents the symbol in its precedence info.
16 * Also used for end of file with EOF_INFO.
17 */
18 class SymbolToken extends analyzer.TokenWithComment {
19 SymbolToken(TokenType type, int offset,
20 [analyzer.CommentToken precedingComments])
21 : super(type, offset, precedingComments);
22
23 factory SymbolToken.eof(int charOffset,
24 [analyzer.CommentToken precedingComments]) {
25 var eof =
26 new SyntheticSymbolToken(TokenType.EOF, charOffset, precedingComments);
27 // EOF points to itself so there's always infinite look-ahead.
28 eof.previous = eof;
29 eof.next = eof;
30 return eof;
31 }
32
33 @override
34 String get lexeme => type.value;
35
36 @override
37 String toString() => "SymbolToken(${isEof ? '-eof-' : lexeme})";
38
39 @override
40 Token copy() => isEof
41 ? new SymbolToken.eof(charOffset, precedingComments)
42 : new SymbolToken(type, charOffset, precedingComments);
43 }
44
45 /**
46 * A [SyntheticSymbolToken] represents the symbol in its precedence info
47 * which does not exist in the original source.
48 * For example, if the scanner finds '(' missing a ')'
49 * then it will insert an synthetic ')'.
50 */
51 class SyntheticSymbolToken extends SymbolToken {
52 SyntheticSymbolToken(TokenType type, int charOffset,
53 [analyzer.CommentToken precedingComments])
54 : super(type, charOffset, precedingComments);
55
56 @override
57 int get length => 0;
58
59 @override
60 Token copy() => isEof
61 ? new SymbolToken.eof(charOffset, precedingComments)
62 : new SyntheticSymbolToken(type, charOffset, precedingComments);
63 }
64
65 /**
66 * A [BeginGroupToken] represents a symbol that may be the beginning of
67 * a pair of brackets, i.e., ( { [ < or ${
68 * The [endGroup] token points to the matching closing bracket in case
69 * it can be identified during scanning.
70 */
71 class BeginGroupToken extends SymbolToken
72 implements analyzer.BeginTokenWithComment {
73 Token endGroup;
74
75 BeginGroupToken(TokenType type, int charOffset,
76 [analyzer.CommentToken precedingComments])
77 : super(type, charOffset, precedingComments);
78
79 @override
80 analyzer.Token get endToken => endGroup;
81
82 @override
83 void set endToken(analyzer.Token token) {
84 endGroup = token;
85 }
86
87 @override
88 Token copy() => new BeginGroupToken(type, charOffset, precedingComments);
89 }
90
91 /**
92 * A String-valued token. Represents identifiers, string literals, 15 * A String-valued token. Represents identifiers, string literals,
93 * number literals, comments, and error tokens, using the corresponding 16 * number literals, comments, and error tokens, using the corresponding
94 * precedence info. 17 * precedence info.
95 */ 18 */
96 class StringToken extends analyzer.TokenWithComment 19 class StringToken extends analyzer.TokenWithComment
97 implements analyzer.StringTokenWithComment { 20 implements analyzer.StringTokenWithComment {
98 /** 21 /**
99 * The length threshold above which substring tokens are computed lazily. 22 * The length threshold above which substring tokens are computed lazily.
100 * 23 *
101 * For string tokens that are substrings of the program source, the actual 24 * For string tokens that are substrings of the program source, the actual
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 identical(value, "<=") || 312 identical(value, "<=") ||
390 identical(value, "<") || 313 identical(value, "<") ||
391 identical(value, "&") || 314 identical(value, "&") ||
392 identical(value, "^") || 315 identical(value, "^") ||
393 identical(value, "|"); 316 identical(value, "|");
394 } 317 }
395 318
396 bool isTernaryOperator(String value) => identical(value, "[]="); 319 bool isTernaryOperator(String value) => identical(value, "[]=");
397 320
398 bool isMinusOperator(String value) => identical(value, "-"); 321 bool isMinusOperator(String value) => identical(value, "-");
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/scanner/recover.dart ('k') | pkg/front_end/lib/src/fasta/source/diet_listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698