| ... | ... | @@ -20,7 +20,7 @@ pub const Document = struct { |
| 20 | 20 | }; |
| 21 | 21 | |
| 22 | 22 | pub const Item = union(enum) { |
| 23 | | event: c.yaml_event_t, |
| 23 | event: Token, |
| 24 | 24 | kv: Key, |
| 25 | 25 | mapping: Mapping, |
| 26 | 26 | sequence: Sequence, |
| ... | ... | @@ -130,7 +130,8 @@ pub const Mapping = struct { |
| 130 | 130 | } |
| 131 | 131 | }; |
| 132 | 132 | |
| 133 | | pub const TokenList = []const c.yaml_event_t; |
| 133 | pub const Token = c.yaml_event_t; |
| 134 | pub const TokenList = []const Token; |
| 134 | 135 | |
| 135 | 136 | // |
| 136 | 137 | // |
| ... | ... | @@ -143,8 +144,8 @@ pub fn parse(alloc: *std.mem.Allocator, input: []const u8) !Document { |
| 143 | 144 | |
| 144 | 145 | _ = c.yaml_parser_set_input_string(&parser, input.ptr, input.len); |
| 145 | 146 | |
| 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; |
| 148 | 149 | while (true) { |
| 149 | 150 | const p = c.yaml_parser_parse(&parser, &event); |
| 150 | 151 | if (p == 0) { |
| ... | ... | @@ -183,7 +184,7 @@ pub const Parser = struct { |
| 183 | 184 | return item.stream; |
| 184 | 185 | } |
| 185 | 186 | |
| 186 | | fn next(self: *Parser) ?c.yaml_event_t { |
| 187 | fn next(self: *Parser) ?Token { |
| 187 | 188 | if (self.index >= self.tokens.len) { |
| 188 | 189 | return null; |
| 189 | 190 | } |
| ... | ... | @@ -196,7 +197,7 @@ pub const Error = |
| 196 | 197 | std.mem.Allocator.Error || |
| 197 | 198 | error{YamlUnexpectedToken}; |
| 198 | 199 | |
| 199 | | fn parse_item(p: *Parser, start: ?c.yaml_event_t) Error!Item { |
| 200 | fn parse_item(p: *Parser, start: ?Token) Error!Item { |
| 200 | 201 | const tok = start orelse p.next(); |
| 201 | 202 | return switch (tok.?.type) { |
| 202 | 203 | .YAML_STREAM_START_EVENT => Item{ .stream = try parse_stream(p) }, |
| ... | ... | @@ -280,7 +281,7 @@ fn parse_sequence(p: *Parser) Error!Sequence { |
| 280 | 281 | } |
| 281 | 282 | } |
| 282 | 283 | |
| 283 | | fn get_event_string(event: c.yaml_event_t, lines: Array) []const u8 { |
| 284 | fn get_event_string(event: Token, lines: Array) []const u8 { |
| 284 | 285 | const sm = event.start_mark; |
| 285 | 286 | const em = event.end_mark; |
| 286 | 287 | return lines[sm.line][sm.column..em.column]; |