Chromium Code Reviews| Index: frog/leg/tree/nodes.dart |
| diff --git a/frog/leg/tree/nodes.dart b/frog/leg/tree/nodes.dart |
| index b05f1e1cc331cd85e07d9102237122d756ca9de7..5b3d956ce2309f18eb52ce32866e2de3de252a15 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.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.
|
| + if (first.isEmpty()) return second; |
| + if (second.isEmpty()) return first; |
| + return new ConsDartString(first, second); |
| + } |
| 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
|
| 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.cons(accumulator, literal.dartString); |
| + literals = literals.tail; |
| } |
| - return new ConsDartString(literal.dartString, |
| - concatenateLiterals(literals.tail)); |
| + return accumulator; |
| } |
| SourceString get value() => null; |