Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Side by Side Diff: pkg/yaml/lib/src/parser.dart

Issue 302313007: Attach source range information to parsed YAML nodes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix tests Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/yaml/lib/src/model.dart ('k') | pkg/yaml/lib/src/utils.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:string_scanner/string_scanner.dart'; 10 import 'package:string_scanner/string_scanner.dart';
10 11
12 import 'equality.dart';
11 import 'model.dart'; 13 import 'model.dart';
14 import 'utils.dart';
12 import 'yaml_exception.dart'; 15 import 'yaml_exception.dart';
13 import 'yaml_map.dart';
14 16
15 /// Translates a string of characters into a YAML serialization tree. 17 /// Translates a string of characters into a YAML serialization tree.
16 /// 18 ///
17 /// This parser is designed to closely follow the spec. All productions in the 19 /// This parser is designed to closely follow the spec. All productions in the
18 /// spec are numbered, and the corresponding methods in the parser have the same 20 /// spec are numbered, and the corresponding methods in the parser have the same
19 /// numbers. This is certainly not the most efficient way of parsing YAML, but 21 /// numbers. This is certainly not the most efficient way of parsing YAML, but
20 /// it is the easiest to write and read in the context of the spec. 22 /// it is the easiest to write and read in the context of the spec.
21 /// 23 ///
22 /// Methods corresponding to productions are also named as in the spec, 24 /// Methods corresponding to productions are also named as in the spec,
23 /// translating the name of the method (although not the annotation characters) 25 /// translating the name of the method (although not the annotation characters)
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 return res; 312 return res;
311 } 313 }
312 314
313 void flushCapture() { 315 void flushCapture() {
314 _capturedString.write(_scanner.string.substring( 316 _capturedString.write(_scanner.string.substring(
315 _captureStart, _scanner.position)); 317 _captureStart, _scanner.position));
316 _captureStart = _scanner.position; 318 _captureStart = _scanner.position;
317 } 319 }
318 320
319 /// Adds a tag and an anchor to [node], if they're defined. 321 /// Adds a tag and an anchor to [node], if they're defined.
320 Node addProps(Node node, _Pair<Tag, String> props) { 322 Node addProps(Node node, Pair<Tag, String> props) {
321 if (props == null || node == null) return node; 323 if (props == null || node == null) return node;
322 if (truth(props.first)) node.tag = props.first; 324 if (truth(props.first)) node.tag = props.first;
323 if (truth(props.last)) node.anchor = props.last; 325 if (truth(props.last)) node.anchor = props.last;
324 return node; 326 return node;
325 } 327 }
326 328
327 /// Creates a MappingNode from [pairs]. 329 /// Creates a MappingNode from [pairs].
328 MappingNode map(List<_Pair<Node, Node>> pairs) { 330 MappingNode map(List<Pair<Node, Node>> pairs, Span span) {
329 var content = new Map<Node, Node>(); 331 var content = new Map<Node, Node>();
330 pairs.forEach((pair) => content[pair.first] = pair.last); 332 pairs.forEach((pair) => content[pair.first] = pair.last);
331 return new MappingNode("?", content); 333 return new MappingNode("?", content, span);
332 } 334 }
333 335
334 /// Runs [fn] in a context named [name]. Used for error reporting. 336 /// Runs [fn] in a context named [name]. Used for error reporting.
335 context(String name, fn()) { 337 context(String name, fn()) {
336 try { 338 try {
337 _contextStack.add(name); 339 _contextStack.add(name);
338 return fn(); 340 return fn();
339 } finally { 341 } finally {
340 var popped = _contextStack.removeLast(); 342 var popped = _contextStack.removeLast();
341 assert(popped == name); 343 assert(popped == name);
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 // 81 754 // 81
753 bool s_separateLines(int indent) { 755 bool s_separateLines(int indent) {
754 return transaction(() => s_l_comments() && s_flowLinePrefix(indent)) || 756 return transaction(() => s_l_comments() && s_flowLinePrefix(indent)) ||
755 s_separateInLine(); 757 s_separateInLine();
756 } 758 }
757 759
758 // 82 760 // 82
759 bool l_directive() => false; // TODO(nweiz): implement 761 bool l_directive() => false; // TODO(nweiz): implement
760 762
761 // 96 763 // 96
762 _Pair<Tag, String> c_ns_properties(int indent, int ctx) { 764 Pair<Tag, String> c_ns_properties(int indent, int ctx) {
763 var tag, anchor; 765 var tag, anchor;
764 tag = c_ns_tagProperty(); 766 tag = c_ns_tagProperty();
765 if (truth(tag)) { 767 if (truth(tag)) {
766 anchor = transaction(() { 768 anchor = transaction(() {
767 if (!truth(s_separate(indent, ctx))) return null; 769 if (!truth(s_separate(indent, ctx))) return null;
768 return c_ns_anchorProperty(); 770 return c_ns_anchorProperty();
769 }); 771 });
770 return new _Pair<Tag, String>(tag, anchor); 772 return new Pair<Tag, String>(tag, anchor);
771 } 773 }
772 774
773 anchor = c_ns_anchorProperty(); 775 anchor = c_ns_anchorProperty();
774 if (truth(anchor)) { 776 if (truth(anchor)) {
775 tag = transaction(() { 777 tag = transaction(() {
776 if (!truth(s_separate(indent, ctx))) return null; 778 if (!truth(s_separate(indent, ctx))) return null;
777 return c_ns_tagProperty(); 779 return c_ns_tagProperty();
778 }); 780 });
779 return new _Pair<Tag, String>(tag, anchor); 781 return new Pair<Tag, String>(tag, anchor);
780 } 782 }
781 783
782 return null; 784 return null;
783 } 785 }
784 786
785 // 97 787 // 97
786 Tag c_ns_tagProperty() => null; // TODO(nweiz): implement 788 Tag c_ns_tagProperty() => null; // TODO(nweiz): implement
787 789
788 // 101 790 // 101
789 String c_ns_anchorProperty() => null; // TODO(nweiz): implement 791 String c_ns_anchorProperty() => null; // TODO(nweiz): implement
790 792
791 // 102 793 // 102
792 bool isAnchorChar(int char) => isNonSpace(char) && !isFlowIndicator(char); 794 bool isAnchorChar(int char) => isNonSpace(char) && !isFlowIndicator(char);
793 795
794 // 103 796 // 103
795 String ns_anchorName() => 797 String ns_anchorName() =>
796 captureString(() => oneOrMore(() => consume(isAnchorChar))); 798 captureString(() => oneOrMore(() => consume(isAnchorChar)));
797 799
798 // 104 800 // 104
799 Node c_ns_aliasNode() { 801 Node c_ns_aliasNode() {
802 var start = _scanner.state;
800 if (!truth(c_indicator(C_ALIAS))) return null; 803 if (!truth(c_indicator(C_ALIAS))) return null;
801 var name = expect(ns_anchorName(), 'anchor name'); 804 var name = expect(ns_anchorName(), 'anchor name');
802 return new AliasNode(name); 805 return new AliasNode(name, _scanner.spanFrom(start));
803 } 806 }
804 807
805 // 105 808 // 105
806 ScalarNode e_scalar() => new ScalarNode("?", content: ""); 809 ScalarNode e_scalar() => new ScalarNode("?", _scanner.emptySpan, content: "");
807 810
808 // 106 811 // 106
809 ScalarNode e_node() => e_scalar(); 812 ScalarNode e_node() => e_scalar();
810 813
811 // 107 814 // 107
812 bool nb_doubleChar() => or([ 815 bool nb_doubleChar() => or([
813 c_ns_escChar, 816 c_ns_escChar,
814 () => consume((c) => isJson(c) && c != BACKSLASH && c != DOUBLE_QUOTE) 817 () => consume((c) => isJson(c) && c != BACKSLASH && c != DOUBLE_QUOTE)
815 ]); 818 ]);
816 819
817 // 108 820 // 108
818 bool ns_doubleChar() => !isSpace(peek()) && truth(nb_doubleChar()); 821 bool ns_doubleChar() => !isSpace(peek()) && truth(nb_doubleChar());
819 822
820 // 109 823 // 109
821 Node c_doubleQuoted(int indent, int ctx) => context('string', () { 824 Node c_doubleQuoted(int indent, int ctx) => context('string', () {
822 return transaction(() { 825 return transaction(() {
826 var start = _scanner.state;
823 if (!truth(c_indicator(C_DOUBLE_QUOTE))) return null; 827 if (!truth(c_indicator(C_DOUBLE_QUOTE))) return null;
824 var contents = nb_doubleText(indent, ctx); 828 var contents = nb_doubleText(indent, ctx);
825 if (!truth(c_indicator(C_DOUBLE_QUOTE))) return null; 829 if (!truth(c_indicator(C_DOUBLE_QUOTE))) return null;
826 return new ScalarNode("!", content: contents); 830 return new ScalarNode("!", _scanner.spanFrom(start), content: contents);
827 }); 831 });
828 }); 832 });
829 833
830 // 110 834 // 110
831 String nb_doubleText(int indent, int ctx) => captureString(() { 835 String nb_doubleText(int indent, int ctx) => captureString(() {
832 switch (ctx) { 836 switch (ctx) {
833 case FLOW_OUT: 837 case FLOW_OUT:
834 case FLOW_IN: 838 case FLOW_IN:
835 nb_doubleMultiLine(indent); 839 nb_doubleMultiLine(indent);
836 break; 840 break;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 c_quotedQuote, 905 c_quotedQuote,
902 () => consume((c) => isJson(c) && c != SINGLE_QUOTE) 906 () => consume((c) => isJson(c) && c != SINGLE_QUOTE)
903 ]); 907 ]);
904 908
905 // 119 909 // 119
906 bool ns_singleChar() => !isSpace(peek()) && truth(nb_singleChar()); 910 bool ns_singleChar() => !isSpace(peek()) && truth(nb_singleChar());
907 911
908 // 120 912 // 120
909 Node c_singleQuoted(int indent, int ctx) => context('string', () { 913 Node c_singleQuoted(int indent, int ctx) => context('string', () {
910 return transaction(() { 914 return transaction(() {
915 var start = _scanner.state;
911 if (!truth(c_indicator(C_SINGLE_QUOTE))) return null; 916 if (!truth(c_indicator(C_SINGLE_QUOTE))) return null;
912 var contents = nb_singleText(indent, ctx); 917 var contents = nb_singleText(indent, ctx);
913 if (!truth(c_indicator(C_SINGLE_QUOTE))) return null; 918 if (!truth(c_indicator(C_SINGLE_QUOTE))) return null;
914 return new ScalarNode("!", content: contents); 919 return new ScalarNode("!", _scanner.spanFrom(start), content: contents);
915 }); 920 });
916 }); 921 });
917 922
918 // 121 923 // 121
919 String nb_singleText(int indent, int ctx) => captureString(() { 924 String nb_singleText(int indent, int ctx) => captureString(() {
920 switch (ctx) { 925 switch (ctx) {
921 case FLOW_OUT: 926 case FLOW_OUT:
922 case FLOW_IN: 927 case FLOW_IN:
923 nb_singleMultiLine(indent); 928 nb_singleMultiLine(indent);
924 break; 929 break;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 return FLOW_IN; 1073 return FLOW_IN;
1069 case BLOCK_KEY: 1074 case BLOCK_KEY:
1070 case FLOW_KEY: 1075 case FLOW_KEY:
1071 return FLOW_KEY; 1076 return FLOW_KEY;
1072 } 1077 }
1073 throw "unreachable"; 1078 throw "unreachable";
1074 } 1079 }
1075 1080
1076 // 137 1081 // 137
1077 SequenceNode c_flowSequence(int indent, int ctx) => transaction(() { 1082 SequenceNode c_flowSequence(int indent, int ctx) => transaction(() {
1083 var start = _scanner.state;
1078 if (!truth(c_indicator(C_SEQUENCE_START))) return null; 1084 if (!truth(c_indicator(C_SEQUENCE_START))) return null;
1079 zeroOrOne(() => s_separate(indent, ctx)); 1085 zeroOrOne(() => s_separate(indent, ctx));
1080 var content = zeroOrOne(() => ns_s_flowSeqEntries(indent, inFlow(ctx))); 1086 var content = zeroOrOne(() => ns_s_flowSeqEntries(indent, inFlow(ctx)));
1081 if (!truth(c_indicator(C_SEQUENCE_END))) return null; 1087 if (!truth(c_indicator(C_SEQUENCE_END))) return null;
1082 return new SequenceNode("?", new List<Node>.from(content)); 1088 return new SequenceNode("?", new List<Node>.from(content),
1089 _scanner.spanFrom(start));
1083 }); 1090 });
1084 1091
1085 // 138 1092 // 138
1086 Iterable<Node> ns_s_flowSeqEntries(int indent, int ctx) { 1093 Iterable<Node> ns_s_flowSeqEntries(int indent, int ctx) {
1087 var first = ns_flowSeqEntry(indent, ctx); 1094 var first = ns_flowSeqEntry(indent, ctx);
1088 if (!truth(first)) return new Queue<Node>(); 1095 if (!truth(first)) return new Queue<Node>();
1089 zeroOrOne(() => s_separate(indent, ctx)); 1096 zeroOrOne(() => s_separate(indent, ctx));
1090 1097
1091 var rest; 1098 var rest;
1092 if (truth(c_indicator(C_COLLECT_ENTRY))) { 1099 if (truth(c_indicator(C_COLLECT_ENTRY))) {
1093 zeroOrOne(() => s_separate(indent, ctx)); 1100 zeroOrOne(() => s_separate(indent, ctx));
1094 rest = zeroOrOne(() => ns_s_flowSeqEntries(indent, ctx)); 1101 rest = zeroOrOne(() => ns_s_flowSeqEntries(indent, ctx));
1095 } 1102 }
1096 1103
1097 if (rest == null) rest = new Queue<Node>(); 1104 if (rest == null) rest = new Queue<Node>();
1098 rest.addFirst(first); 1105 rest.addFirst(first);
1099 1106
1100 return rest; 1107 return rest;
1101 } 1108 }
1102 1109
1103 // 139 1110 // 139
1104 Node ns_flowSeqEntry(int indent, int ctx) => or([ 1111 Node ns_flowSeqEntry(int indent, int ctx) => or([
1105 () => ns_flowPair(indent, ctx), 1112 () => ns_flowPair(indent, ctx),
1106 () => ns_flowNode(indent, ctx) 1113 () => ns_flowNode(indent, ctx)
1107 ]); 1114 ]);
1108 1115
1109 // 140 1116 // 140
1110 Node c_flowMapping(int indent, int ctx) { 1117 Node c_flowMapping(int indent, int ctx) {
1118 var start = _scanner.state;
1111 if (!truth(c_indicator(C_MAPPING_START))) return null; 1119 if (!truth(c_indicator(C_MAPPING_START))) return null;
1112 zeroOrOne(() => s_separate(indent, ctx)); 1120 zeroOrOne(() => s_separate(indent, ctx));
1113 var content = zeroOrOne(() => ns_s_flowMapEntries(indent, inFlow(ctx))); 1121 var content = zeroOrOne(() => ns_s_flowMapEntries(indent, inFlow(ctx)));
1114 if (!truth(c_indicator(C_MAPPING_END))) return null; 1122 if (!truth(c_indicator(C_MAPPING_END))) return null;
1115 return new MappingNode("?", content); 1123 return new MappingNode("?", content, _scanner.spanFrom(start));
1116 } 1124 }
1117 1125
1118 // 141 1126 // 141
1119 YamlMap ns_s_flowMapEntries(int indent, int ctx) { 1127 Map ns_s_flowMapEntries(int indent, int ctx) {
1120 var first = ns_flowMapEntry(indent, ctx); 1128 var first = ns_flowMapEntry(indent, ctx);
1121 if (!truth(first)) return new YamlMap(); 1129 if (!truth(first)) return deepEqualsMap();
1122 zeroOrOne(() => s_separate(indent, ctx)); 1130 zeroOrOne(() => s_separate(indent, ctx));
1123 1131
1124 var rest; 1132 var rest;
1125 if (truth(c_indicator(C_COLLECT_ENTRY))) { 1133 if (truth(c_indicator(C_COLLECT_ENTRY))) {
1126 zeroOrOne(() => s_separate(indent, ctx)); 1134 zeroOrOne(() => s_separate(indent, ctx));
1127 rest = ns_s_flowMapEntries(indent, ctx); 1135 rest = ns_s_flowMapEntries(indent, ctx);
1128 } 1136 }
1129 1137
1130 if (rest == null) rest = new YamlMap(); 1138 if (rest == null) rest = deepEqualsMap();
1131 1139
1132 // TODO(nweiz): Duplicate keys should be an error. This includes keys with 1140 // TODO(nweiz): Duplicate keys should be an error. This includes keys with
1133 // different representations but the same value (e.g. 10 vs 0xa). To make 1141 // different representations but the same value (e.g. 10 vs 0xa). To make
1134 // this user-friendly we'll probably also want to associate nodes with a 1142 // this user-friendly we'll probably also want to associate nodes with a
1135 // source range. 1143 // source range.
1136 if (!rest.containsKey(first.first)) rest[first.first] = first.last; 1144 if (!rest.containsKey(first.first)) rest[first.first] = first.last;
1137 1145
1138 return rest; 1146 return rest;
1139 } 1147 }
1140 1148
1141 // 142 1149 // 142
1142 _Pair<Node, Node> ns_flowMapEntry(int indent, int ctx) => or([ 1150 Pair<Node, Node> ns_flowMapEntry(int indent, int ctx) => or([
1143 () => transaction(() { 1151 () => transaction(() {
1144 if (!truth(c_indicator(C_MAPPING_KEY))) return false; 1152 if (!truth(c_indicator(C_MAPPING_KEY))) return false;
1145 if (!truth(s_separate(indent, ctx))) return false; 1153 if (!truth(s_separate(indent, ctx))) return false;
1146 return ns_flowMapExplicitEntry(indent, ctx); 1154 return ns_flowMapExplicitEntry(indent, ctx);
1147 }), 1155 }),
1148 () => ns_flowMapImplicitEntry(indent, ctx) 1156 () => ns_flowMapImplicitEntry(indent, ctx)
1149 ]); 1157 ]);
1150 1158
1151 // 143 1159 // 143
1152 _Pair<Node, Node> ns_flowMapExplicitEntry(int indent, int ctx) => or([ 1160 Pair<Node, Node> ns_flowMapExplicitEntry(int indent, int ctx) => or([
1153 () => ns_flowMapImplicitEntry(indent, ctx), 1161 () => ns_flowMapImplicitEntry(indent, ctx),
1154 () => new _Pair<Node, Node>(e_node(), e_node()) 1162 () => new Pair<Node, Node>(e_node(), e_node())
1155 ]); 1163 ]);
1156 1164
1157 // 144 1165 // 144
1158 _Pair<Node, Node> ns_flowMapImplicitEntry(int indent, int ctx) => or([ 1166 Pair<Node, Node> ns_flowMapImplicitEntry(int indent, int ctx) => or([
1159 () => ns_flowMapYamlKeyEntry(indent, ctx), 1167 () => ns_flowMapYamlKeyEntry(indent, ctx),
1160 () => c_ns_flowMapEmptyKeyEntry(indent, ctx), 1168 () => c_ns_flowMapEmptyKeyEntry(indent, ctx),
1161 () => c_ns_flowMapJsonKeyEntry(indent, ctx) 1169 () => c_ns_flowMapJsonKeyEntry(indent, ctx)
1162 ]); 1170 ]);
1163 1171
1164 // 145 1172 // 145
1165 _Pair<Node, Node> ns_flowMapYamlKeyEntry(int indent, int ctx) { 1173 Pair<Node, Node> ns_flowMapYamlKeyEntry(int indent, int ctx) {
1166 var key = ns_flowYamlNode(indent, ctx); 1174 var key = ns_flowYamlNode(indent, ctx);
1167 if (!truth(key)) return null; 1175 if (!truth(key)) return null;
1168 var value = or([ 1176 var value = or([
1169 () => transaction(() { 1177 () => transaction(() {
1170 zeroOrOne(() => s_separate(indent, ctx)); 1178 zeroOrOne(() => s_separate(indent, ctx));
1171 return c_ns_flowMapSeparateValue(indent, ctx); 1179 return c_ns_flowMapSeparateValue(indent, ctx);
1172 }), 1180 }),
1173 e_node 1181 e_node
1174 ]); 1182 ]);
1175 return new _Pair<Node, Node>(key, value); 1183 return new Pair<Node, Node>(key, value);
1176 } 1184 }
1177 1185
1178 // 146 1186 // 146
1179 _Pair<Node, Node> c_ns_flowMapEmptyKeyEntry(int indent, int ctx) { 1187 Pair<Node, Node> c_ns_flowMapEmptyKeyEntry(int indent, int ctx) {
1180 var value = c_ns_flowMapSeparateValue(indent, ctx); 1188 var value = c_ns_flowMapSeparateValue(indent, ctx);
1181 if (!truth(value)) return null; 1189 if (!truth(value)) return null;
1182 return new _Pair<Node, Node>(e_node(), value); 1190 return new Pair<Node, Node>(e_node(), value);
1183 } 1191 }
1184 1192
1185 // 147 1193 // 147
1186 Node c_ns_flowMapSeparateValue(int indent, int ctx) => transaction(() { 1194 Node c_ns_flowMapSeparateValue(int indent, int ctx) => transaction(() {
1187 if (!truth(c_indicator(C_MAPPING_VALUE))) return null; 1195 if (!truth(c_indicator(C_MAPPING_VALUE))) return null;
1188 if (isPlainSafe(ctx, peek())) return null; 1196 if (isPlainSafe(ctx, peek())) return null;
1189 1197
1190 return or([ 1198 return or([
1191 () => transaction(() { 1199 () => transaction(() {
1192 if (!s_separate(indent, ctx)) return null; 1200 if (!s_separate(indent, ctx)) return null;
1193 return ns_flowNode(indent, ctx); 1201 return ns_flowNode(indent, ctx);
1194 }), 1202 }),
1195 e_node 1203 e_node
1196 ]); 1204 ]);
1197 }); 1205 });
1198 1206
1199 // 148 1207 // 148
1200 _Pair<Node, Node> c_ns_flowMapJsonKeyEntry(int indent, int ctx) { 1208 Pair<Node, Node> c_ns_flowMapJsonKeyEntry(int indent, int ctx) {
1201 var key = c_flowJsonNode(indent, ctx); 1209 var key = c_flowJsonNode(indent, ctx);
1202 if (!truth(key)) return null; 1210 if (!truth(key)) return null;
1203 var value = or([ 1211 var value = or([
1204 () => transaction(() { 1212 () => transaction(() {
1205 zeroOrOne(() => s_separate(indent, ctx)); 1213 zeroOrOne(() => s_separate(indent, ctx));
1206 return c_ns_flowMapAdjacentValue(indent, ctx); 1214 return c_ns_flowMapAdjacentValue(indent, ctx);
1207 }), 1215 }),
1208 e_node 1216 e_node
1209 ]); 1217 ]);
1210 return new _Pair<Node, Node>(key, value); 1218 return new Pair<Node, Node>(key, value);
1211 } 1219 }
1212 1220
1213 // 149 1221 // 149
1214 Node c_ns_flowMapAdjacentValue(int indent, int ctx) { 1222 Node c_ns_flowMapAdjacentValue(int indent, int ctx) {
1215 if (!truth(c_indicator(C_MAPPING_VALUE))) return null; 1223 if (!truth(c_indicator(C_MAPPING_VALUE))) return null;
1216 return or([ 1224 return or([
1217 () => transaction(() { 1225 () => transaction(() {
1218 zeroOrOne(() => s_separate(indent, ctx)); 1226 zeroOrOne(() => s_separate(indent, ctx));
1219 return ns_flowNode(indent, ctx); 1227 return ns_flowNode(indent, ctx);
1220 }), 1228 }),
1221 e_node 1229 e_node
1222 ]); 1230 ]);
1223 } 1231 }
1224 1232
1225 // 150 1233 // 150
1226 Node ns_flowPair(int indent, int ctx) { 1234 Node ns_flowPair(int indent, int ctx) {
1235 var start = _scanner.state;
1227 var pair = or([ 1236 var pair = or([
1228 () => transaction(() { 1237 () => transaction(() {
1229 if (!truth(c_indicator(C_MAPPING_KEY))) return null; 1238 if (!truth(c_indicator(C_MAPPING_KEY))) return null;
1230 if (!truth(s_separate(indent, ctx))) return null; 1239 if (!truth(s_separate(indent, ctx))) return null;
1231 return ns_flowMapExplicitEntry(indent, ctx); 1240 return ns_flowMapExplicitEntry(indent, ctx);
1232 }), 1241 }),
1233 () => ns_flowPairEntry(indent, ctx) 1242 () => ns_flowPairEntry(indent, ctx)
1234 ]); 1243 ]);
1235 if (!truth(pair)) return null; 1244 if (!truth(pair)) return null;
1236 1245
1237 return map([pair]); 1246 return map([pair], _scanner.spanFrom(start));
1238 } 1247 }
1239 1248
1240 // 151 1249 // 151
1241 _Pair<Node, Node> ns_flowPairEntry(int indent, int ctx) => or([ 1250 Pair<Node, Node> ns_flowPairEntry(int indent, int ctx) => or([
1242 () => ns_flowPairYamlKeyEntry(indent, ctx), 1251 () => ns_flowPairYamlKeyEntry(indent, ctx),
1243 () => c_ns_flowMapEmptyKeyEntry(indent, ctx), 1252 () => c_ns_flowMapEmptyKeyEntry(indent, ctx),
1244 () => c_ns_flowPairJsonKeyEntry(indent, ctx) 1253 () => c_ns_flowPairJsonKeyEntry(indent, ctx)
1245 ]); 1254 ]);
1246 1255
1247 // 152 1256 // 152
1248 _Pair<Node, Node> ns_flowPairYamlKeyEntry(int indent, int ctx) => 1257 Pair<Node, Node> ns_flowPairYamlKeyEntry(int indent, int ctx) =>
1249 transaction(() { 1258 transaction(() {
1250 var key = ns_s_implicitYamlKey(FLOW_KEY); 1259 var key = ns_s_implicitYamlKey(FLOW_KEY);
1251 if (!truth(key)) return null; 1260 if (!truth(key)) return null;
1252 var value = c_ns_flowMapSeparateValue(indent, ctx); 1261 var value = c_ns_flowMapSeparateValue(indent, ctx);
1253 if (!truth(value)) return null; 1262 if (!truth(value)) return null;
1254 return new _Pair<Node, Node>(key, value); 1263 return new Pair<Node, Node>(key, value);
1255 }); 1264 });
1256 1265
1257 // 153 1266 // 153
1258 _Pair<Node, Node> c_ns_flowPairJsonKeyEntry(int indent, int ctx) => 1267 Pair<Node, Node> c_ns_flowPairJsonKeyEntry(int indent, int ctx) =>
1259 transaction(() { 1268 transaction(() {
1260 var key = c_s_implicitJsonKey(FLOW_KEY); 1269 var key = c_s_implicitJsonKey(FLOW_KEY);
1261 if (!truth(key)) return null; 1270 if (!truth(key)) return null;
1262 var value = c_ns_flowMapAdjacentValue(indent, ctx); 1271 var value = c_ns_flowMapAdjacentValue(indent, ctx);
1263 if (!truth(value)) return null; 1272 if (!truth(value)) return null;
1264 return new _Pair<Node, Node>(key, value); 1273 return new Pair<Node, Node>(key, value);
1265 }); 1274 });
1266 1275
1267 // 154 1276 // 154
1268 Node ns_s_implicitYamlKey(int ctx) => transaction(() { 1277 Node ns_s_implicitYamlKey(int ctx) => transaction(() {
1269 // TODO(nweiz): this is supposed to be limited to 1024 characters. 1278 // TODO(nweiz): this is supposed to be limited to 1024 characters.
1270 1279
1271 // The indentation parameter is "null" since it's unused in this path 1280 // The indentation parameter is "null" since it's unused in this path
1272 var node = ns_flowYamlNode(null, ctx); 1281 var node = ns_flowYamlNode(null, ctx);
1273 if (!truth(node)) return null; 1282 if (!truth(node)) return null;
1274 zeroOrOne(s_separateInLine); 1283 zeroOrOne(s_separateInLine);
1275 return node; 1284 return node;
1276 }); 1285 });
1277 1286
1278 // 155 1287 // 155
1279 Node c_s_implicitJsonKey(int ctx) => transaction(() { 1288 Node c_s_implicitJsonKey(int ctx) => transaction(() {
1280 // TODO(nweiz): this is supposed to be limited to 1024 characters. 1289 // TODO(nweiz): this is supposed to be limited to 1024 characters.
1281 1290
1282 // The indentation parameter is "null" since it's unused in this path 1291 // The indentation parameter is "null" since it's unused in this path
1283 var node = c_flowJsonNode(null, ctx); 1292 var node = c_flowJsonNode(null, ctx);
1284 if (!truth(node)) return null; 1293 if (!truth(node)) return null;
1285 zeroOrOne(s_separateInLine); 1294 zeroOrOne(s_separateInLine);
1286 return node; 1295 return node;
1287 }); 1296 });
1288 1297
1289 // 156 1298 // 156
1290 Node ns_flowYamlContent(int indent, int ctx) { 1299 Node ns_flowYamlContent(int indent, int ctx) {
1300 var start = _scanner.state;
1291 var str = ns_plain(indent, ctx); 1301 var str = ns_plain(indent, ctx);
1292 if (!truth(str)) return null; 1302 if (!truth(str)) return null;
1293 return new ScalarNode("?", content: str); 1303 return new ScalarNode("?", _scanner.spanFrom(start), content: str);
1294 } 1304 }
1295 1305
1296 // 157 1306 // 157
1297 Node c_flowJsonContent(int indent, int ctx) => or([ 1307 Node c_flowJsonContent(int indent, int ctx) => or([
1298 () => c_flowSequence(indent, ctx), 1308 () => c_flowSequence(indent, ctx),
1299 () => c_flowMapping(indent, ctx), 1309 () => c_flowMapping(indent, ctx),
1300 () => c_singleQuoted(indent, ctx), 1310 () => c_singleQuoted(indent, ctx),
1301 () => c_doubleQuoted(indent, ctx) 1311 () => c_doubleQuoted(indent, ctx)
1302 ]); 1312 ]);
1303 1313
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1430 bool l_trailComments(int indent) => transaction(() { 1440 bool l_trailComments(int indent) => transaction(() {
1431 if (!truth(s_indentLessThanOrEqualTo(indent))) return false; 1441 if (!truth(s_indentLessThanOrEqualTo(indent))) return false;
1432 if (!truth(c_nb_commentText())) return false; 1442 if (!truth(c_nb_commentText())) return false;
1433 if (!truth(b_comment())) return false; 1443 if (!truth(b_comment())) return false;
1434 zeroOrMore(l_comment); 1444 zeroOrMore(l_comment);
1435 return true; 1445 return true;
1436 }); 1446 });
1437 1447
1438 // 170 1448 // 170
1439 Node c_l_literal(int indent) => transaction(() { 1449 Node c_l_literal(int indent) => transaction(() {
1450 var start = _scanner.state;
1440 if (!truth(c_indicator(C_LITERAL))) return null; 1451 if (!truth(c_indicator(C_LITERAL))) return null;
1441 var header = c_b_blockHeader(); 1452 var header = c_b_blockHeader();
1442 if (!truth(header)) return null; 1453 if (!truth(header)) return null;
1443 1454
1444 var additionalIndent = blockScalarAdditionalIndentation(header, indent); 1455 var additionalIndent = blockScalarAdditionalIndentation(header, indent);
1445 var content = l_literalContent(indent + additionalIndent, header.chomping); 1456 var content = l_literalContent(indent + additionalIndent, header.chomping);
1446 if (!truth(content)) return null; 1457 if (!truth(content)) return null;
1447 1458
1448 return new ScalarNode("!", content: content); 1459 return new ScalarNode("!", _scanner.spanFrom(start), content: content);
1449 }); 1460 });
1450 1461
1451 // 171 1462 // 171
1452 bool l_nb_literalText(int indent) => transaction(() { 1463 bool l_nb_literalText(int indent) => transaction(() {
1453 zeroOrMore(() => captureAs("\n", () => l_empty(indent, BLOCK_IN))); 1464 zeroOrMore(() => captureAs("\n", () => l_empty(indent, BLOCK_IN)));
1454 if (!truth(captureAs("", () => s_indent(indent)))) return false; 1465 if (!truth(captureAs("", () => s_indent(indent)))) return false;
1455 return truth(oneOrMore(() => consume(isNonBreak))); 1466 return truth(oneOrMore(() => consume(isNonBreak)));
1456 }); 1467 });
1457 1468
1458 // 172 1469 // 172
1459 bool b_nb_literalNext(int indent) => transaction(() { 1470 bool b_nb_literalNext(int indent) => transaction(() {
1460 if (!truth(b_asLineFeed())) return false; 1471 if (!truth(b_asLineFeed())) return false;
1461 return l_nb_literalText(indent); 1472 return l_nb_literalText(indent);
1462 }); 1473 });
1463 1474
1464 // 173 1475 // 173
1465 String l_literalContent(int indent, int chomping) => captureString(() { 1476 String l_literalContent(int indent, int chomping) => captureString(() {
1466 transaction(() { 1477 transaction(() {
1467 if (!truth(l_nb_literalText(indent))) return false; 1478 if (!truth(l_nb_literalText(indent))) return false;
1468 zeroOrMore(() => b_nb_literalNext(indent)); 1479 zeroOrMore(() => b_nb_literalNext(indent));
1469 return b_chompedLast(chomping); 1480 return b_chompedLast(chomping);
1470 }); 1481 });
1471 l_chompedEmpty(indent, chomping); 1482 l_chompedEmpty(indent, chomping);
1472 return true; 1483 return true;
1473 }); 1484 });
1474 1485
1475 // 174 1486 // 174
1476 Node c_l_folded(int indent) => transaction(() { 1487 Node c_l_folded(int indent) => transaction(() {
1488 var start = _scanner.state;
1477 if (!truth(c_indicator(C_FOLDED))) return null; 1489 if (!truth(c_indicator(C_FOLDED))) return null;
1478 var header = c_b_blockHeader(); 1490 var header = c_b_blockHeader();
1479 if (!truth(header)) return null; 1491 if (!truth(header)) return null;
1480 1492
1481 var additionalIndent = blockScalarAdditionalIndentation(header, indent); 1493 var additionalIndent = blockScalarAdditionalIndentation(header, indent);
1482 var content = l_foldedContent(indent + additionalIndent, header.chomping); 1494 var content = l_foldedContent(indent + additionalIndent, header.chomping);
1483 if (!truth(content)) return null; 1495 if (!truth(content)) return null;
1484 1496
1485 return new ScalarNode("!", content: content); 1497 return new ScalarNode("!", _scanner.spanFrom(start), content: content);
1486 }); 1498 });
1487 1499
1488 // 175 1500 // 175
1489 bool s_nb_foldedText(int indent) => transaction(() { 1501 bool s_nb_foldedText(int indent) => transaction(() {
1490 if (!truth(captureAs('', () => s_indent(indent)))) return false; 1502 if (!truth(captureAs('', () => s_indent(indent)))) return false;
1491 if (!truth(consume(isNonSpace))) return false; 1503 if (!truth(consume(isNonSpace))) return false;
1492 zeroOrMore(() => consume(isNonBreak)); 1504 zeroOrMore(() => consume(isNonBreak));
1493 return true; 1505 return true;
1494 }); 1506 });
1495 1507
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 }); 1567 });
1556 l_chompedEmpty(indent, chomping); 1568 l_chompedEmpty(indent, chomping);
1557 return true; 1569 return true;
1558 }); 1570 });
1559 1571
1560 // 183 1572 // 183
1561 SequenceNode l_blockSequence(int indent) => context('sequence', () { 1573 SequenceNode l_blockSequence(int indent) => context('sequence', () {
1562 var additionalIndent = countIndentation() - indent; 1574 var additionalIndent = countIndentation() - indent;
1563 if (additionalIndent <= 0) return null; 1575 if (additionalIndent <= 0) return null;
1564 1576
1577 var start = _scanner.state;
1565 var content = oneOrMore(() => transaction(() { 1578 var content = oneOrMore(() => transaction(() {
1566 if (!truth(s_indent(indent + additionalIndent))) return null; 1579 if (!truth(s_indent(indent + additionalIndent))) return null;
1567 return c_l_blockSeqEntry(indent + additionalIndent); 1580 return c_l_blockSeqEntry(indent + additionalIndent);
1568 })); 1581 }));
1569 if (!truth(content)) return null; 1582 if (!truth(content)) return null;
1570 1583
1571 return new SequenceNode("?", content); 1584 return new SequenceNode("?", content, _scanner.spanFrom(start));
1572 }); 1585 });
1573 1586
1574 // 184 1587 // 184
1575 Node c_l_blockSeqEntry(int indent) => transaction(() { 1588 Node c_l_blockSeqEntry(int indent) => transaction(() {
1576 if (!truth(c_indicator(C_SEQUENCE_ENTRY))) return null; 1589 if (!truth(c_indicator(C_SEQUENCE_ENTRY))) return null;
1577 if (isNonSpace(peek())) return null; 1590 if (isNonSpace(peek())) return null;
1578 1591
1579 return s_l_blockIndented(indent, BLOCK_IN); 1592 return s_l_blockIndented(indent, BLOCK_IN);
1580 }); 1593 });
1581 1594
1582 // 185 1595 // 185
1583 Node s_l_blockIndented(int indent, int ctx) { 1596 Node s_l_blockIndented(int indent, int ctx) {
1584 var additionalIndent = countIndentation(); 1597 var additionalIndent = countIndentation();
1585 return or([ 1598 return or([
1586 () => transaction(() { 1599 () => transaction(() {
1587 if (!truth(s_indent(additionalIndent))) return null; 1600 if (!truth(s_indent(additionalIndent))) return null;
1588 return or([ 1601 return or([
1589 () => ns_l_compactSequence(indent + 1 + additionalIndent), 1602 () => ns_l_compactSequence(indent + 1 + additionalIndent),
1590 () => ns_l_compactMapping(indent + 1 + additionalIndent)]); 1603 () => ns_l_compactMapping(indent + 1 + additionalIndent)]);
1591 }), 1604 }),
1592 () => s_l_blockNode(indent, ctx), 1605 () => s_l_blockNode(indent, ctx),
1593 () => s_l_comments() ? e_node() : null]); 1606 () => s_l_comments() ? e_node() : null]);
1594 } 1607 }
1595 1608
1596 // 186 1609 // 186
1597 Node ns_l_compactSequence(int indent) => context('sequence', () { 1610 Node ns_l_compactSequence(int indent) => context('sequence', () {
1611 var start = _scanner.state;
1598 var first = c_l_blockSeqEntry(indent); 1612 var first = c_l_blockSeqEntry(indent);
1599 if (!truth(first)) return null; 1613 if (!truth(first)) return null;
1600 1614
1601 var content = zeroOrMore(() => transaction(() { 1615 var content = zeroOrMore(() => transaction(() {
1602 if (!truth(s_indent(indent))) return null; 1616 if (!truth(s_indent(indent))) return null;
1603 return c_l_blockSeqEntry(indent); 1617 return c_l_blockSeqEntry(indent);
1604 })); 1618 }));
1605 content.insert(0, first); 1619 content.insert(0, first);
1606 1620
1607 return new SequenceNode("?", content); 1621 return new SequenceNode("?", content, _scanner.spanFrom(start));
1608 }); 1622 });
1609 1623
1610 // 187 1624 // 187
1611 Node l_blockMapping(int indent) => context('mapping', () { 1625 Node l_blockMapping(int indent) => context('mapping', () {
1612 var additionalIndent = countIndentation() - indent; 1626 var additionalIndent = countIndentation() - indent;
1613 if (additionalIndent <= 0) return null; 1627 if (additionalIndent <= 0) return null;
1614 1628
1629 var start = _scanner.state;
1615 var pairs = oneOrMore(() => transaction(() { 1630 var pairs = oneOrMore(() => transaction(() {
1616 if (!truth(s_indent(indent + additionalIndent))) return null; 1631 if (!truth(s_indent(indent + additionalIndent))) return null;
1617 return ns_l_blockMapEntry(indent + additionalIndent); 1632 return ns_l_blockMapEntry(indent + additionalIndent);
1618 })); 1633 }));
1619 if (!truth(pairs)) return null; 1634 if (!truth(pairs)) return null;
1620 1635
1621 return map(pairs); 1636 return map(pairs, _scanner.spanFrom(start));
1622 }); 1637 });
1623 1638
1624 // 188 1639 // 188
1625 _Pair<Node, Node> ns_l_blockMapEntry(int indent) => or([ 1640 Pair<Node, Node> ns_l_blockMapEntry(int indent) => or([
1626 () => c_l_blockMapExplicitEntry(indent), 1641 () => c_l_blockMapExplicitEntry(indent),
1627 () => ns_l_blockMapImplicitEntry(indent) 1642 () => ns_l_blockMapImplicitEntry(indent)
1628 ]); 1643 ]);
1629 1644
1630 // 189 1645 // 189
1631 _Pair<Node, Node> c_l_blockMapExplicitEntry(int indent) { 1646 Pair<Node, Node> c_l_blockMapExplicitEntry(int indent) {
1632 var key = c_l_blockMapExplicitKey(indent); 1647 var key = c_l_blockMapExplicitKey(indent);
1633 if (!truth(key)) return null; 1648 if (!truth(key)) return null;
1634 1649
1635 var value = or([ 1650 var value = or([
1636 () => l_blockMapExplicitValue(indent), 1651 () => l_blockMapExplicitValue(indent),
1637 e_node 1652 e_node
1638 ]); 1653 ]);
1639 1654
1640 return new _Pair<Node, Node>(key, value); 1655 return new Pair<Node, Node>(key, value);
1641 } 1656 }
1642 1657
1643 // 190 1658 // 190
1644 Node c_l_blockMapExplicitKey(int indent) => transaction(() { 1659 Node c_l_blockMapExplicitKey(int indent) => transaction(() {
1645 if (!truth(c_indicator(C_MAPPING_KEY))) return null; 1660 if (!truth(c_indicator(C_MAPPING_KEY))) return null;
1646 return s_l_blockIndented(indent, BLOCK_OUT); 1661 return s_l_blockIndented(indent, BLOCK_OUT);
1647 }); 1662 });
1648 1663
1649 // 191 1664 // 191
1650 Node l_blockMapExplicitValue(int indent) => transaction(() { 1665 Node l_blockMapExplicitValue(int indent) => transaction(() {
1651 if (!truth(s_indent(indent))) return null; 1666 if (!truth(s_indent(indent))) return null;
1652 if (!truth(c_indicator(C_MAPPING_VALUE))) return null; 1667 if (!truth(c_indicator(C_MAPPING_VALUE))) return null;
1653 return s_l_blockIndented(indent, BLOCK_OUT); 1668 return s_l_blockIndented(indent, BLOCK_OUT);
1654 }); 1669 });
1655 1670
1656 // 192 1671 // 192
1657 _Pair<Node, Node> ns_l_blockMapImplicitEntry(int indent) => transaction(() { 1672 Pair<Node, Node> ns_l_blockMapImplicitEntry(int indent) => transaction(() {
1658 var key = or([ns_s_blockMapImplicitKey, e_node]); 1673 var key = or([ns_s_blockMapImplicitKey, e_node]);
1659 var value = c_l_blockMapImplicitValue(indent); 1674 var value = c_l_blockMapImplicitValue(indent);
1660 return truth(value) ? new _Pair<Node, Node>(key, value) : null; 1675 return truth(value) ? new Pair<Node, Node>(key, value) : null;
1661 }); 1676 });
1662 1677
1663 // 193 1678 // 193
1664 Node ns_s_blockMapImplicitKey() => context('mapping key', () => or([ 1679 Node ns_s_blockMapImplicitKey() => context('mapping key', () => or([
1665 () => c_s_implicitJsonKey(BLOCK_KEY), 1680 () => c_s_implicitJsonKey(BLOCK_KEY),
1666 () => ns_s_implicitYamlKey(BLOCK_KEY) 1681 () => ns_s_implicitYamlKey(BLOCK_KEY)
1667 ])); 1682 ]));
1668 1683
1669 // 194 1684 // 194
1670 Node c_l_blockMapImplicitValue(int indent) => context('mapping value', () => 1685 Node c_l_blockMapImplicitValue(int indent) => context('mapping value', () =>
1671 transaction(() { 1686 transaction(() {
1672 if (!truth(c_indicator(C_MAPPING_VALUE))) return null; 1687 if (!truth(c_indicator(C_MAPPING_VALUE))) return null;
1673 return or([ 1688 return or([
1674 () => s_l_blockNode(indent, BLOCK_OUT), 1689 () => s_l_blockNode(indent, BLOCK_OUT),
1675 () => s_l_comments() ? e_node() : null 1690 () => s_l_comments() ? e_node() : null
1676 ]); 1691 ]);
1677 })); 1692 }));
1678 1693
1679 // 195 1694 // 195
1680 Node ns_l_compactMapping(int indent) => context('mapping', () { 1695 Node ns_l_compactMapping(int indent) => context('mapping', () {
1696 var start = _scanner.state;
1681 var first = ns_l_blockMapEntry(indent); 1697 var first = ns_l_blockMapEntry(indent);
1682 if (!truth(first)) return null; 1698 if (!truth(first)) return null;
1683 1699
1684 var pairs = zeroOrMore(() => transaction(() { 1700 var pairs = zeroOrMore(() => transaction(() {
1685 if (!truth(s_indent(indent))) return null; 1701 if (!truth(s_indent(indent))) return null;
1686 return ns_l_blockMapEntry(indent); 1702 return ns_l_blockMapEntry(indent);
1687 })); 1703 }));
1688 pairs.insert(0, first); 1704 pairs.insert(0, first);
1689 1705
1690 return map(pairs); 1706 return map(pairs, _scanner.spanFrom(start));
1691 }); 1707 });
1692 1708
1693 // 196 1709 // 196
1694 Node s_l_blockNode(int indent, int ctx) => or([ 1710 Node s_l_blockNode(int indent, int ctx) => or([
1695 () => s_l_blockInBlock(indent, ctx), 1711 () => s_l_blockInBlock(indent, ctx),
1696 () => s_l_flowInBlock(indent) 1712 () => s_l_flowInBlock(indent)
1697 ]); 1713 ]);
1698 1714
1699 // 197 1715 // 197
1700 Node s_l_flowInBlock(int indent) => transaction(() { 1716 Node s_l_flowInBlock(int indent) => transaction(() {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1800 if (doc != null) return doc; 1816 if (doc != null) return doc;
1801 parseFailed(); 1817 parseFailed();
1802 return null; // Unreachable. 1818 return null; // Unreachable.
1803 } 1819 }
1804 1820
1805 // 210 1821 // 210
1806 Node l_anyDocument() => 1822 Node l_anyDocument() =>
1807 or([l_directiveDocument, l_explicitDocument, l_bareDocument]); 1823 or([l_directiveDocument, l_explicitDocument, l_bareDocument]);
1808 1824
1809 // 211 1825 // 211
1810 List<Node> l_yamlStream() { 1826 Pair<List<Node>, Span> l_yamlStream() {
1827 var start = _scanner.state;
1811 var docs = []; 1828 var docs = [];
1812 zeroOrMore(l_documentPrefix); 1829 zeroOrMore(l_documentPrefix);
1813 var first = zeroOrOne(l_anyDocument); 1830 var first = zeroOrOne(l_anyDocument);
1814 if (!truth(first)) first = e_node(); 1831 if (!truth(first)) first = e_node();
1815 docs.add(first); 1832 docs.add(first);
1816 1833
1817 zeroOrMore(() { 1834 zeroOrMore(() {
1818 var doc; 1835 var doc;
1819 if (truth(oneOrMore(l_documentSuffix))) { 1836 if (truth(oneOrMore(l_documentSuffix))) {
1820 zeroOrMore(l_documentPrefix); 1837 zeroOrMore(l_documentPrefix);
1821 doc = zeroOrOne(l_anyDocument); 1838 doc = zeroOrOne(l_anyDocument);
1822 } else { 1839 } else {
1823 zeroOrMore(l_documentPrefix); 1840 zeroOrMore(l_documentPrefix);
1824 doc = zeroOrOne(l_explicitDocument); 1841 doc = zeroOrOne(l_explicitDocument);
1825 } 1842 }
1826 if (truth(doc)) docs.add(doc); 1843 if (truth(doc)) docs.add(doc);
1827 return doc; 1844 return doc;
1828 }); 1845 });
1829 1846
1830 if (!_scanner.isDone) parseFailed(); 1847 if (!_scanner.isDone) parseFailed();
1831 return docs; 1848 return new Pair(docs, _scanner.spanFrom(start));
1832 } 1849 }
1833 } 1850 }
1834 1851
1835 /// A pair of values.
1836 class _Pair<E, F> {
1837 E first;
1838 F last;
1839
1840 _Pair(this.first, this.last);
1841
1842 String toString() => '($first, $last)';
1843 }
1844
1845 /// The information in the header for a block scalar. 1852 /// The information in the header for a block scalar.
1846 class _BlockHeader { 1853 class _BlockHeader {
1847 final int additionalIndent; 1854 final int additionalIndent;
1848 final int chomping; 1855 final int chomping;
1849 1856
1850 _BlockHeader(this.additionalIndent, this.chomping); 1857 _BlockHeader(this.additionalIndent, this.chomping);
1851 1858
1852 bool get autoDetectIndent => additionalIndent == null; 1859 bool get autoDetectIndent => additionalIndent == null;
1853 } 1860 }
1854 1861
(...skipping 10 matching lines...) Expand all
1865 1872
1866 /// Returns whether or not [pos] lies within this range. 1873 /// Returns whether or not [pos] lies within this range.
1867 bool contains(int pos) => pos >= start && pos <= end; 1874 bool contains(int pos) => pos >= start && pos <= end;
1868 } 1875 }
1869 1876
1870 /// A map that associates [E] values with [_Range]s. It's efficient to create 1877 /// A map that associates [E] values with [_Range]s. It's efficient to create
1871 /// new associations, but finding the value associated with a position is more 1878 /// new associations, but finding the value associated with a position is more
1872 /// expensive. 1879 /// expensive.
1873 class _RangeMap<E> { 1880 class _RangeMap<E> {
1874 /// The ranges and their associated elements. 1881 /// The ranges and their associated elements.
1875 final List<_Pair<_Range, E>> _contents = <_Pair<_Range, E>>[]; 1882 final List<Pair<_Range, E>> _contents = <Pair<_Range, E>>[];
1876 1883
1877 _RangeMap(); 1884 _RangeMap();
1878 1885
1879 /// Returns the value associated with the range in which [pos] lies, or null 1886 /// Returns the value associated with the range in which [pos] lies, or null
1880 /// if there is no such range. If there's more than one such range, the most 1887 /// if there is no such range. If there's more than one such range, the most
1881 /// recently set one is used. 1888 /// recently set one is used.
1882 E operator[](int pos) { 1889 E operator[](int pos) {
1883 // Iterate backwards through contents so the more recent range takes 1890 // Iterate backwards through contents so the more recent range takes
1884 // precedence. 1891 // precedence.
1885 for (var pair in _contents.reversed) { 1892 for (var pair in _contents.reversed) {
1886 if (pair.first.contains(pos)) return pair.last; 1893 if (pair.first.contains(pos)) return pair.last;
1887 } 1894 }
1888 return null; 1895 return null;
1889 } 1896 }
1890 1897
1891 /// Associates [value] with [range]. 1898 /// Associates [value] with [range].
1892 operator[]=(_Range range, E value) => 1899 operator[]=(_Range range, E value) =>
1893 _contents.add(new _Pair<_Range, E>(range, value)); 1900 _contents.add(new Pair<_Range, E>(range, value));
1894 } 1901 }
OLDNEW
« no previous file with comments | « pkg/yaml/lib/src/model.dart ('k') | pkg/yaml/lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698