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

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

Issue 2910583002: improve fasta interpolation recovery (Closed)
Patch Set: remove unnecessary label 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' 9 import '../../scanner/token.dart'
10 show 10 show
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 * 115 *
116 * This method is used by the scanners to track line breaks and create the 116 * This method is used by the scanners to track line breaks and create the
117 * [lineStarts] map. 117 * [lineStarts] map.
118 */ 118 */
119 void lineFeedInMultiline() { 119 void lineFeedInMultiline() {
120 lineStarts.add(stringOffset + 1); 120 lineStarts.add(stringOffset + 1);
121 } 121 }
122 122
123 /** 123 /**
124 * Appends a token that begins a new group, represented by [type]. 124 * Appends a token that begins a new group, represented by [type].
125 * Group begin tokens are '{', '(', '[' and '${'. 125 * Group begin tokens are '{', '(', '[', '<' and '${'.
126 */ 126 */
127 void appendBeginGroup(TokenType type) { 127 void appendBeginGroup(TokenType type) {
128 Token token = new BeginTokenWithComment(type, tokenStart, comments); 128 Token token = new BeginTokenWithComment(type, tokenStart, comments);
129 appendToken(token); 129 appendToken(token);
130 130
131 // { [ ${ cannot appear inside a type parameters / arguments. 131 // { [ ${ cannot appear inside a type parameters / arguments.
132 if (!identical(type.kind, LT_TOKEN) && 132 if (!identical(type.kind, LT_TOKEN) &&
133 !identical(type.kind, OPEN_PAREN_TOKEN)) { 133 !identical(type.kind, OPEN_PAREN_TOKEN)) {
134 discardOpenLt(); 134 discardOpenLt();
135 } 135 }
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 * something which cannot possibly be part of a type parameter/argument 250 * something which cannot possibly be part of a type parameter/argument
251 * list, like the '=' in the above example. 251 * list, like the '=' in the above example.
252 */ 252 */
253 void discardOpenLt() { 253 void discardOpenLt() {
254 while (!groupingStack.isEmpty && 254 while (!groupingStack.isEmpty &&
255 identical(groupingStack.head.kind, LT_TOKEN)) { 255 identical(groupingStack.head.kind, LT_TOKEN)) {
256 groupingStack = groupingStack.tail; 256 groupingStack = groupingStack.tail;
257 } 257 }
258 } 258 }
259 259
260 /**
261 * This method is called to discard '${' from the "grouping" stack.
262 *
263 * This method is called when the scanner finds the end of a string
264 * or an unterminated string.
ahe 2017/05/31 13:15:48 I think this is only called when it finds an unter
danrubel 2017/06/01 19:02:46 Right. Fixed in https://codereview.chromium.org/29
265 */
266 void discardInterpolation() {
267 if (groupingStack.isEmpty) return;
268 BeginToken begin = groupingStack.head;
269 if (begin.kind != STRING_INTERPOLATION_TOKEN) return;
270 unmatchedBeginGroup(begin);
271 groupingStack = groupingStack.tail;
ahe 2017/05/31 13:15:48 What happens in this case: "${([{
danrubel 2017/06/01 19:02:46 Hmmm... good point. Fixed in https://codereview.ch
272 }
273
260 void unmatchedBeginGroup(BeginToken begin) { 274 void unmatchedBeginGroup(BeginToken begin) {
261 // We want to ensure that unmatched BeginTokens are reported as 275 // We want to ensure that unmatched BeginTokens are reported as
262 // errors. However, the diet parser assumes that groups are well-balanced 276 // errors. However, the diet parser assumes that groups are well-balanced
263 // and will never look at the endGroup token. This is a nice property that 277 // and will never look at the endGroup token. This is a nice property that
264 // allows us to skip quickly over correct code. By inserting an additional 278 // allows us to skip quickly over correct code. By inserting an additional
265 // synthetic token in the stream, we can keep ignoring endGroup tokens. 279 // synthetic token in the stream, we can keep ignoring endGroup tokens.
266 // 280 //
267 // [begin] --next--> [tail] 281 // [begin] --next--> [tail]
268 // [begin] --endG--> [synthetic] --next--> [next] --next--> [tail] 282 // [begin] --endG--> [synthetic] --next--> [next] --next--> [tail]
269 // 283 //
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 // | 315 // |
302 // next 316 // next
303 // v 317 // v
304 // EOF 318 // EOF
305 TokenType type = closeBraceInfoFor(begin); 319 TokenType type = closeBraceInfoFor(begin);
306 appendToken(new SyntheticToken(type, tokenStart)); 320 appendToken(new SyntheticToken(type, tokenStart));
307 begin.endGroup = tail; 321 begin.endGroup = tail;
308 appendErrorToken(new UnmatchedToken(begin)); 322 appendErrorToken(new UnmatchedToken(begin));
309 } 323 }
310 } 324 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698