diff options
| author | Taylan Kammer <taylan.kammer@gmail.com> | 2026-01-07 02:22:27 +0100 |
|---|---|---|
| committer | Taylan Kammer <taylan.kammer@gmail.com> | 2026-01-07 02:22:27 +0100 |
| commit | c575aafc23cf20cee76653a179384357cdb918f2 (patch) | |
| tree | 2ceb7f6797e374bdc7f99112cb34c5ff1409bc89 /src/zisp/io/parser.zig | |
| parent | 910b1697e16bfb77a46dd39914116c5102519c41 (diff) | |
Rename some files and functions.
Diffstat (limited to 'src/zisp/io/parser.zig')
| -rw-r--r-- | src/zisp/io/parser.zig | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/src/zisp/io/parser.zig b/src/zisp/io/parser.zig deleted file mode 100644 index 49d260c..0000000 --- a/src/zisp/io/parser.zig +++ /dev/null @@ -1,76 +0,0 @@ -const builtin = @import("builtin"); -const std = @import("std"); - -const value = @import("../value.zig"); - -const Parser = @import("Parser.zig"); - -const Value = value.Value; - -const is_test = builtin.is_test; -const is_debug = builtin.mode == .Debug; - -const ctx_size = @sizeOf(Parser.Context); - -pub fn Sfa(init_stack: usize, init_chars: usize) type { - return struct { - const Self = @This(); - - pub const init_stack_capacity: usize = init_stack; - pub const init_chars_capacity: usize = init_chars; - - pub const init_stack_mem: usize = init_stack * ctx_size; - pub const init_chars_mem: usize = init_chars; - - stack: std.heap.StackFallbackAllocator(init_stack_mem), - chars: std.heap.StackFallbackAllocator(init_chars_mem), - - pub fn init(fallback: std.mem.Allocator) Self { - return .{ - .stack = std.heap.stackFallback(init_stack_mem, fallback), - .chars = std.heap.stackFallback(init_chars_mem, fallback), - }; - } - - pub fn allocator(s: *Self) Parser.Alloc { - return .{ .stack = s.stack.get(), .chars = s.chars.get() }; - } - }; -} - -pub const DefaultSfa = Sfa(32, 2048); - -pub fn initSfa(alloc: anytype) !Parser { - const SfaType = @typeInfo(@TypeOf(alloc)).pointer.child; - return Parser.init( - alloc.allocator(), - std.Io.Threaded.global_single_threaded.io(), - SfaType.init_stack_capacity, - SfaType.init_chars_capacity, - ); -} - -pub fn parse(input: *std.Io.Reader) Value { - return _parse(input, true); -} - -pub fn _parse( - input: *std.Io.Reader, - comptime panic: bool, -) if (panic) Value else error{ ParseError, OutOfMemory }!Value { - const alloc = std.heap.smp_allocator; - var sfa = DefaultSfa.init(alloc); - var p = initSfa(&sfa) catch |e| if (panic) @panic("OOM") else return e; - defer p.deinit(); - return p.run(input) catch |e| if (panic) { - const format = "Parse error: {s}, unread_char: {s}\n"; - const unread: [4]u8 = - if (p.unread_char) |c| - "0x".* ++ std.fmt.hex(c) - else - "none".*; - std.debug.panic(format, .{ p.err_msg, unread }); - } else { - return e; - }; -} |
