@@ -64,6 +64,12 @@ class ParseException extends BaseException {
6464 }
6565}
6666
67+ class SplitInterpolation {
68+ List <String > strings;
69+ List <String > expressions;
70+ SplitInterpolation (this .strings, this .expressions) {}
71+ }
72+
6773@Injectable ()
6874class Parser {
6975 Lexer _lexer;
@@ -128,6 +134,20 @@ class Parser {
128134 }
129135
130136 ASTWithSource parseInterpolation (String input, dynamic location) {
137+ var split = this .splitInterpolation (input, location);
138+ if (split == null ) return null ;
139+ var expressions = [];
140+ for (var i = 0 ; i < split.expressions.length; ++ i) {
141+ var tokens = this ._lexer.tokenize (split.expressions[i]);
142+ var ast = new _ParseAST (input, location, tokens, this ._reflector, false )
143+ .parseChain ();
144+ expressions.add (ast);
145+ }
146+ return new ASTWithSource (
147+ new Interpolation (split.strings, expressions), input, location);
148+ }
149+
150+ SplitInterpolation splitInterpolation (String input, String location) {
131151 var parts = StringWrapper .split (input, INTERPOLATION_REGEXP );
132152 if (parts.length <= 1 ) {
133153 return null ;
@@ -140,10 +160,7 @@ class Parser {
140160 // fixed string
141161 strings.add (part);
142162 } else if (part.trim ().length > 0 ) {
143- var tokens = this ._lexer.tokenize (part);
144- var ast = new _ParseAST (input, location, tokens, this ._reflector, false )
145- .parseChain ();
146- expressions.add (ast);
163+ expressions.add (part);
147164 } else {
148165 throw new ParseException (
149166 "Blank expressions are not allowed in interpolated strings" ,
@@ -152,8 +169,7 @@ class Parser {
152169 location);
153170 }
154171 }
155- return new ASTWithSource (
156- new Interpolation (strings, expressions), input, location);
172+ return new SplitInterpolation (strings, expressions);
157173 }
158174
159175 ASTWithSource wrapLiteralPrimitive (String input, dynamic location) {
0 commit comments