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

Unified 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: Addressed review comments. 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 side-by-side diff with in-line comments
Download patch
Index: frog/leg/tree/nodes.dart
diff --git a/frog/leg/tree/nodes.dart b/frog/leg/tree/nodes.dart
index b05f1e1cc331cd85e07d9102237122d756ca9de7..54d989d168c9167b3bc84d35d2e4ca891825040b 100644
--- a/frog/leg/tree/nodes.dart
+++ b/frog/leg/tree/nodes.dart
@@ -726,6 +726,11 @@ class DartString implements Iterable<int> {
new RawSourceDartString(source, length);
factory DartString.escapedString(SourceString source, int length) =>
new EscapedSourceDartString(source, length);
+ factory DartString.concat(DartString first, DartString second) {
+ if (first.isEmpty()) return second;
+ if (second.isEmpty()) return first;
+ return new ConsDartString(first, second);
+ }
DartString();
abstract int get length();
bool isEmpty() => length == 0;
@@ -1254,21 +1259,28 @@ class StringInterpolationPart extends Node {
}
class LiteralStringJuxtaposition extends LiteralString {
- // List of either StringLiteral or StringInterpolation.
- final Link<Expression> literals;
+ // List of StringLiterals.
+ final Link<LiteralString> literals;
- LiteralStringJuxtaposition(Link<Expression> literals)
+ LiteralStringJuxtaposition(Link<LiteralString> literals)
: this.literals = literals,
super(literals.head.getBeginToken(), concatenateLiterals(literals));
- static DartString concatenateLiterals(Link<Expression> literals) {
+ static DartString concatenateLiterals(Link<LiteralString> literals) {
assert(!literals.isEmpty());
LiteralString literal = literals.head;
- if (literals.tail.isEmpty()) {
- return literal.dartString;
+ // If any of the literals couldn't be validated, then nor can their
+ // concatenation.
+ if (!literal.isValidated()) return null;
+ DartString accumulator = literal.dartString;
+ literals = literals.tail;
+ while (!literals.isEmpty()) {
+ literal = literals.head;
+ if (!literal.isValidated()) return null;
+ accumulator = new DartString.concat(accumulator, literal.dartString);
+ literals = literals.tail;
}
- return new ConsDartString(literal.dartString,
- concatenateLiterals(literals.tail));
+ return accumulator;
}
SourceString get value() => null;

Powered by Google App Engine
This is Rietveld 408576698