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

Unified Diff: frog/parser.dart

Issue 9653021: Add support for implicitly concatenating adjacent string literals. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added test case. 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
« no previous file with comments | « frog/minfrog ('k') | frog/tree.g.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/parser.dart
diff --git a/frog/parser.dart b/frog/parser.dart
index 3a6ab3d749714fb25bb572a8f9ed3bc9734523ff..4cb22ab8250a72ba142f3976f8a566d59fb8fcef 100644
--- a/frog/parser.dart
+++ b/frog/parser.dart
@@ -1115,11 +1115,8 @@ class Parser {
Value.fromDouble(Math.parseDouble(t.text), t.span));
case TokenKind.STRING:
- var t = _next();
- return _makeLiteral(Value.fromString(t.value, t.span));
-
case TokenKind.STRING_PART:
- return stringInterpolation();
+ return adjacentStrings();
case TokenKind.LT:
return finishTypedLiteral(start, false);
@@ -1138,6 +1135,27 @@ class Parser {
}
}
+ adjacentStrings() {
+ int start = _peekToken.start;
+ List<Expression> strings = [];
+ while (_peek() == TokenKind.STRING || _peek() == TokenKind.STRING_PART) {
+ Expression part = null;
+ if (_peek() == TokenKind.STRING) {
+ var t = _next();
+ part = _makeLiteral(Value.fromString(t.value, t.span));
+ } else {
+ part = stringInterpolation();
+ }
+ strings.add(part);
+ }
+ if (strings.length == 1) {
+ return strings[0];
+ } else {
+ assert(!strings.isEmpty());
+ return new StringConcatExpression(strings, _makeSpan(start));
+ }
+ }
+
stringInterpolation() {
int start = _peekToken.start;
var pieces = new List<Expression>();
« no previous file with comments | « frog/minfrog ('k') | frog/tree.g.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698