Skip to content

Commit

Permalink
update to zig master
Browse files Browse the repository at this point in the history
  • Loading branch information
nektro committed Jun 11, 2023
1 parent b0111b4 commit cf09039
Showing 1 changed file with 7 additions and 31 deletions.
38 changes: 7 additions & 31 deletions src/lib.zig
Original file line number Diff line number Diff line change
Expand Up @@ -120,32 +120,12 @@ pub const Member = struct {
};

const Parser = struct {
alloc: std.mem.Allocator,
p: std.json.StreamingParser,
input: []const u8,
index: usize,
tok2: ?std.json.Token,
p: std.json.Scanner,

pub fn next(self: *Parser) !?std.json.Token {
if (self.tok2) |t2| {
defer self.tok2 = null;
return t2;
}
while (self.index < self.input.len) {
var tok: ?std.json.Token = null;
var tok2: ?std.json.Token = null;
const b = self.input[self.index];
try self.p.feed(b, &tok, &tok2);
self.index += 1;
if (tok) |_| {} else {
continue;
}
if (tok2) |t2| {
self.tok2 = t2;
}
return tok;
}
return null;
const tok = try self.p.next();
if (tok == .end_of_document) return null;
return tok;
}

pub const Error =
Expand All @@ -158,14 +138,10 @@ const Parser = struct {
};

pub fn parse(alloc: std.mem.Allocator, input: []const u8) Parser.Error!Value {
const p = &Parser{
.alloc = alloc,
.p = std.json.StreamingParser.init(),
.input = input,
.index = 0,
.tok2 = null,
var p = Parser{
.p = std.json.Scanner.initCompleteInput(alloc, input),
};
return try parse_value(p, null);
return try parse_value(&p, null);
}

fn parse_value(p: *Parser, start: ?std.json.Token) Parser.Error!Value {
Expand Down

0 comments on commit cf09039

Please sign in to comment.