| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /** | 5 /** |
| 6 * This provides classes to represent the internal structure of the | 6 * This provides classes to represent the internal structure of the |
| 7 * arguments to `Intl.message`. It is used when parsing sources to extract | 7 * arguments to `Intl.message`. It is used when parsing sources to extract |
| 8 * messages or to generate code for message substitution. Normal programs | 8 * messages or to generate code for message substitution. Normal programs |
| 9 * using Intl would not import this library. | 9 * using Intl would not import this library. |
| 10 * | 10 * |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 class LiteralString extends Message { | 226 class LiteralString extends Message { |
| 227 String string; | 227 String string; |
| 228 LiteralString(this.string, Message parent) : super(parent); | 228 LiteralString(this.string, Message parent) : super(parent); |
| 229 toCode() => escapeAndValidateString(string); | 229 toCode() => escapeAndValidateString(string); |
| 230 toString() => "Literal($string)"; | 230 toString() => "Literal($string)"; |
| 231 String expanded([Function f = _nullTransform]) => f(this, string); | 231 String expanded([Function f = _nullTransform]) => f(this, string); |
| 232 } | 232 } |
| 233 | 233 |
| 234 /** | 234 /** |
| 235 * Represents an interpolation of a variable value in a message. We expect | 235 * Represents an interpolation of a variable value in a message. We expect |
| 236 * this to be specified as an [index] into the list of variables, and we will | 236 * this to be specified as an [index] into the list of variables, or else |
| 237 * compute the variable name for the interpolation based on that. | 237 * as the name of a variable that exists in [arguments] and we will |
| 238 * compute the variable name or the index based on the value of the other. |
| 238 */ | 239 */ |
| 239 class VariableSubstitution extends Message { | 240 class VariableSubstitution extends Message { |
| 240 VariableSubstitution(this.index, Message parent) : super(parent); | 241 VariableSubstitution(this._index, Message parent) : super(parent); |
| 242 VariableSubstitution.named(this._variableName, Message parent) |
| 243 : super(parent); |
| 241 | 244 |
| 242 /** The index in the list of parameters of the containing function. */ | 245 /** The index in the list of parameters of the containing function. */ |
| 243 int index; | 246 int _index; |
| 247 int get index { |
| 248 if (_index != null) return _index; |
| 249 if (arguments.isEmpty) return null; |
| 250 return _index = arguments.indexOf(_variableName); |
| 251 } |
| 244 | 252 |
| 245 /** | 253 /** |
| 246 * The name of the variable in the parameter list of the containing function. | 254 * The name of the variable in the parameter list of the containing function. |
| 247 * Used when generating code for the interpolation. | 255 * Used when generating code for the interpolation. |
| 248 */ | 256 */ |
| 249 String get variableName => | 257 String get variableName => |
| 250 _variableName == null ? _variableName = arguments[index] : _variableName; | 258 _variableName == null ? _variableName = arguments[index] : _variableName; |
| 251 String _variableName; | 259 String _variableName; |
| 252 // Although we only allow simple variable references, we always enclose them | 260 // Although we only allow simple variable references, we always enclose them |
| 253 // in curly braces so that there's no possibility of ambiguity with | 261 // in curly braces so that there's no possibility of ambiguity with |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 out.write('('); | 642 out.write('('); |
| 635 out.write(mainArgument); | 643 out.write(mainArgument); |
| 636 var args = codeAttributeNames; | 644 var args = codeAttributeNames; |
| 637 out.write(", {"); | 645 out.write(", {"); |
| 638 args.fold(out, (buffer, arg) => buffer..write( | 646 args.fold(out, (buffer, arg) => buffer..write( |
| 639 "'$arg': '${this[arg].toCode()}', ")); | 647 "'$arg': '${this[arg].toCode()}', ")); |
| 640 out.write("})}"); | 648 out.write("})}"); |
| 641 return out.toString(); | 649 return out.toString(); |
| 642 } | 650 } |
| 643 } | 651 } |
| OLD | NEW |