Lexer โ
Simple explanation โ
The lexer turns raw bytes into labeled tokens (identifier, number, +, โฆ) while tracking exactly where each token sits โ byte offsets plus row/column points.
Technical explanation โ
lexer/lexer.zigis a position-tracking cursor over the source:advance()moves one byte and updates the point;markEnd()freezes the token end independently of lookahead.- Tokenization tries every non-extra
TokenMatcherat each offset and takes the longest match; extra symbols (whitespace) are skipped in a loop first. - End of input surfaces as the grammar's
endtoken; bytes no matcher accepts surface as an invalid marker that error recovery skips one byte at a time. lexer/input.zig(ChunkReader) abstracts slice vs callback sources;lexer/unicode.zigdecodes the current character without decoding the whole file;lexer/external.zigdispatches to a Zig external scanner when the language provides one.
The lexer never allocates for ordinary lookahead.
