| 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 * Translates a string of characters into a YAML serialization tree. | 6 * Translates a string of characters into a YAML serialization tree. |
| 7 * | 7 * |
| 8 * This parser is designed to closely follow the spec. All productions in the | 8 * This parser is designed to closely follow the spec. All productions in the |
| 9 * spec are numbered, and the corresponding methods in the parser have the same | 9 * spec are numbered, and the corresponding methods in the parser have the same |
| 10 * numbers. This is certainly not the most efficient way of parsing YAML, but it | 10 * numbers. This is certainly not the most efficient way of parsing YAML, but it |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 * Adds a tag and an anchor to [node], if they're defined. | 406 * Adds a tag and an anchor to [node], if they're defined. |
| 407 */ | 407 */ |
| 408 _Node addProps(_Node node, _Pair<_Tag, String> props) { | 408 _Node addProps(_Node node, _Pair<_Tag, String> props) { |
| 409 if (props == null || node == null) return node; | 409 if (props == null || node == null) return node; |
| 410 if (truth(props.first)) node.tag = props.first; | 410 if (truth(props.first)) node.tag = props.first; |
| 411 if (truth(props.last)) node.anchor = props.last; | 411 if (truth(props.last)) node.anchor = props.last; |
| 412 return node; | 412 return node; |
| 413 } | 413 } |
| 414 | 414 |
| 415 /** Creates a MappingNode from [pairs]. */ | 415 /** Creates a MappingNode from [pairs]. */ |
| 416 _MappingNode mappedBy(List<_Pair<_Node, _Node>> pairs) { | 416 _MappingNode map(List<_Pair<_Node, _Node>> pairs) { |
| 417 var content = new Map<_Node, _Node>(); | 417 var content = new Map<_Node, _Node>(); |
| 418 pairs.forEach((pair) => content[pair.first] = pair.last); | 418 pairs.forEach((pair) => content[pair.first] = pair.last); |
| 419 return new _MappingNode("?", content); | 419 return new _MappingNode("?", content); |
| 420 } | 420 } |
| 421 | 421 |
| 422 /** Runs [fn] in a context named [name]. Used for error reporting. */ | 422 /** Runs [fn] in a context named [name]. Used for error reporting. */ |
| 423 context(String name, fn()) { | 423 context(String name, fn()) { |
| 424 try { | 424 try { |
| 425 contextStack.add(name); | 425 contextStack.add(name); |
| 426 return fn(); | 426 return fn(); |
| (...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1318 var pair = or([ | 1318 var pair = or([ |
| 1319 () => transaction(() { | 1319 () => transaction(() { |
| 1320 if (!truth(c_indicator(C_MAPPING_KEY))) return null; | 1320 if (!truth(c_indicator(C_MAPPING_KEY))) return null; |
| 1321 if (!truth(s_separate(indent, ctx))) return null; | 1321 if (!truth(s_separate(indent, ctx))) return null; |
| 1322 return ns_flowMapExplicitEntry(indent, ctx); | 1322 return ns_flowMapExplicitEntry(indent, ctx); |
| 1323 }), | 1323 }), |
| 1324 () => ns_flowPairEntry(indent, ctx) | 1324 () => ns_flowPairEntry(indent, ctx) |
| 1325 ]); | 1325 ]); |
| 1326 if (!truth(pair)) return null; | 1326 if (!truth(pair)) return null; |
| 1327 | 1327 |
| 1328 return mappedBy([pair]); | 1328 return map([pair]); |
| 1329 } | 1329 } |
| 1330 | 1330 |
| 1331 // 151 | 1331 // 151 |
| 1332 _Pair<_Node, _Node> ns_flowPairEntry(int indent, int ctx) => or([ | 1332 _Pair<_Node, _Node> ns_flowPairEntry(int indent, int ctx) => or([ |
| 1333 () => ns_flowPairYamlKeyEntry(indent, ctx), | 1333 () => ns_flowPairYamlKeyEntry(indent, ctx), |
| 1334 () => c_ns_flowMapEmptyKeyEntry(indent, ctx), | 1334 () => c_ns_flowMapEmptyKeyEntry(indent, ctx), |
| 1335 () => c_ns_flowPairJsonKeyEntry(indent, ctx) | 1335 () => c_ns_flowPairJsonKeyEntry(indent, ctx) |
| 1336 ]); | 1336 ]); |
| 1337 | 1337 |
| 1338 // 152 | 1338 // 152 |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1701 _Node l_blockMapping(int indent) => context('mapping', () { | 1701 _Node l_blockMapping(int indent) => context('mapping', () { |
| 1702 var additionalIndent = countIndentation() - indent; | 1702 var additionalIndent = countIndentation() - indent; |
| 1703 if (additionalIndent <= 0) return null; | 1703 if (additionalIndent <= 0) return null; |
| 1704 | 1704 |
| 1705 var pairs = oneOrMore(() => transaction(() { | 1705 var pairs = oneOrMore(() => transaction(() { |
| 1706 if (!truth(s_indent(indent + additionalIndent))) return null; | 1706 if (!truth(s_indent(indent + additionalIndent))) return null; |
| 1707 return ns_l_blockMapEntry(indent + additionalIndent); | 1707 return ns_l_blockMapEntry(indent + additionalIndent); |
| 1708 })); | 1708 })); |
| 1709 if (!truth(pairs)) return null; | 1709 if (!truth(pairs)) return null; |
| 1710 | 1710 |
| 1711 return mappedBy(pairs); | 1711 return map(pairs); |
| 1712 }); | 1712 }); |
| 1713 | 1713 |
| 1714 // 188 | 1714 // 188 |
| 1715 _Pair<_Node, _Node> ns_l_blockMapEntry(int indent) => or([ | 1715 _Pair<_Node, _Node> ns_l_blockMapEntry(int indent) => or([ |
| 1716 () => c_l_blockMapExplicitEntry(indent), | 1716 () => c_l_blockMapExplicitEntry(indent), |
| 1717 () => ns_l_blockMapImplicitEntry(indent) | 1717 () => ns_l_blockMapImplicitEntry(indent) |
| 1718 ]); | 1718 ]); |
| 1719 | 1719 |
| 1720 // 189 | 1720 // 189 |
| 1721 _Pair<_Node, _Node> c_l_blockMapExplicitEntry(int indent) { | 1721 _Pair<_Node, _Node> c_l_blockMapExplicitEntry(int indent) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1770 _Node ns_l_compactMapping(int indent) => context('mapping', () { | 1770 _Node ns_l_compactMapping(int indent) => context('mapping', () { |
| 1771 var first = ns_l_blockMapEntry(indent); | 1771 var first = ns_l_blockMapEntry(indent); |
| 1772 if (!truth(first)) return null; | 1772 if (!truth(first)) return null; |
| 1773 | 1773 |
| 1774 var pairs = zeroOrMore(() => transaction(() { | 1774 var pairs = zeroOrMore(() => transaction(() { |
| 1775 if (!truth(s_indent(indent))) return null; | 1775 if (!truth(s_indent(indent))) return null; |
| 1776 return ns_l_blockMapEntry(indent); | 1776 return ns_l_blockMapEntry(indent); |
| 1777 })); | 1777 })); |
| 1778 pairs.insertRange(0, 1, first); | 1778 pairs.insertRange(0, 1, first); |
| 1779 | 1779 |
| 1780 return mappedBy(pairs); | 1780 return map(pairs); |
| 1781 }); | 1781 }); |
| 1782 | 1782 |
| 1783 // 196 | 1783 // 196 |
| 1784 _Node s_l_blockNode(int indent, int ctx) => or([ | 1784 _Node s_l_blockNode(int indent, int ctx) => or([ |
| 1785 () => s_l_blockInBlock(indent, ctx), | 1785 () => s_l_blockInBlock(indent, ctx), |
| 1786 () => s_l_flowInBlock(indent) | 1786 () => s_l_flowInBlock(indent) |
| 1787 ]); | 1787 ]); |
| 1788 | 1788 |
| 1789 // 197 | 1789 // 197 |
| 1790 _Node s_l_flowInBlock(int indent) => transaction(() { | 1790 _Node s_l_flowInBlock(int indent) => transaction(() { |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1990 var pair = contents[i]; | 1990 var pair = contents[i]; |
| 1991 if (pair.first.contains(pos)) return pair.last; | 1991 if (pair.first.contains(pos)) return pair.last; |
| 1992 } | 1992 } |
| 1993 return null; | 1993 return null; |
| 1994 } | 1994 } |
| 1995 | 1995 |
| 1996 /** Associates [value] with [range]. */ | 1996 /** Associates [value] with [range]. */ |
| 1997 operator[]=(_Range range, E value) => | 1997 operator[]=(_Range range, E value) => |
| 1998 contents.add(new _Pair<_Range, E>(range, value)); | 1998 contents.add(new _Pair<_Range, E>(range, value)); |
| 1999 } | 1999 } |
| OLD | NEW |