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

Side by Side Diff: frog/leg/tree/nodes.dart

Issue 9642001: Make string juxtaposition combine properly with string interpolations. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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) 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 interface Visitor<R> { 5 interface Visitor<R> {
6 R visitBlock(Block node); 6 R visitBlock(Block node);
7 R visitBreakStatement(BreakStatement node); 7 R visitBreakStatement(BreakStatement node);
8 R visitCatchBlock(CatchBlock node); 8 R visitCatchBlock(CatchBlock node);
9 R visitClassNode(ClassNode node); 9 R visitClassNode(ClassNode node);
10 R visitConditional(Conditional node); 10 R visitConditional(Conditional node);
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 } 719 }
720 } 720 }
721 721
722 722
723 class DartString implements Iterable<int> { 723 class DartString implements Iterable<int> {
724 factory DartString.literal(String string) => new LiteralDartString(string); 724 factory DartString.literal(String string) => new LiteralDartString(string);
725 factory DartString.rawString(SourceString source, int length) => 725 factory DartString.rawString(SourceString source, int length) =>
726 new RawSourceDartString(source, length); 726 new RawSourceDartString(source, length);
727 factory DartString.escapedString(SourceString source, int length) => 727 factory DartString.escapedString(SourceString source, int length) =>
728 new EscapedSourceDartString(source, length); 728 new EscapedSourceDartString(source, length);
729 factory DartString.cons(DartString first, DartString second) {
ngeoffray 2012/03/08 10:37:09 cons is very close to 'const' and I often get conf
Lasse Reichstein Nielsen 2012/03/08 11:17:49 ok, will do.
730 if (first.isEmpty()) return second;
731 if (second.isEmpty()) return first;
732 return new ConsDartString(first, second);
733 }
729 DartString(); 734 DartString();
ngeoffray 2012/03/08 10:37:09 Why do you still have this constructor? There shou
Lasse Reichstein Nielsen 2012/03/08 11:17:49 Isn't that only if I don't have any other construc
ngeoffray 2012/03/08 11:21:21 Yes, you're right. I got confused by the mix of fa
730 abstract int get length(); 735 abstract int get length();
731 bool isEmpty() => length == 0; 736 bool isEmpty() => length == 0;
732 abstract Iterator<int> iterator(); 737 abstract Iterator<int> iterator();
733 abstract String toString(); 738 abstract String toString();
734 739
735 bool operator ==(var other) { 740 bool operator ==(var other) {
736 if (other is !DartString) return false; 741 if (other is !DartString) return false;
737 DartString otherString = other; 742 DartString otherString = other;
738 if (length != otherString.length) return false; 743 if (length != otherString.length) return false;
739 Iterator it1 = iterator(); 744 Iterator it1 = iterator();
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 expression.accept(visitor); 1252 expression.accept(visitor);
1248 string.accept(visitor); 1253 string.accept(visitor);
1249 } 1254 }
1250 1255
1251 Token getBeginToken() => expression.getBeginToken(); 1256 Token getBeginToken() => expression.getBeginToken();
1252 1257
1253 Token getEndToken() => string.getEndToken(); 1258 Token getEndToken() => string.getEndToken();
1254 } 1259 }
1255 1260
1256 class LiteralStringJuxtaposition extends LiteralString { 1261 class LiteralStringJuxtaposition extends LiteralString {
1257 // List of either StringLiteral or StringInterpolation. 1262 // List of StringLiterals.
1258 final Link<Expression> literals; 1263 final Link<LiteralString> literals;
1259 1264
1260 LiteralStringJuxtaposition(Link<Expression> literals) 1265 LiteralStringJuxtaposition(Link<LiteralString> literals)
1261 : this.literals = literals, 1266 : this.literals = literals,
1262 super(literals.head.getBeginToken(), concatenateLiterals(literals)); 1267 super(literals.head.getBeginToken(), concatenateLiterals(literals));
1263 1268
1264 static DartString concatenateLiterals(Link<Expression> literals) { 1269 static DartString concatenateLiterals(Link<LiteralString> literals) {
1265 assert(!literals.isEmpty()); 1270 assert(!literals.isEmpty());
1266 LiteralString literal = literals.head; 1271 LiteralString literal = literals.head;
1267 if (literals.tail.isEmpty()) { 1272 // If any of the literals couldn't be validated, then nor can their
1268 return literal.dartString; 1273 // concatenation.
1274 if (!literal.isValidated()) return null;
1275 DartString accumulator = literal.dartString;
1276 literals = literals.tail;
1277 while (!literals.isEmpty()) {
1278 literal = literals.head;
1279 if (!literal.isValidated()) return null;
1280 accumulator = new DartString.cons(accumulator, literal.dartString);
1281 literals = literals.tail;
1269 } 1282 }
1270 return new ConsDartString(literal.dartString, 1283 return accumulator;
1271 concatenateLiterals(literals.tail));
1272 } 1284 }
1273 1285
1274 SourceString get value() => null; 1286 SourceString get value() => null;
1275 1287
1276 accept(Visitor visitor) => visitor.visitLiteralStringJuxtaposition(this); 1288 accept(Visitor visitor) => visitor.visitLiteralStringJuxtaposition(this);
1277 1289
1278 visitChildren(Visitor visitor) { 1290 visitChildren(Visitor visitor) {
1279 for (Expression literal in literals) { 1291 for (Expression literal in literals) {
1280 literal.accept(visitor); 1292 literal.accept(visitor);
1281 } 1293 }
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
1696 static bool isConstructorRedirect(Send node) { 1708 static bool isConstructorRedirect(Send node) {
1697 return (node.receiver === null && 1709 return (node.receiver === null &&
1698 node.selector.asIdentifier() !== null && 1710 node.selector.asIdentifier() !== null &&
1699 node.selector.asIdentifier().isThis()) || 1711 node.selector.asIdentifier().isThis()) ||
1700 (node.receiver !== null && 1712 (node.receiver !== null &&
1701 node.receiver.asIdentifier() !== null && 1713 node.receiver.asIdentifier() !== null &&
1702 node.receiver.asIdentifier().isThis() && 1714 node.receiver.asIdentifier().isThis() &&
1703 node.selector.asIdentifier() !== null); 1715 node.selector.asIdentifier() !== null);
1704 } 1716 }
1705 } 1717 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698