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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/tree/nodes.dart

Issue 336413002: Allow whitespace and \ before the first newline of multiline string. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use more intuitive test. Created 6 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
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 part of tree; 5 part of tree;
6 6
7 abstract class Visitor<R> { 7 abstract class Visitor<R> {
8 const Visitor(); 8 const Visitor();
9 9
10 R visitNode(Node node); 10 R visitNode(Node node);
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 if (identical(token.stringValue, 'false')) return false; 819 if (identical(token.stringValue, 'false')) return false;
820 (this.handler)(token, "not a bool ${token.value}"); 820 (this.handler)(token, "not a bool ${token.value}");
821 throw false; 821 throw false;
822 } 822 }
823 823
824 accept(Visitor visitor) => visitor.visitLiteralBool(this); 824 accept(Visitor visitor) => visitor.visitLiteralBool(this);
825 } 825 }
826 826
827 827
828 class StringQuoting { 828 class StringQuoting {
829 static const StringQuoting SINGLELINE_DQ =
830 const StringQuoting($DQ, raw: false, leftQuoteLength: 1);
831 static const StringQuoting RAW_SINGLELINE_DQ =
832 const StringQuoting($DQ, raw: true, leftQuoteLength: 1);
833 static const StringQuoting MULTILINE_DQ =
834 const StringQuoting($DQ, raw: false, leftQuoteLength: 3);
835 static const StringQuoting RAW_MULTILINE_DQ =
836 const StringQuoting($DQ, raw: true, leftQuoteLength: 3);
837 static const StringQuoting MULTILINE_NL_DQ =
838 const StringQuoting($DQ, raw: false, leftQuoteLength: 4);
839 static const StringQuoting RAW_MULTILINE_NL_DQ =
840 const StringQuoting($DQ, raw: true, leftQuoteLength: 4);
841 static const StringQuoting MULTILINE_NL2_DQ =
842 const StringQuoting($DQ, raw: false, leftQuoteLength: 5);
843 static const StringQuoting RAW_MULTILINE_NL2_DQ =
844 const StringQuoting($DQ, raw: true, leftQuoteLength: 5);
845 static const StringQuoting SINGLELINE_SQ =
846 const StringQuoting($SQ, raw: false, leftQuoteLength: 1);
847 static const StringQuoting RAW_SINGLELINE_SQ =
848 const StringQuoting($SQ, raw: true, leftQuoteLength: 1);
849 static const StringQuoting MULTILINE_SQ =
850 const StringQuoting($SQ, raw: false, leftQuoteLength: 3);
851 static const StringQuoting RAW_MULTILINE_SQ =
852 const StringQuoting($SQ, raw: true, leftQuoteLength: 3);
853 static const StringQuoting MULTILINE_NL_SQ =
854 const StringQuoting($SQ, raw: false, leftQuoteLength: 4);
855 static const StringQuoting RAW_MULTILINE_NL_SQ =
856 const StringQuoting($SQ, raw: true, leftQuoteLength: 4);
857 static const StringQuoting MULTILINE_NL2_SQ =
858 const StringQuoting($SQ, raw: false, leftQuoteLength: 5);
859 static const StringQuoting RAW_MULTILINE_NL2_SQ =
860 const StringQuoting($SQ, raw: true, leftQuoteLength: 5);
861 829
830 /// Cache of common quotings.
831 static const List<StringQuoting> _mapping = const <StringQuoting>[
832 const StringQuoting($SQ, raw: false, leftQuoteLength: 1),
833 const StringQuoting($SQ, raw: true, leftQuoteLength: 1),
834 const StringQuoting($DQ, raw: false, leftQuoteLength: 1),
835 const StringQuoting($DQ, raw: true, leftQuoteLength: 1),
836 // No string quotes with 2 characters.
837 null,
838 null,
839 null,
840 null,
841 const StringQuoting($SQ, raw: false, leftQuoteLength: 3),
842 const StringQuoting($SQ, raw: true, leftQuoteLength: 3),
843 const StringQuoting($DQ, raw: false, leftQuoteLength: 3),
844 const StringQuoting($DQ, raw: true, leftQuoteLength: 3),
845 // Leading single whitespace or espaped newline.
846 const StringQuoting($SQ, raw: false, leftQuoteLength: 4),
847 const StringQuoting($SQ, raw: true, leftQuoteLength: 4),
848 const StringQuoting($DQ, raw: false, leftQuoteLength: 4),
849 const StringQuoting($DQ, raw: true, leftQuoteLength: 4),
850 // Other combinations of leading whitespace and/or escaped newline.
851 const StringQuoting($SQ, raw: false, leftQuoteLength: 5),
852 const StringQuoting($SQ, raw: true, leftQuoteLength: 5),
853 const StringQuoting($DQ, raw: false, leftQuoteLength: 5),
854 const StringQuoting($DQ, raw: true, leftQuoteLength: 5),
855 const StringQuoting($SQ, raw: false, leftQuoteLength: 6),
856 const StringQuoting($SQ, raw: true, leftQuoteLength: 6),
857 const StringQuoting($DQ, raw: false, leftQuoteLength: 6),
858 const StringQuoting($DQ, raw: true, leftQuoteLength: 6)
859 ];
862 860
863 static const List<StringQuoting> mapping = const <StringQuoting>[
864 SINGLELINE_DQ,
865 RAW_SINGLELINE_DQ,
866 MULTILINE_DQ,
867 RAW_MULTILINE_DQ,
868 MULTILINE_NL_DQ,
869 RAW_MULTILINE_NL_DQ,
870 MULTILINE_NL2_DQ,
871 RAW_MULTILINE_NL2_DQ,
872 SINGLELINE_SQ,
873 RAW_SINGLELINE_SQ,
874 MULTILINE_SQ,
875 RAW_MULTILINE_SQ,
876 MULTILINE_NL_SQ,
877 RAW_MULTILINE_NL_SQ,
878 MULTILINE_NL2_SQ,
879 RAW_MULTILINE_NL2_SQ
880 ];
881 final bool raw; 861 final bool raw;
882 final int leftQuoteCharCount; 862 final int leftQuoteCharCount;
883 final int quote; 863 final int quote;
884 const StringQuoting(this.quote, {bool raw, int leftQuoteLength}) 864 const StringQuoting(this.quote, {bool raw, int leftQuoteLength})
Lasse Reichstein Nielsen 2014/06/18 09:05:32 "While you are here": Please change this to "{bool
floitsch 2014/06/18 12:14:23 Done.
885 : this.raw = raw, this.leftQuoteCharCount = leftQuoteLength; 865 : this.raw = raw, this.leftQuoteCharCount = leftQuoteLength;
886 String get quoteChar => identical(quote, $DQ) ? '"' : "'"; 866 String get quoteChar => identical(quote, $DQ) ? '"' : "'";
887 867
888 int get leftQuoteLength => (raw ? 1 : 0) + leftQuoteCharCount; 868 int get leftQuoteLength => (raw ? 1 : 0) + leftQuoteCharCount;
889 int get rightQuoteLength => (leftQuoteCharCount > 2) ? 3 : 1; 869 int get rightQuoteLength => (leftQuoteCharCount > 2) ? 3 : 1;
890 static StringQuoting getQuoting(int quote, bool raw, int quoteLength) { 870 static StringQuoting getQuoting(int quote, bool raw, int quoteLength) {
871 int quoteKindOffset = (quote == $DQ) ? 2 : 0;
872 int rawOffset = raw ? 1 : 0;
891 int index = quoteLength - 1; 873 int index = quoteLength - 1;
Lasse Reichstein Nielsen 2014/06/18 09:05:32 Just multiply this by four immediately, instead of
floitsch 2014/06/18 12:14:23 Computing the full index now (including the rawOff
892 if (quoteLength > 2) index -= 1; 874 if (index * 4 < _mapping.length) {
893 return mapping[(raw ? 1 : 0) + index * 2 + (identical(quote, $SQ) ? 8 : 0)]; 875 return _mapping[rawOffset + quoteKindOffset + index * 4];
876 }
877 return new StringQuoting(quote, raw: raw, leftQuoteLength: index + 1);
Lasse Reichstein Nielsen 2014/06/18 09:05:32 index + 1 -> quoteLength
floitsch 2014/06/18 12:14:23 doh. done.
894 } 878 }
895 } 879 }
896 880
897 /** 881 /**
898 * Superclass for classes representing string literals. 882 * Superclass for classes representing string literals.
899 */ 883 */
900 abstract class StringNode extends Expression { 884 abstract class StringNode extends Expression {
901 DartString get dartString; 885 DartString get dartString;
902 bool get isInterpolation; 886 bool get isInterpolation;
903 887
(...skipping 1203 matching lines...) Expand 10 before | Expand all | Expand 10 after
2107 } 2091 }
2108 2092
2109 class IsInterpolationVisitor extends Visitor<bool> { 2093 class IsInterpolationVisitor extends Visitor<bool> {
2110 const IsInterpolationVisitor(); 2094 const IsInterpolationVisitor();
2111 bool visitNode(Node node) => false; 2095 bool visitNode(Node node) => false;
2112 bool visitStringInterpolation(StringInterpolation node) => true; 2096 bool visitStringInterpolation(StringInterpolation node) => true;
2113 bool visitStringJuxtaposition(StringJuxtaposition node) 2097 bool visitStringJuxtaposition(StringJuxtaposition node)
2114 => node.isInterpolation; 2098 => node.isInterpolation;
2115 } 2099 }
2116 2100
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698