Skip to content

Input โ€‹

What you'll learn โ€‹

  • Serving source from chunk callbacks and from std.Io.Reader.

Complete example โ€‹

examples/custom_input.zig serves 12 + 34 as two chunks ("12 + ", "34") through an Input.read callback, then parses with parseWithInput.

Running the example โ€‹

sh
zig build run-custom_input

Expected output โ€‹

text
parsed from chunks: 12 + 34 error=false

examples/utf16_parse.zig feeds UTF-16LE bytes (with BOM) through an Input with .encoding = .utf16_le โ€” try zig build run-utf16_parse:

text
parsed utf16: 1 + 2 error=false

How it works โ€‹

The callback maps a byte index to the containing chunk and returns its remainder; null signals end of input. ReaderSource adapts the same shape over any std.Io.Reader with a caller buffer. parseWithInput buffers pulled chunks and runs the standard parse, so results equal parseString on the concatenated bytes. parseStream skips the pre-buffering and lexes incrementally instead โ€” same result, streaming memory profile.

API used โ€‹

Released under the MIT License.