Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 * Takes a parsed YAML document (what the spec calls the "serialization tree") | 6 * Takes a parsed YAML document (what the spec calls the "serialization tree") |
| 7 * and resolves aliases, resolves tags, and parses scalars to produce the | 7 * and resolves aliases, resolves tags, and parses scalars to produce the |
| 8 * "representation graph". | 8 * "representation graph". |
| 9 */ | 9 */ |
| 10 class _Composer extends _Visitor { | 10 class _Composer extends _Visitor { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 | 145 |
| 146 return null; | 146 return null; |
| 147 } | 147 } |
| 148 | 148 |
| 149 /** Parses a floating-point scalar. */ | 149 /** Parses a floating-point scalar. */ |
| 150 _ScalarNode parseFloat(String content) { | 150 _ScalarNode parseFloat(String content) { |
| 151 var match = const RegExp( | 151 var match = const RegExp( |
| 152 "^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?\$"). | 152 "^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?\$"). |
| 153 firstMatch(content); | 153 firstMatch(content); |
| 154 if (match != null) { | 154 if (match != null) { |
| 155 // YAML allows floats of the form "0.", but Dart does not. Fix up those | |
| 156 // floats by removing the trailing dot. | |
| 157 var matchStr = match.group(0).replaceAll(new RegExp(@"\.$"), ""); | |
| 155 return new _ScalarNode(_Tag.yaml("float"), | 158 return new _ScalarNode(_Tag.yaml("float"), |
| 156 value: Math.parseDouble(match.group(0))); | 159 value: Math.parseDouble(matchStr)); |
| 157 } | 160 } |
| 158 | 161 |
| 159 match = const RegExp("^([+-]?)\.(inf|Inf|INF)\$").firstMatch(content); | 162 match = const RegExp("^([+-]?)\.(inf|Inf|INF)\$").firstMatch(content); |
| 160 if (match != null) { | 163 if (match != null) { |
| 164 var infStr = match.group(1) == "-" ? "-Infinity" : "Infinity"; | |
|
Bob Nystrom
2012/05/18 21:06:30
wflly shrt nm. How about "infinity"?
nweiz
2012/05/18 21:47:04
Done.
| |
| 161 return new _ScalarNode(_Tag.yaml("float"), | 165 return new _ScalarNode(_Tag.yaml("float"), |
| 162 value: Math.parseDouble("${match.group(1)}Infinity")); | 166 value: Math.parseDouble(infStr)); |
| 163 } | 167 } |
| 164 | 168 |
| 165 match = const RegExp("^\.(nan|NaN|NAN)\$").firstMatch(content); | 169 match = const RegExp("^\.(nan|NaN|NAN)\$").firstMatch(content); |
| 166 if (match != null) { | 170 if (match != null) { |
| 167 return new _ScalarNode(_Tag.yaml("float"), | 171 return new _ScalarNode(_Tag.yaml("float"), |
| 168 value: Math.parseDouble("NaN")); | 172 value: Math.parseDouble("NaN")); |
| 169 } | 173 } |
| 170 | 174 |
| 171 return null; | 175 return null; |
| 172 } | 176 } |
| 173 | 177 |
| 174 /** Parses a string scalar. */ | 178 /** Parses a string scalar. */ |
| 175 _ScalarNode parseString(String content) => | 179 _ScalarNode parseString(String content) => |
| 176 new _ScalarNode(_Tag.yaml("str"), value: content); | 180 new _ScalarNode(_Tag.yaml("str"), value: content); |
| 177 } | 181 } |
| OLD | NEW |