| 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 library yaml; | 5 library yaml; | 
| 6 | 6 | 
|  | 7 import 'package:string_scanner/string_scanner.dart'; | 
|  | 8 | 
| 7 import 'src/composer.dart'; | 9 import 'src/composer.dart'; | 
| 8 import 'src/constructor.dart'; | 10 import 'src/constructor.dart'; | 
| 9 import 'src/parser.dart'; | 11 import 'src/parser.dart'; | 
| 10 import 'src/yaml_exception.dart'; | 12 import 'src/yaml_exception.dart'; | 
| 11 import 'src/yaml_node.dart'; | 13 import 'src/yaml_node.dart'; | 
| 12 | 14 | 
| 13 export 'src/yaml_exception.dart'; | 15 export 'src/yaml_exception.dart'; | 
| 14 export 'src/yaml_node.dart'; | 16 export 'src/yaml_node.dart'; | 
| 15 | 17 | 
| 16 /// Loads a single document from a YAML string. | 18 /// Loads a single document from a YAML string. | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 33     loadYamlNode(yaml, sourceName: sourceName).value; | 35     loadYamlNode(yaml, sourceName: sourceName).value; | 
| 34 | 36 | 
| 35 /// Loads a single document from a YAML string as a [YamlNode]. | 37 /// Loads a single document from a YAML string as a [YamlNode]. | 
| 36 /// | 38 /// | 
| 37 /// This is just like [loadYaml], except that where [loadYaml] would return a | 39 /// This is just like [loadYaml], except that where [loadYaml] would return a | 
| 38 /// normal Dart value this returns a [YamlNode] instead. This allows the caller | 40 /// normal Dart value this returns a [YamlNode] instead. This allows the caller | 
| 39 /// to be confident that the return value will always be a [YamlNode]. | 41 /// to be confident that the return value will always be a [YamlNode]. | 
| 40 YamlNode loadYamlNode(String yaml, {String sourceName}) { | 42 YamlNode loadYamlNode(String yaml, {String sourceName}) { | 
| 41   var stream = loadYamlStream(yaml, sourceName: sourceName); | 43   var stream = loadYamlStream(yaml, sourceName: sourceName); | 
| 42   if (stream.length != 1) { | 44   if (stream.length != 1) { | 
| 43     throw new YamlException("Expected 1 document, were ${stream.length}."); | 45     throw new YamlException("Expected 1 document, were ${stream.length}.", | 
|  | 46         stream.span); | 
| 44   } | 47   } | 
| 45   return stream.nodes[0]; | 48   return stream.nodes[0]; | 
| 46 } | 49 } | 
| 47 | 50 | 
| 48 /// Loads a stream of documents from a YAML string. | 51 /// Loads a stream of documents from a YAML string. | 
| 49 /// | 52 /// | 
| 50 /// The return value is mostly normal Dart objects. However, since YAML mappings | 53 /// The return value is mostly normal Dart objects. However, since YAML mappings | 
| 51 /// support some key types that the default Dart map implementation doesn't | 54 /// support some key types that the default Dart map implementation doesn't | 
| 52 /// (NaN, lists, and maps), all maps in the returned document are [YamlMap]s. | 55 /// (NaN, lists, and maps), all maps in the returned document are [YamlMap]s. | 
| 53 /// These have a few small behavioral differences from the default Map | 56 /// These have a few small behavioral differences from the default Map | 
| 54 /// implementation; for details, see the [YamlMap] class. | 57 /// implementation; for details, see the [YamlMap] class. | 
| 55 /// | 58 /// | 
| 56 /// In future versions, maps will instead be [HashMap]s with a custom equality | 59 /// In future versions, maps will instead be [HashMap]s with a custom equality | 
| 57 /// operation. | 60 /// operation. | 
| 58 /// | 61 /// | 
| 59 /// If [sourceName] is passed, it's used as the name of the file or URL from | 62 /// If [sourceName] is passed, it's used as the name of the file or URL from | 
| 60 /// which the YAML originated for error reporting. | 63 /// which the YAML originated for error reporting. | 
| 61 YamlList loadYamlStream(String yaml, {String sourceName}) { | 64 YamlList loadYamlStream(String yaml, {String sourceName}) { | 
| 62   var pair; | 65   var pair; | 
| 63   try { | 66   try { | 
| 64     pair = new Parser(yaml, sourceName).l_yamlStream(); | 67     pair = new Parser(yaml, sourceName).l_yamlStream(); | 
| 65   } on FormatException catch (error) { | 68   } on StringScannerException catch (error) { | 
| 66     throw new YamlException(error.toString()); | 69     throw new YamlException(error.message, error.span); | 
| 67   } | 70   } | 
| 68 | 71 | 
| 69   var nodes = pair.first | 72   var nodes = pair.first | 
| 70       .map((doc) => new Constructor(new Composer(doc).compose()).construct()) | 73       .map((doc) => new Constructor(new Composer(doc).compose()).construct()) | 
| 71       .toList(); | 74       .toList(); | 
| 72   return new YamlList(nodes, pair.last); | 75   return new YamlList(nodes, pair.last); | 
| 73 } | 76 } | 
| OLD | NEW | 
|---|