| 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 part of yaml; | 5 part of yaml; |
| 6 | 6 |
| 7 /// Takes a parsed YAML document (what the spec calls the "serialization tree") | 7 /// Takes a parsed YAML document (what the spec calls the "serialization tree") |
| 8 /// and resolves aliases, resolves tags, and parses scalars to produce the | 8 /// and resolves aliases, resolves tags, and parses scalars to produce the |
| 9 /// "representation graph". | 9 /// "representation graph". |
| 10 class _Composer extends _Visitor { | 10 class _Composer extends _Visitor { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 /// that anchor is pointing to the representation graph node [result]. | 91 /// that anchor is pointing to the representation graph node [result]. |
| 92 _Node setAnchor(_Node anchored, _Node result) { | 92 _Node setAnchor(_Node anchored, _Node result) { |
| 93 if (anchored.anchor == null) return result; | 93 if (anchored.anchor == null) return result; |
| 94 result.anchor = '${idCounter++}'; | 94 result.anchor = '${idCounter++}'; |
| 95 anchors[anchored.anchor] = result; | 95 anchors[anchored.anchor] = result; |
| 96 return result; | 96 return result; |
| 97 } | 97 } |
| 98 | 98 |
| 99 /// Parses a null scalar. | 99 /// Parses a null scalar. |
| 100 _ScalarNode parseNull(String content) { | 100 _ScalarNode parseNull(String content) { |
| 101 if (!new RegExp("^(null|Null|NULL|~|)\$").hasMatch(content)) return null; | 101 if (!new RegExp(r"^(null|Null|NULL|~|)$").hasMatch(content)) return null; |
| 102 return new _ScalarNode(_Tag.yaml("null"), value: null); | 102 return new _ScalarNode(_Tag.yaml("null"), value: null); |
| 103 } | 103 } |
| 104 | 104 |
| 105 /// Parses a boolean scalar. | 105 /// Parses a boolean scalar. |
| 106 _ScalarNode parseBool(String content) { | 106 _ScalarNode parseBool(String content) { |
| 107 var match = new RegExp("^(?:(true|True|TRUE)|(false|False|FALSE))\$"). | 107 var match = new RegExp(r"^(?:(true|True|TRUE)|(false|False|FALSE))$"). |
| 108 firstMatch(content); | 108 firstMatch(content); |
| 109 if (match == null) return null; | 109 if (match == null) return null; |
| 110 return new _ScalarNode(_Tag.yaml("bool"), value: match.group(1) != null); | 110 return new _ScalarNode(_Tag.yaml("bool"), value: match.group(1) != null); |
| 111 } | 111 } |
| 112 | 112 |
| 113 /// Parses an integer scalar. | 113 /// Parses an integer scalar. |
| 114 _ScalarNode parseInt(String content) { | 114 _ScalarNode parseInt(String content) { |
| 115 var match = new RegExp("^[-+]?[0-9]+\$").firstMatch(content); | 115 var match = new RegExp(r"^[-+]?[0-9]+$").firstMatch(content); |
| 116 if (match != null) { | 116 if (match != null) { |
| 117 return new _ScalarNode(_Tag.yaml("int"), | 117 return new _ScalarNode(_Tag.yaml("int"), |
| 118 value: int.parse(match.group(0))); | 118 value: int.parse(match.group(0))); |
| 119 } | 119 } |
| 120 | 120 |
| 121 match = new RegExp("^0o([0-7]+)\$").firstMatch(content); | 121 match = new RegExp(r"^0o([0-7]+)$").firstMatch(content); |
| 122 if (match != null) { | 122 if (match != null) { |
| 123 int n = int.parse(match.group(1), radix: 8); | 123 int n = int.parse(match.group(1), radix: 8); |
| 124 return new _ScalarNode(_Tag.yaml("int"), value: n); | 124 return new _ScalarNode(_Tag.yaml("int"), value: n); |
| 125 } | 125 } |
| 126 | 126 |
| 127 match = new RegExp("^0x[0-9a-fA-F]+\$").firstMatch(content); | 127 match = new RegExp(r"^0x[0-9a-fA-F]+$").firstMatch(content); |
| 128 if (match != null) { | 128 if (match != null) { |
| 129 return new _ScalarNode(_Tag.yaml("int"), | 129 return new _ScalarNode(_Tag.yaml("int"), |
| 130 value: int.parse(match.group(0))); | 130 value: int.parse(match.group(0))); |
| 131 } | 131 } |
| 132 | 132 |
| 133 return null; | 133 return null; |
| 134 } | 134 } |
| 135 | 135 |
| 136 /// Parses a floating-point scalar. | 136 /// Parses a floating-point scalar. |
| 137 _ScalarNode parseFloat(String content) { | 137 _ScalarNode parseFloat(String content) { |
| 138 var match = new RegExp( | 138 var match = new RegExp( |
| 139 "^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?\$"). | 139 r"^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$"). |
| 140 firstMatch(content); | 140 firstMatch(content); |
| 141 if (match != null) { | 141 if (match != null) { |
| 142 // YAML allows floats of the form "0.", but Dart does not. Fix up those | 142 // YAML allows floats of the form "0.", but Dart does not. Fix up those |
| 143 // floats by removing the trailing dot. | 143 // floats by removing the trailing dot. |
| 144 var matchStr = match.group(0).replaceAll(new RegExp(r"\.$"), ""); | 144 var matchStr = match.group(0).replaceAll(new RegExp(r"\.$"), ""); |
| 145 return new _ScalarNode(_Tag.yaml("float"), | 145 return new _ScalarNode(_Tag.yaml("float"), |
| 146 value: double.parse(matchStr)); | 146 value: double.parse(matchStr)); |
| 147 } | 147 } |
| 148 | 148 |
| 149 match = new RegExp("^([+-]?)\.(inf|Inf|INF)\$").firstMatch(content); | 149 match = new RegExp(r"^([+-]?)\.(inf|Inf|INF)$").firstMatch(content); |
| 150 if (match != null) { | 150 if (match != null) { |
| 151 var value = match.group(1) == "-" ? -double.INFINITY : double.INFINITY; | 151 var value = match.group(1) == "-" ? -double.INFINITY : double.INFINITY; |
| 152 return new _ScalarNode(_Tag.yaml("float"), value: value); | 152 return new _ScalarNode(_Tag.yaml("float"), value: value); |
| 153 } | 153 } |
| 154 | 154 |
| 155 match = new RegExp("^\.(nan|NaN|NAN)\$").firstMatch(content); | 155 match = new RegExp(r"^\.(nan|NaN|NAN)$").firstMatch(content); |
| 156 if (match != null) { | 156 if (match != null) { |
| 157 return new _ScalarNode(_Tag.yaml("float"), value: double.NAN); | 157 return new _ScalarNode(_Tag.yaml("float"), value: double.NAN); |
| 158 } | 158 } |
| 159 | 159 |
| 160 return null; | 160 return null; |
| 161 } | 161 } |
| 162 | 162 |
| 163 /// Parses a string scalar. | 163 /// Parses a string scalar. |
| 164 _ScalarNode parseString(String content) => | 164 _ScalarNode parseString(String content) => |
| 165 new _ScalarNode(_Tag.yaml("str"), value: content); | 165 new _ScalarNode(_Tag.yaml("str"), value: content); |
| 166 } | 166 } |
| OLD | NEW |