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 'src/loader.dart'; | 7 import 'src/loader.dart'; |
8 import 'src/style.dart'; | 8 import 'src/style.dart'; |
9 import 'src/yaml_document.dart'; | 9 import 'src/yaml_document.dart'; |
10 import 'src/yaml_exception.dart'; | 10 import 'src/yaml_exception.dart'; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 /// implementation; for details, see the [YamlMap] class. | 74 /// implementation; for details, see the [YamlMap] class. |
75 /// | 75 /// |
76 /// In future versions, maps will instead be [HashMap]s with a custom equality | 76 /// In future versions, maps will instead be [HashMap]s with a custom equality |
77 /// operation. | 77 /// operation. |
78 /// | 78 /// |
79 /// If [sourceUrl] is passed, it's used as the URL from which the YAML | 79 /// If [sourceUrl] is passed, it's used as the URL from which the YAML |
80 /// originated for error reporting. It can be a [String], a [Uri], or `null`. | 80 /// originated for error reporting. It can be a [String], a [Uri], or `null`. |
81 YamlList loadYamlStream(String yaml, {sourceUrl}) { | 81 YamlList loadYamlStream(String yaml, {sourceUrl}) { |
82 var loader = new Loader(yaml, sourceUrl: sourceUrl); | 82 var loader = new Loader(yaml, sourceUrl: sourceUrl); |
83 | 83 |
84 var documents = []; | 84 var documents = <YamlDocument>[]; |
85 var document = loader.load(); | 85 var document = loader.load(); |
86 while (document != null) { | 86 while (document != null) { |
87 documents.add(document); | 87 documents.add(document); |
88 document = loader.load(); | 88 document = loader.load(); |
89 } | 89 } |
90 | 90 |
| 91 // TODO(jmesserly): the type on the `document` parameter is a workaround for: |
| 92 // https://github.com/dart-lang/dev_compiler/issues/203 |
91 return new YamlList.internal( | 93 return new YamlList.internal( |
92 documents.map((document) => document.contents).toList(), | 94 documents.map((YamlDocument document) => document.contents).toList(), |
93 loader.span, | 95 loader.span, |
94 CollectionStyle.ANY); | 96 CollectionStyle.ANY); |
95 } | 97 } |
96 | 98 |
97 /// Loads a stream of documents from a YAML string. | 99 /// Loads a stream of documents from a YAML string. |
98 /// | 100 /// |
99 /// This is like [loadYamlStream], except that it returns [YamlDocument]s with | 101 /// This is like [loadYamlStream], except that it returns [YamlDocument]s with |
100 /// metadata wrapping the document contents. | 102 /// metadata wrapping the document contents. |
101 List<YamlDocument> loadYamlDocuments(String yaml, {sourceUrl}) { | 103 List<YamlDocument> loadYamlDocuments(String yaml, {sourceUrl}) { |
102 var loader = new Loader(yaml, sourceUrl: sourceUrl); | 104 var loader = new Loader(yaml, sourceUrl: sourceUrl); |
103 | 105 |
104 var documents = []; | 106 var documents = <YamlDocument>[]; |
105 var document = loader.load(); | 107 var document = loader.load(); |
106 while (document != null) { | 108 while (document != null) { |
107 documents.add(document); | 109 documents.add(document); |
108 document = loader.load(); | 110 document = loader.load(); |
109 } | 111 } |
110 | 112 |
111 return documents; | 113 return documents; |
112 } | 114 } |
OLD | NEW |