Commit Graph
13 Commits
Author SHA1 Message Date
Andrew Kelley 6ddb6f5759 regenerate parser oracle 2026-08-20 17:35:12 -07:00
Justus Klausecker 69a26976ed zig fmt
Converts usages of `@intFromEnum` and `@enumFromInt` to instead use the
new `@backingInt` and `@fromBackingInt` builtins.
2026-07-17 23:30:26 +02:00
Ryan Liptak e07edda6e7 gen_parser_oracle: Handle CRLF line endings, fail on invalid grammar 2026-07-10 12:18:39 +02:00
Andrew Kelley 65073f3dc5 std.zig.Ast: move mode into ParseOptions 2026-07-08 18:26:18 -07:00
Isaac Freund b2c3c33eef build: check if parser oracle must be regenerated 2026-07-08 15:49:43 +02:00
Isaac Freund 06b1896a61 build: add gen-parser-oracle step 2026-07-08 15:49:43 +02:00
Isaac Freund 3e45baa60a std.zig.Ast.parse: introduce options struct
This is a much cleaner way to expose the new option to disable recovery
added in 62720ad9f9. It also makes it possible to add further
options in the future without further breaking changes.
2026-07-08 15:49:18 +02:00
Isaac Freund 5bafdbf9d8 tools/gen_parser_oracle: gen recursion guards for all defs
More rules are being made recursive for efficiency reasons, see the
previous commit.
2026-07-08 11:49:02 +02:00
Isaac Freund e6749167fe tools: enforce Block max depth in parser oracle 2026-07-08 11:49:01 +02:00
Isaac Freund 775dac9149 tools: add max depth to parser oracle
This is useful to avoid unbounded recursion/iteration while fuzzing.
It's not interesting to learn that the parser hits a stack overflow when
fed a million open parens for example.
2026-07-08 11:49:00 +02:00
Isaac Freund 068d483780 grammar: fix doc comment at start of file
My attempt to handle this case in 6f151109b5fdf88eb8b has proven
insufficient, the test case added by this commit was failing.

Solve this with a "start of file" non-terminal in the PEG grammar,
which unfortunately isn't portable but much better reflects the actual
implementation and is much simpler.
2026-07-08 11:48:59 +02:00
Isaac Freund ac6930544f grammar: fix operator whitespace after multiline string literal
Currently the grammar fails to enforce matching whitespace or lack of
whitespace around operators that are immediately preceded by a multiline
string literal and terminating newline.
2026-07-08 11:48:58 +02:00
Isaac Freund 20a2485061 tools: add oracle generator for parser fuzzing
This script parses a PEG grammar definition and generates a simple
recursive descent parser that recognizes that grammar.

The intent is to use this tool to generate an oracle against which
std.zig.Ast.parse() can be fuzz tested.

Unfortunately, generating a "smith" that can produce all possible valid
source code according to the PEG grammar definition does not seem
feasible due to PEG semantics. In particular, modeling the ordered
choice operator ('/') with a smith is problematic and seems to have
worst-case exponential runtime. Consider that `A / B` is equivalent to
`A / !A B`, it is not sufficient for a smith to choose an option from
the ordered choice at random and generate an input matched by that
sub-expression.

The current handwritten AstSmith.zig implementation does not match the
exact semantics of the PEG grammar. It has some hacks (see the `not_*`
variables) to work around specific instances of the general problem
with ordered choice described above but that is not an acceptable
long term solution in my opinion.

Generating the oracle for the fuzz test automatically from the PEG
makes the oracle correct by construction and gives us a single source of
truth: the PEG definition in the language spec.
2026-07-08 11:48:57 +02:00