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

Side by Side Diff: dart/lib/compiler/implementation/scanner/scanner.dart

Issue 10544173: Update partial parser and scanner to be able to skip expressions like "new Map<S, T>()". (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address comments and add comments Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « dart/lib/compiler/implementation/scanner/partial_parser.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 interface Scanner { 5 interface Scanner {
6 Token tokenize(); 6 Token tokenize();
7 } 7 }
8 8
9 /** 9 /**
10 * Common base class for a Dart scanner. 10 * Common base class for a Dart scanner.
(...skipping 15 matching lines...) Expand all
26 abstract Token previousToken(); 26 abstract Token previousToken();
27 abstract void beginToken(); 27 abstract void beginToken();
28 abstract void addToCharOffset(int offset); 28 abstract void addToCharOffset(int offset);
29 abstract int get charOffset(); 29 abstract int get charOffset();
30 abstract int get byteOffset(); 30 abstract int get byteOffset();
31 abstract void appendBeginGroup(PrecedenceInfo info, String value); 31 abstract void appendBeginGroup(PrecedenceInfo info, String value);
32 abstract int appendEndGroup(PrecedenceInfo info, String value, int openKind); 32 abstract int appendEndGroup(PrecedenceInfo info, String value, int openKind);
33 abstract void appendGt(PrecedenceInfo info, String value); 33 abstract void appendGt(PrecedenceInfo info, String value);
34 abstract void appendGtGt(PrecedenceInfo info, String value); 34 abstract void appendGtGt(PrecedenceInfo info, String value);
35 abstract void appendGtGtGt(PrecedenceInfo info, String value); 35 abstract void appendGtGtGt(PrecedenceInfo info, String value);
36
37 /**
38 * We call this method to discard '<' from the "grouping" stack
39 * (maintained by subclasses). That we don't create groups for stuff
40 * like "a = b < c, d = e > f" is used by
41 * [PartialParser.skipExpression].
42 */
Lasse Reichstein Nielsen 2012/06/15 13:59:14 So you call this when you recognize something that
ahe 2012/06/19 11:02:42 Done.
36 abstract void discardOpenLt(); 43 abstract void discardOpenLt();
37 44
38 // TODO(ahe): Move this class to implementation. 45 // TODO(ahe): Move this class to implementation.
39 46
40 Token tokenize() { 47 Token tokenize() {
41 int next = advance(); 48 int next = advance();
42 while (next !== $EOF) { 49 while (next !== $EOF) {
43 next = bigSwitch(next); 50 next = bigSwitch(next);
44 } 51 }
45 appendEofToken(); 52 appendEofToken();
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 return advance(); 143 return advance();
137 } 144 }
138 145
139 if (next === $COLON) { 146 if (next === $COLON) {
140 appendPrecedenceToken(COLON_INFO); 147 appendPrecedenceToken(COLON_INFO);
141 return advance(); 148 return advance();
142 } 149 }
143 150
144 if (next === $SEMICOLON) { 151 if (next === $SEMICOLON) {
145 appendPrecedenceToken(SEMICOLON_INFO); 152 appendPrecedenceToken(SEMICOLON_INFO);
153 // Type parameters and arguments cannot contain semicolon.
146 discardOpenLt(); 154 discardOpenLt();
147 return advance(); 155 return advance();
148 } 156 }
149 157
150 if (next === $QUESTION) { 158 if (next === $QUESTION) {
151 appendPrecedenceToken(QUESTION_INFO); 159 appendPrecedenceToken(QUESTION_INFO);
152 return advance(); 160 return advance();
153 } 161 }
154 162
155 if (next === $CLOSE_SQUARE_BRACKET) { 163 if (next === $CLOSE_SQUARE_BRACKET) {
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 next = advance(); 342 next = advance();
335 if (next === $EQ) { 343 if (next === $EQ) {
336 return select($EQ, BANG_EQ_EQ_INFO, BANG_EQ_INFO); 344 return select($EQ, BANG_EQ_EQ_INFO, BANG_EQ_INFO);
337 } 345 }
338 appendPrecedenceToken(BANG_INFO); 346 appendPrecedenceToken(BANG_INFO);
339 return next; 347 return next;
340 } 348 }
341 349
342 int tokenizeEquals(int next) { 350 int tokenizeEquals(int next) {
343 // = == === 351 // = == ===
352
353 // Type parameters and arguments cannot contain any token that
354 // starts with '='.
355 discardOpenLt();
356
344 next = advance(); 357 next = advance();
345 if (next === $EQ) { 358 if (next === $EQ) {
346 return select($EQ, EQ_EQ_EQ_INFO, EQ_EQ_INFO); 359 return select($EQ, EQ_EQ_EQ_INFO, EQ_EQ_INFO);
347 } else if (next === $GT) { 360 } else if (next === $GT) {
348 appendPrecedenceToken(FUNCTION_INFO); 361 appendPrecedenceToken(FUNCTION_INFO);
349 return advance(); 362 return advance();
350 } 363 }
351 appendPrecedenceToken(EQ_INFO); 364 appendPrecedenceToken(EQ_INFO);
352 return next; 365 return next;
353 } 366 }
354 367
355 int tokenizeGreaterThan(int next) { 368 int tokenizeGreaterThan(int next) {
356 // > >= >> >>= >>> >>>= 369 // > >= >> >>= >>> >>>=
Lasse Reichstein Nielsen 2012/06/15 13:59:14 When type names can be expressions (reified types)
ahe 2012/06/19 11:02:42 Yay! More fun to be had in the future. :-)
357 next = advance(); 370 next = advance();
358 if ($EQ === next) { 371 if ($EQ === next) {
359 appendPrecedenceToken(GT_EQ_INFO); 372 appendPrecedenceToken(GT_EQ_INFO);
360 return advance(); 373 return advance();
361 } else if ($GT === next) { 374 } else if ($GT === next) {
362 next = advance(); 375 next = advance();
363 if ($EQ === next) { 376 if ($EQ === next) {
364 appendPrecedenceToken(GT_GT_EQ_INFO); 377 appendPrecedenceToken(GT_GT_EQ_INFO);
365 return advance(); 378 return advance();
366 } else if ($GT === next) { 379 } else if ($GT === next) {
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 charOffset); 774 charOffset);
762 } 775 }
763 } 776 }
764 777
765 class MalformedInputException { 778 class MalformedInputException {
766 final String message; 779 final String message;
767 final position; 780 final position;
768 MalformedInputException(this.message, this.position); 781 MalformedInputException(this.message, this.position);
769 toString() => message; 782 toString() => message;
770 } 783 }
OLDNEW
« no previous file with comments | « dart/lib/compiler/implementation/scanner/partial_parser.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698