3 ms·
I can't speak as much about the last two examples, but writing a giant parser file is pretty common in Zig from what I've seen. Here's Zig's own parser, for exa
by smj-edison 11mo ago
I can't speak as much about the last two examples, but writing a giant parser file is pretty common in Zig from what I've seen. Here's Zig's own parser, for example[1]. I'm also not sure what you mean by memory unsafe, since all slices have bounds checks. It also looks like this uses an arena allocator, so lifetime tracking is pretty simple (dump everything onto the allocator, and copy over the result at the end). Granted, I could be misunderstanding the code, but that's the read I get of it.
[1] https://codeberg.org/ziglang/zig/src/commit/be9649f4ea5a32fdb5b5ce6488a6ae7d30f3acb0/lib/std/zig/Parse.zig https://codeberg.org/ziglang/zig/src/commit/be9649f4ea5a32fd...
- AndyKelley 11mo agoIt used to be arena-allocated but now it's using a different technique which I outlined in this talk: https://vimeo.com/649009599 https://vimeo.com/649009599
- dgroshev 11mo agoAs it happens, the commit I linked fixes a segfault, which shouldn't normally happen in memory-safe code.