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

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

Issue 2890523002: merge fasta.Token into analyzer.Token (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.array_based_scanner; 5 library fasta.scanner.array_based_scanner;
6 6
7 import 'error_token.dart' show ErrorToken, UnmatchedToken; 7 import 'error_token.dart' show ErrorToken, UnmatchedToken;
8 8
9 import '../../scanner/token.dart' show Keyword, TokenType; 9 import '../../scanner/token.dart'
10 show Keyword, KeywordTokenWithComment, Token, TokenType;
10 11
11 import 'token.dart' 12 import 'token.dart'
12 show 13 show BeginGroupToken, StringToken, SymbolToken, SyntheticSymbolToken;
13 BeginGroupToken,
14 KeywordToken,
15 StringToken,
16 SymbolToken,
17 SyntheticSymbolToken,
18 Token;
19 14
20 import 'token_constants.dart' 15 import 'token_constants.dart'
21 show 16 show
22 LT_TOKEN, 17 LT_TOKEN,
23 OPEN_CURLY_BRACKET_TOKEN, 18 OPEN_CURLY_BRACKET_TOKEN,
24 OPEN_PAREN_TOKEN, 19 OPEN_PAREN_TOKEN,
25 STRING_INTERPOLATION_TOKEN; 20 STRING_INTERPOLATION_TOKEN;
26 21
27 import 'characters.dart' show $LF, $STX; 22 import 'characters.dart' show $LF, $STX;
28 23
(...skipping 17 matching lines...) Expand all
46 Link<BeginGroupToken> groupingStack = const Link<BeginGroupToken>(); 41 Link<BeginGroupToken> groupingStack = const Link<BeginGroupToken>();
47 42
48 /** 43 /**
49 * Appends a fixed token whose kind and content is determined by [type]. 44 * Appends a fixed token whose kind and content is determined by [type].
50 * Appends an *operator* token from [type]. 45 * Appends an *operator* token from [type].
51 * 46 *
52 * An operator token represent operators like ':', '.', ';', '&&', '==', '--', 47 * An operator token represent operators like ':', '.', ';', '&&', '==', '--',
53 * '=>', etc. 48 * '=>', etc.
54 */ 49 */
55 void appendPrecedenceToken(TokenType type) { 50 void appendPrecedenceToken(TokenType type) {
56 appendToken(new SymbolToken(type, tokenStart)); 51 appendToken(new SymbolToken(type, tokenStart, comments));
57 } 52 }
58 53
59 /** 54 /**
60 * Appends a fixed token based on whether the current char is [choice] or not. 55 * Appends a fixed token based on whether the current char is [choice] or not.
61 * If the current char is [choice] a fixed token whose kind and content 56 * If the current char is [choice] a fixed token whose kind and content
62 * is determined by [yes] is appended, otherwise a fixed token whose kind 57 * is determined by [yes] is appended, otherwise a fixed token whose kind
63 * and content is determined by [no] is appended. 58 * and content is determined by [no] is appended.
64 */ 59 */
65 int select(int choice, TokenType yes, TokenType no) { 60 int select(int choice, TokenType yes, TokenType no) {
66 int next = advance(); 61 int next = advance();
67 if (identical(next, choice)) { 62 if (identical(next, choice)) {
68 appendPrecedenceToken(yes); 63 appendPrecedenceToken(yes);
69 return advance(); 64 return advance();
70 } else { 65 } else {
71 appendPrecedenceToken(no); 66 appendPrecedenceToken(no);
72 return next; 67 return next;
73 } 68 }
74 } 69 }
75 70
76 /** 71 /**
77 * Appends a keyword token whose kind is determined by [keyword]. 72 * Appends a keyword token whose kind is determined by [keyword].
78 */ 73 */
79 void appendKeywordToken(Keyword keyword) { 74 void appendKeywordToken(Keyword keyword) {
80 String syntax = keyword.lexeme; 75 String syntax = keyword.lexeme;
81 // Type parameters and arguments cannot contain 'this'. 76 // Type parameters and arguments cannot contain 'this'.
82 if (identical(syntax, 'this')) { 77 if (identical(syntax, 'this')) {
83 discardOpenLt(); 78 discardOpenLt();
84 } 79 }
85 appendToken(new KeywordToken(keyword, tokenStart)); 80 appendToken(new KeywordTokenWithComment(keyword, tokenStart, comments));
86 } 81 }
87 82
88 void appendEofToken() { 83 void appendEofToken() {
89 beginToken(); 84 beginToken();
90 discardOpenLt(); 85 discardOpenLt();
91 while (!groupingStack.isEmpty) { 86 while (!groupingStack.isEmpty) {
92 unmatchedBeginGroup(groupingStack.head); 87 unmatchedBeginGroup(groupingStack.head);
93 groupingStack = groupingStack.tail; 88 groupingStack = groupingStack.tail;
94 } 89 }
95 appendToken(new SymbolToken.eof(tokenStart)); 90 appendToken(new SymbolToken.eof(tokenStart, comments));
96 } 91 }
97 92
98 /** 93 /**
99 * Notifies scanning a whitespace character. Note that [appendWhiteSpace] is 94 * Notifies scanning a whitespace character. Note that [appendWhiteSpace] is
100 * not always invoked for [$SPACE] characters. 95 * not always invoked for [$SPACE] characters.
101 * 96 *
102 * This method is used by the scanners to track line breaks and create the 97 * This method is used by the scanners to track line breaks and create the
103 * [lineStarts] map. 98 * [lineStarts] map.
104 */ 99 */
105 void appendWhiteSpace(int next) { 100 void appendWhiteSpace(int next) {
(...skipping 10 matching lines...) Expand all
116 */ 111 */
117 void lineFeedInMultiline() { 112 void lineFeedInMultiline() {
118 lineStarts.add(stringOffset + 1); 113 lineStarts.add(stringOffset + 1);
119 } 114 }
120 115
121 /** 116 /**
122 * Appends a token that begins a new group, represented by [type]. 117 * Appends a token that begins a new group, represented by [type].
123 * Group begin tokens are '{', '(', '[' and '${'. 118 * Group begin tokens are '{', '(', '[' and '${'.
124 */ 119 */
125 void appendBeginGroup(TokenType type) { 120 void appendBeginGroup(TokenType type) {
126 Token token = new BeginGroupToken(type, tokenStart); 121 Token token = new BeginGroupToken(type, tokenStart, comments);
127 appendToken(token); 122 appendToken(token);
128 123
129 // { [ ${ cannot appear inside a type parameters / arguments. 124 // { [ ${ cannot appear inside a type parameters / arguments.
130 if (!identical(type.kind, LT_TOKEN) && 125 if (!identical(type.kind, LT_TOKEN) &&
131 !identical(type.kind, OPEN_PAREN_TOKEN)) { 126 !identical(type.kind, OPEN_PAREN_TOKEN)) {
132 discardOpenLt(); 127 discardOpenLt();
133 } 128 }
134 groupingStack = groupingStack.prepend(token); 129 groupingStack = groupingStack.prepend(token);
135 } 130 }
136 131
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 // SymbolToken(})<----------------------------------+ 289 // SymbolToken(})<----------------------------------+
295 // | 290 // |
296 // next 291 // next
297 // v 292 // v
298 // SymbolToken(;) 293 // SymbolToken(;)
299 // | 294 // |
300 // next 295 // next
301 // v 296 // v
302 // EOF 297 // EOF
303 TokenType type = closeBraceInfoFor(begin); 298 TokenType type = closeBraceInfoFor(begin);
304 appendToken(new SyntheticSymbolToken(type, tokenStart)); 299 appendToken(new SyntheticSymbolToken(type, tokenStart, comments));
305 begin.endGroup = tail; 300 begin.endGroup = tail;
306 appendErrorToken(new UnmatchedToken(begin)); 301 appendErrorToken(new UnmatchedToken(begin));
307 } 302 }
308 } 303 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/scanner/abstract_scanner.dart ('k') | pkg/front_end/lib/src/fasta/scanner/error_token.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698