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

Side by Side Diff: dart/frog/leg/scanner/scanner.dart

Issue 9288070: Don't allow escaping newlines in single line strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 11 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
OLDNEW
1 // Copyright (c) 2011, 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.
11 */ 11 */
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 } 629 }
630 } 630 }
631 631
632 static bool isHexDigit(int character) { 632 static bool isHexDigit(int character) {
633 if ($0 <= character && character <= $9) return true; 633 if ($0 <= character && character <= $9) return true;
634 character |= 0x20; 634 character |= 0x20;
635 return ($a <= character && character <= $f); 635 return ($a <= character && character <= $f);
636 } 636 }
637 637
638 int tokenizeSingleLineString(int next, int q1, int start) { 638 int tokenizeSingleLineString(int next, int q1, int start) {
639 while (next !== $EOF) { 639 while (next !== q1) {
640 if (next === q1) { 640 if (next === $BACKSLASH) {
641 appendByteStringToken(STRING_INFO, utf8String(start, 0));
642 return advance();
643 } else if (next === $BACKSLASH) {
644 next = advance(); 641 next = advance();
645 if (next === $EOF) {
646 throw new MalformedInputException("unterminated string literal",
647 charOffset);
648 }
649 } else if (next === $$) { 642 } else if (next === $$) {
650 beginToken(); 643 next = tokenizeStringInterpolation(start);
651 next = advance();
652 if (next === $OPEN_CURLY_BRACKET) {
653 next = tokenizeInterpolatedExpression(next, start);
654 } else {
655 next = tokenizeInterpolatedIdentifier(next, start);
656 }
657 start = byteOffset; 644 start = byteOffset;
658 continue; 645 continue;
659 } else if (next === $LF || next === $CR) { 646 }
647 if (next <= $CR && (next === $LF || next === $CR || next === $EOF)) {
660 throw new MalformedInputException("unterminated string literal", 648 throw new MalformedInputException("unterminated string literal",
661 charOffset); 649 charOffset);
662 } 650 }
663 next = advance(); 651 next = advance();
664 } 652 }
665 throw new MalformedInputException("unterminated string literal", 653 appendByteStringToken(STRING_INFO, utf8String(start, 0));
666 charOffset); 654 return advance();
655 }
656
657 int tokenizeStringInterpolation(int start) {
658 beginToken();
659 int next = advance();
660 if (next === $OPEN_CURLY_BRACKET) {
661 return tokenizeInterpolatedExpression(next, start);
662 } else {
663 return tokenizeInterpolatedIdentifier(next, start);
664 }
667 } 665 }
668 666
669 int tokenizeInterpolatedExpression(int next, int start) { 667 int tokenizeInterpolatedExpression(int next, int start) {
670 appendByteStringToken(STRING_INFO, utf8String(start, -2)); 668 appendByteStringToken(STRING_INFO, utf8String(start, -2));
Lasse Reichstein Nielsen 2012/01/26 19:19:19 Consider moving this line and the identical one fr
ahe 2012/01/26 19:30:28 Good suggestion, I'll look into that later. I don'
671 appendBeginGroup(STRING_INTERPOLATION_INFO, "\${"); 669 appendBeginGroup(STRING_INTERPOLATION_INFO, "\${");
672 next = advance(); 670 next = advance();
673 while (next !== $EOF && next !== $STX) { 671 while (next !== $EOF && next !== $STX) {
674 next = bigSwitch(next); 672 next = bigSwitch(next);
675 } 673 }
676 if (next === $EOF) return next; 674 if (next === $EOF) return next;
677 return advance(); 675 return advance();
678 } 676 }
679 677
680 int tokenizeInterpolatedIdentifier(int next, int start) { 678 int tokenizeInterpolatedIdentifier(int next, int start) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 return next; 719 return next;
722 } 720 }
723 } 721 }
724 722
725 class MalformedInputException { 723 class MalformedInputException {
726 final String message; 724 final String message;
727 final position; 725 final position;
728 MalformedInputException(this.message, this.position); 726 MalformedInputException(this.message, this.position);
729 toString() => message; 727 toString() => message;
730 } 728 }
OLDNEW
« no previous file with comments | « no previous file | dart/frog/leg/scanner/source_list.dart » ('j') | dart/tests/language/src/StringEscape2NegativeTestHelper.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698