authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-06-07 05:37:18 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-06-07 05:37:18 -07:00
logdd5c32c4fd294bfe52cfd12a6fa92573cb7e8847
tree2ddb5c9a4897a173052c3909c1fd87f3cd4d8385
parenteaf70895de1efa8d01d58268919c4f7737554824

util/yaml


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

src/util/yaml.zig+8-7
......@@ -20,7 +20,7 @@ pub const Document = struct {
2020};
2121
2222pub const Item = union(enum) {
23 event: c.yaml_event_t,
23 event: Token,
2424 kv: Key,
2525 mapping: Mapping,
2626 sequence: Sequence,
......@@ -130,7 +130,8 @@ pub const Mapping = struct {
130130 }
131131};
132132
133pub const TokenList = []const c.yaml_event_t;
133pub const Token = c.yaml_event_t;
134pub const TokenList = []const Token;
134135
135136//
136137//
......@@ -143,8 +144,8 @@ pub fn parse(alloc: *std.mem.Allocator, input: []const u8) !Document {
143144
144145 _ = c.yaml_parser_set_input_string(&parser, input.ptr, input.len);
145146
146 const all_events = &std.ArrayList(c.yaml_event_t).init(alloc);
147 var event: c.yaml_event_t = undefined;
147 const all_events = &std.ArrayList(Token).init(alloc);
148 var event: Token = undefined;
148149 while (true) {
149150 const p = c.yaml_parser_parse(&parser, &event);
150151 if (p == 0) {
......@@ -183,7 +184,7 @@ pub const Parser = struct {
183184 return item.stream;
184185 }
185186
186 fn next(self: *Parser) ?c.yaml_event_t {
187 fn next(self: *Parser) ?Token {
187188 if (self.index >= self.tokens.len) {
188189 return null;
189190 }
......@@ -196,7 +197,7 @@ pub const Error =
196197 std.mem.Allocator.Error ||
197198 error{YamlUnexpectedToken};
198199
199fn parse_item(p: *Parser, start: ?c.yaml_event_t) Error!Item {
200fn parse_item(p: *Parser, start: ?Token) Error!Item {
200201 const tok = start orelse p.next();
201202 return switch (tok.?.type) {
202203 .YAML_STREAM_START_EVENT => Item{ .stream = try parse_stream(p) },
......@@ -280,7 +281,7 @@ fn parse_sequence(p: *Parser) Error!Sequence {
280281 }
281282}
282283
283fn get_event_string(event: c.yaml_event_t, lines: Array) []const u8 {
284fn get_event_string(event: Token, lines: Array) []const u8 {
284285 const sm = event.start_mark;
285286 const em = event.end_mark;
286287 return lines[sm.line][sm.column..em.column];