| 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.parser; | 5 library yaml.parser; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:source_maps/source_maps.dart'; | 9 import 'package:source_span/source_span.dart'; |
| 10 import 'package:string_scanner/string_scanner.dart'; | 10 import 'package:string_scanner/string_scanner.dart'; |
| 11 | 11 |
| 12 import 'equality.dart'; | 12 import 'equality.dart'; |
| 13 import 'model.dart'; | 13 import 'model.dart'; |
| 14 import 'utils.dart'; | 14 import 'utils.dart'; |
| 15 | 15 |
| 16 /// Translates a string of characters into a YAML serialization tree. | 16 /// Translates a string of characters into a YAML serialization tree. |
| 17 /// | 17 /// |
| 18 /// This parser is designed to closely follow the spec. All productions in the | 18 /// This parser is designed to closely follow the spec. All productions in the |
| 19 /// spec are numbered, and the corresponding methods in the parser have the same | 19 /// spec are numbered, and the corresponding methods in the parser have the same |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 | 144 |
| 145 /// The buffer containing the string currently being captured. | 145 /// The buffer containing the string currently being captured. |
| 146 StringBuffer _capturedString; | 146 StringBuffer _capturedString; |
| 147 | 147 |
| 148 /// The beginning of the current section of the captured string. | 148 /// The beginning of the current section of the captured string. |
| 149 int _captureStart; | 149 int _captureStart; |
| 150 | 150 |
| 151 /// Whether the current string capture is being overridden. | 151 /// Whether the current string capture is being overridden. |
| 152 bool _capturingAs = false; | 152 bool _capturingAs = false; |
| 153 | 153 |
| 154 Parser(String yaml, String sourceName) | 154 Parser(String yaml, sourceUrl) |
| 155 : _scanner = new SpanScanner(yaml, sourceName) { | 155 : _scanner = new SpanScanner(yaml, sourceUrl: sourceUrl) { |
| 156 _farthestState = _scanner.state; | 156 _farthestState = _scanner.state; |
| 157 } | 157 } |
| 158 | 158 |
| 159 /// Returns the character at the current position, then moves that position | 159 /// Returns the character at the current position, then moves that position |
| 160 /// forward one character. | 160 /// forward one character. |
| 161 int next() => _scanner.readChar(); | 161 int next() => _scanner.readChar(); |
| 162 | 162 |
| 163 /// Returns the code unit at the current position, or the character [i] | 163 /// Returns the code unit at the current position, or the character [i] |
| 164 /// characters after the current position. | 164 /// characters after the current position. |
| 165 int peek([int i = 0]) => _scanner.peekChar(i); | 165 int peek([int i = 0]) => _scanner.peekChar(i); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 | 319 |
| 320 /// Adds a tag and an anchor to [node], if they're defined. | 320 /// Adds a tag and an anchor to [node], if they're defined. |
| 321 Node addProps(Node node, Pair<Tag, String> props) { | 321 Node addProps(Node node, Pair<Tag, String> props) { |
| 322 if (props == null || node == null) return node; | 322 if (props == null || node == null) return node; |
| 323 if (truth(props.first)) node.tag = props.first; | 323 if (truth(props.first)) node.tag = props.first; |
| 324 if (truth(props.last)) node.anchor = props.last; | 324 if (truth(props.last)) node.anchor = props.last; |
| 325 return node; | 325 return node; |
| 326 } | 326 } |
| 327 | 327 |
| 328 /// Creates a MappingNode from [pairs]. | 328 /// Creates a MappingNode from [pairs]. |
| 329 MappingNode map(List<Pair<Node, Node>> pairs, Span span) { | 329 MappingNode map(List<Pair<Node, Node>> pairs, SourceSpan span) { |
| 330 var content = new Map<Node, Node>(); | 330 var content = new Map<Node, Node>(); |
| 331 pairs.forEach((pair) => content[pair.first] = pair.last); | 331 pairs.forEach((pair) => content[pair.first] = pair.last); |
| 332 return new MappingNode("?", content, span); | 332 return new MappingNode("?", content, span); |
| 333 } | 333 } |
| 334 | 334 |
| 335 /// Runs [fn] in a context named [name]. Used for error reporting. | 335 /// Runs [fn] in a context named [name]. Used for error reporting. |
| 336 context(String name, fn()) { | 336 context(String name, fn()) { |
| 337 try { | 337 try { |
| 338 _contextStack.add(name); | 338 _contextStack.add(name); |
| 339 return fn(); | 339 return fn(); |
| (...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1815 if (doc != null) return doc; | 1815 if (doc != null) return doc; |
| 1816 parseFailed(); | 1816 parseFailed(); |
| 1817 return null; // Unreachable. | 1817 return null; // Unreachable. |
| 1818 } | 1818 } |
| 1819 | 1819 |
| 1820 // 210 | 1820 // 210 |
| 1821 Node l_anyDocument() => | 1821 Node l_anyDocument() => |
| 1822 or([l_directiveDocument, l_explicitDocument, l_bareDocument]); | 1822 or([l_directiveDocument, l_explicitDocument, l_bareDocument]); |
| 1823 | 1823 |
| 1824 // 211 | 1824 // 211 |
| 1825 Pair<List<Node>, Span> l_yamlStream() { | 1825 Pair<List<Node>, SourceSpan> l_yamlStream() { |
| 1826 var start = _scanner.state; | 1826 var start = _scanner.state; |
| 1827 var docs = []; | 1827 var docs = []; |
| 1828 zeroOrMore(l_documentPrefix); | 1828 zeroOrMore(l_documentPrefix); |
| 1829 var first = zeroOrOne(l_anyDocument); | 1829 var first = zeroOrOne(l_anyDocument); |
| 1830 if (!truth(first)) first = e_node(); | 1830 if (!truth(first)) first = e_node(); |
| 1831 docs.add(first); | 1831 docs.add(first); |
| 1832 | 1832 |
| 1833 zeroOrMore(() { | 1833 zeroOrMore(() { |
| 1834 var doc; | 1834 var doc; |
| 1835 if (truth(oneOrMore(l_documentSuffix))) { | 1835 if (truth(oneOrMore(l_documentSuffix))) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1891 for (var pair in _contents.reversed) { | 1891 for (var pair in _contents.reversed) { |
| 1892 if (pair.first.contains(pos)) return pair.last; | 1892 if (pair.first.contains(pos)) return pair.last; |
| 1893 } | 1893 } |
| 1894 return null; | 1894 return null; |
| 1895 } | 1895 } |
| 1896 | 1896 |
| 1897 /// Associates [value] with [range]. | 1897 /// Associates [value] with [range]. |
| 1898 operator[]=(_Range range, E value) => | 1898 operator[]=(_Range range, E value) => |
| 1899 _contents.add(new Pair<_Range, E>(range, value)); | 1899 _contents.add(new Pair<_Range, E>(range, value)); |
| 1900 } | 1900 } |
| OLD | NEW |