OLD | NEW |
---|---|
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 part of scanner; | 5 part of scanner; |
6 | 6 |
7 abstract class Scanner { | 7 abstract class Scanner { |
8 Token tokenize(); | 8 Token tokenize(); |
9 } | 9 } |
10 | 10 |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
455 } else { | 455 } else { |
456 appendBeginGroup(LT_INFO, "<"); | 456 appendBeginGroup(LT_INFO, "<"); |
457 return next; | 457 return next; |
458 } | 458 } |
459 } | 459 } |
460 | 460 |
461 int tokenizeNumber(int next) { | 461 int tokenizeNumber(int next) { |
462 int start = byteOffset; | 462 int start = byteOffset; |
463 while (true) { | 463 while (true) { |
464 next = advance(); | 464 next = advance(); |
465 int nextnext = peek(); | |
ahe
2013/09/06 14:20:26
Can you avoid calling peek until you see a '.'?
| |
465 if ($0 <= next && next <= $9) { | 466 if ($0 <= next && next <= $9) { |
466 continue; | 467 continue; |
467 } else if (identical(next, $PERIOD)) { | 468 } else if (identical(next, $PERIOD) |
ahe
2013/09/06 14:20:26
Would this work:
} else if (identical(next, $PERI
| |
469 && ($0 <= nextnext && nextnext <= $9)) { | |
468 return tokenizeFractionPart(advance(), start); | 470 return tokenizeFractionPart(advance(), start); |
469 } else if (identical(next, $e) || identical(next, $E) | 471 } else if (identical(next, $e) || identical(next, $E)) { |
470 || identical(next, $d) || identical(next, $D)) { | |
471 return tokenizeFractionPart(next, start); | 472 return tokenizeFractionPart(next, start); |
472 } else { | 473 } else { |
473 appendByteStringToken(INT_INFO, asciiString(start, 0)); | 474 appendByteStringToken(INT_INFO, asciiString(start, 0)); |
474 return next; | 475 return next; |
475 } | 476 } |
476 } | 477 } |
477 } | 478 } |
478 | 479 |
479 int tokenizeHexOrNumber(int next) { | 480 int tokenizeHexOrNumber(int next) { |
480 int x = peek(); | 481 int x = peek(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
536 } | 537 } |
537 if (!hasDigit) { | 538 if (!hasDigit) { |
538 appendByteStringToken(INT_INFO, asciiString(start, -1)); | 539 appendByteStringToken(INT_INFO, asciiString(start, -1)); |
539 if (identical($PERIOD, next)) { | 540 if (identical($PERIOD, next)) { |
540 return select($PERIOD, PERIOD_PERIOD_PERIOD_INFO, PERIOD_PERIOD_INFO); | 541 return select($PERIOD, PERIOD_PERIOD_PERIOD_INFO, PERIOD_PERIOD_INFO); |
541 } | 542 } |
542 // TODO(ahe): Wrong offset for the period. | 543 // TODO(ahe): Wrong offset for the period. |
543 appendPrecedenceToken(PERIOD_INFO); | 544 appendPrecedenceToken(PERIOD_INFO); |
544 return bigSwitch(next); | 545 return bigSwitch(next); |
545 } | 546 } |
546 if (identical(next, $d) || identical(next, $D)) { | |
547 next = advance(); | |
548 } | |
549 appendByteStringToken(DOUBLE_INFO, asciiString(start, 0)); | 547 appendByteStringToken(DOUBLE_INFO, asciiString(start, 0)); |
550 return next; | 548 return next; |
551 } | 549 } |
552 | 550 |
553 int tokenizeExponent(int next) { | 551 int tokenizeExponent(int next) { |
554 if (identical(next, $PLUS) || identical(next, $MINUS)) { | 552 if (identical(next, $PLUS) || identical(next, $MINUS)) { |
555 next = advance(); | 553 next = advance(); |
556 } | 554 } |
557 bool hasDigits = false; | 555 bool hasDigits = false; |
558 while (true) { | 556 while (true) { |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
836 next = advance(); | 834 next = advance(); |
837 } | 835 } |
838 return error(const SourceString("unterminated string literal")); | 836 return error(const SourceString("unterminated string literal")); |
839 } | 837 } |
840 | 838 |
841 int error(SourceString message) { | 839 int error(SourceString message) { |
842 appendByteStringToken(BAD_INPUT_INFO, message); | 840 appendByteStringToken(BAD_INPUT_INFO, message); |
843 return advance(); // Ensure progress. | 841 return advance(); // Ensure progress. |
844 } | 842 } |
845 } | 843 } |
OLD | NEW |