From a9d103161ba34361432c576c0bed088db2e093fa Mon Sep 17 00:00:00 2001 From: Meghan Date: Mon, 16 Nov 2020 17:57:52 -0800 Subject: [PATCH] yaml: support sequence being a string array --- src/util/yaml.zig | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/util/yaml.zig b/src/util/yaml.zig index 8eb6ce931b51661358c6caa2c474399c98bbcbc0..444041278b3425f4dc2c0882f8023d57b91b2d87 100644 --- a/src/util/yaml.zig +++ b/src/util/yaml.zig @@ -18,6 +18,7 @@ pub const Item = union(enum) { mapping: Mapping, sequence: []Item, document: Document, + string: []const u8, }; pub const Key = struct { @@ -190,20 +191,27 @@ fn condense_event_list_sequence(from: []Item, at: usize, to: *std.ArrayList(Item var i: usize = 1; while (true) : (i += 1) { const ele = from[at+i]; - if (ele == .event and @enumToInt(ele.event.type) == c.YAML_SEQUENCE_END_EVENT) { - break; - } if (ele == .event) { + if (@enumToInt(ele.event.type) == c.YAML_SEQUENCE_END_EVENT) { + break; + } + if (@enumToInt(ele.event.type) == c.YAML_SCALAR_EVENT) { + continue; + } return null; } } - const result = from[at+1..at+i]; - for (result) |item| { - std.debug.assert(item == .mapping); + const result = &std.ArrayList(Item).init(to.allocator); + for (from[at+1..at+i]) |item| { + try result.append(switch (item) { + .mapping => item, + .event => Item{ .string = get_event_string(item.event, lines) }, + else => unreachable, + }); } try to.append(Item{ - .sequence = result, + .sequence = result.items, }); return 0+i; } -- 2.54.0