OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 part of js_ast; | 5 part of js_ast; |
6 | 6 |
7 class TemplateManager { | 7 class TemplateManager { |
8 Map<String, Template> expressionTemplates = new Map<String, Template>(); | 8 Map<String, Template> expressionTemplates = new Map<String, Template>(); |
9 Map<String, Template> statementTemplates = new Map<String, Template>(); | 9 Map<String, Template> statementTemplates = new Map<String, Template>(); |
10 | 10 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 throw 'Unimplemented InstantiatorGeneratorVisitor for $node'; | 178 throw 'Unimplemented InstantiatorGeneratorVisitor for $node'; |
179 } | 179 } |
180 | 180 |
181 static RegExp identiferRE = new RegExp(r'^[A-Za-z_$][A-Za-z_$0-9]*$'); | 181 static RegExp identiferRE = new RegExp(r'^[A-Za-z_$][A-Za-z_$0-9]*$'); |
182 | 182 |
183 static Expression convertStringToVariableUse(String value) { | 183 static Expression convertStringToVariableUse(String value) { |
184 assert(identiferRE.hasMatch(value)); | 184 assert(identiferRE.hasMatch(value)); |
185 return new VariableUse(value); | 185 return new VariableUse(value); |
186 } | 186 } |
187 | 187 |
| 188 static Expression convertStringToVariableDeclaration(String value) { |
| 189 assert(identiferRE.hasMatch(value)); |
| 190 return new VariableDeclaration(value); |
| 191 } |
| 192 |
188 Instantiator visitInterpolatedExpression(InterpolatedExpression node) { | 193 Instantiator visitInterpolatedExpression(InterpolatedExpression node) { |
189 var nameOrPosition = node.nameOrPosition; | 194 var nameOrPosition = node.nameOrPosition; |
190 return (arguments) { | 195 return (arguments) { |
191 var value = arguments[nameOrPosition]; | 196 var value = arguments[nameOrPosition]; |
192 if (value is Expression) return value; | 197 if (value is Expression) return value; |
193 if (value is String) return convertStringToVariableUse(value); | 198 if (value is String) return convertStringToVariableUse(value); |
194 error('Interpolated value #$nameOrPosition is not an Expression: $value'); | 199 error('Interpolated value #$nameOrPosition is not an Expression: $value'); |
195 }; | 200 }; |
196 } | 201 } |
197 | 202 |
| 203 Instantiator visitInterpolatedDeclaration(InterpolatedDeclaration node) { |
| 204 var nameOrPosition = node.nameOrPosition; |
| 205 return (arguments) { |
| 206 var value = arguments[nameOrPosition]; |
| 207 if (value is Declaration) return value; |
| 208 if (value is String) return convertStringToVariableDeclaration(value); |
| 209 error('Interpolated value #$nameOrPosition is not a declaration: $value'); |
| 210 }; |
| 211 } |
| 212 |
198 Instantiator visitSplayableExpression(Node node) { | 213 Instantiator visitSplayableExpression(Node node) { |
199 if (node is InterpolatedExpression) { | 214 if (node is InterpolatedExpression) { |
200 var nameOrPosition = node.nameOrPosition; | 215 var nameOrPosition = node.nameOrPosition; |
201 return (arguments) { | 216 return (arguments) { |
202 var value = arguments[nameOrPosition]; | 217 var value = arguments[nameOrPosition]; |
203 Expression toExpression(item) { | 218 Expression toExpression(item) { |
204 if (item is Expression) return item; | 219 if (item is Expression) return item; |
205 if (item is String) return convertStringToVariableUse(item); | 220 if (item is String) return convertStringToVariableUse(item); |
206 return error('Interpolated value #$nameOrPosition is not ' | 221 return error('Interpolated value #$nameOrPosition is not ' |
207 'an Expression or List of Expressions: $value'); | 222 'an Expression or List of Expressions: $value'); |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 if (count != before) containsInterpolatedNode.add(node); | 745 if (count != before) containsInterpolatedNode.add(node); |
731 return null; | 746 return null; |
732 } | 747 } |
733 | 748 |
734 visitInterpolatedNode(InterpolatedNode node) { | 749 visitInterpolatedNode(InterpolatedNode node) { |
735 containsInterpolatedNode.add(node); | 750 containsInterpolatedNode.add(node); |
736 if (node.isNamed) holeNames.add(node.nameOrPosition); | 751 if (node.isNamed) holeNames.add(node.nameOrPosition); |
737 ++count; | 752 ++count; |
738 } | 753 } |
739 } | 754 } |
OLD | NEW |