authorgravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-11-16 17:57:52 -08:00
committergravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-11-16 17:57:52 -08:00
loga9d103161ba34361432c576c0bed088db2e093fa
tree3eefae6595d892f0f7faaff54481383b9117aa4c
parentb35ff753ae17c8de839287bfb98bd14c7c699b4b

yaml: support sequence being a string array


1 files changed, 15 insertions(+), 7 deletions(-)

src/util/yaml.zig+15-7
...@@ -18,6 +18,7 @@ pub const Item = union(enum) {...@@ -18,6 +18,7 @@ pub const Item = union(enum) {
18 mapping: Mapping,18 mapping: Mapping,
19 sequence: []Item,19 sequence: []Item,
20 document: Document,20 document: Document,
21 string: []const u8,
21};22};
2223
23pub const Key = struct {24pub const Key = struct {
...@@ -190,20 +191,27 @@ fn condense_event_list_sequence(from: []Item, at: usize, to: *std.ArrayList(Item...@@ -190,20 +191,27 @@ fn condense_event_list_sequence(from: []Item, at: usize, to: *std.ArrayList(Item
190 var i: usize = 1;191 var i: usize = 1;
191 while (true) : (i += 1) {192 while (true) : (i += 1) {
192 const ele = from[at+i];193 const ele = from[at+i];
193 if (ele == .event and @enumToInt(ele.event.type) == c.YAML_SEQUENCE_END_EVENT) {
194 break;
195 }
196 if (ele == .event) {194 if (ele == .event) {
195 if (@enumToInt(ele.event.type) == c.YAML_SEQUENCE_END_EVENT) {
196 break;
197 }
198 if (@enumToInt(ele.event.type) == c.YAML_SCALAR_EVENT) {
199 continue;
200 }
197 return null;201 return null;
198 }202 }
199 }203 }
200204
201 const result = from[at+1..at+i];205 const result = &std.ArrayList(Item).init(to.allocator);
202 for (result) |item| {206 for (from[at+1..at+i]) |item| {
203 std.debug.assert(item == .mapping);207 try result.append(switch (item) {
208 .mapping => item,
209 .event => Item{ .string = get_event_string(item.event, lines) },
210 else => unreachable,
211 });
204 }212 }
205 try to.append(Item{213 try to.append(Item{
206 .sequence = result,214 .sequence = result.items,
207 });215 });
208 return 0+i;216 return 0+i;
209}217}