diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-07-30 09:36:34 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-07-30 09:36:34 +0200 |
| commit | aca38f5c96709f56db75a476051eb644de644d3d (patch) | |
| tree | 1ce90ccffb80cff8d527be6efbd073031fccd3a1 /src/z/js/parser/parser.zig | |
| parent | 006674d7e08146a9bd980e2138ce9444d2e40e6f (diff) | |
restructure project
Diffstat (limited to 'src/z/js/parser/parser.zig')
| -rw-r--r-- | src/z/js/parser/parser.zig | 68 |
1 files changed, 0 insertions, 68 deletions
diff --git a/src/z/js/parser/parser.zig b/src/z/js/parser/parser.zig deleted file mode 100644 index 050f8c1..0000000 --- a/src/z/js/parser/parser.zig +++ /dev/null @@ -1,68 +0,0 @@ -const std = @import("std"); - -const root = @import("root.zig"); -const Result = root.Result; - -pub fn Parser(T: type) type { - const R = Result(T); - - return struct { - parse: *const fn ([]const u8) anyerror!R, - - pub fn parseAll(self: *const @This(), buffer: []const u8) !T { - const value, const next = try self.parse(buffer); - - if (next.len > 0) { - return error.NotExhaustive; - } - - return value; - } - - pub fn fromType(P: type) @This() { - return .{ .parse = P.parse }; - } - - pub fn variants(V: type) @This() { - if (@typeInfo(T) != .@"union") { - @compileError("variants is only allowed with an union as result type"); - } - - return .{ - .parse = struct { - fn parse(buffer: []const u8) !R { - inline for (std.meta.fields(T)) |field| { - if (@field(V, field.name).parse(buffer)) |result| { - const value, const next = result; - return .{ - @unionInit(T, field.name, value), - next, - }; - } else |_| {} - } - - return error.Variants; - } - }.parse, - }; - } - - pub fn any(P: type, comptime parsers: []const struct { Parser(P), T }) @This() { - return .{ - .parse = struct { - fn parse(buffer: []const u8) !R { - inline for (parsers) |pair| { - const parser, const value = pair; - - if (parser.parse(buffer)) |result| { - _, const next = result; - return .{ value, next }; - } else |_| {} - } - return error.Any; - } - }.parse, - }; - } - }; -} |