authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2026-07-08 11:01:39+02:00
committergravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2026-07-08 15:49:43+02:00
log06b1896a619d13a8b3471dc119d2076f04f85b93
tree6c5dda23d4f7e32a855c9097ce48b3d142fc92fc
parent3e45baa60adbb041bf75af4cde380abb3b05abfb
signaturelock-open Commit is signed but in an unrecognized format.

build: add gen-parser-oracle step


3 files changed, 25 insertions(+), 8 deletions(-)

build.zig+15
...@@ -719,6 +719,21 @@ pub fn build(b: *std.Build) !void {...@@ -719,6 +719,21 @@ pub fn build(b: *std.Build) !void {
719 check_mingw_run.addDirectoryArg(b.path("lib/libc/mingw"));719 check_mingw_run.addDirectoryArg(b.path("lib/libc/mingw"));
720 check_mingw_step.dependOn(&check_mingw_run.step);720 check_mingw_step.dependOn(&check_mingw_run.step);
721721
722 {
723 const gpo_step = b.step("gen-parser-oracle", "Regenerate lib/std/zig/parser_generated_oracle.zig from doc/langref/grammar.peg");
724 const gpo_exe = b.addExecutable(.{
725 .name = "gen_parser_oracle",
726 .root_module = b.createModule(.{
727 .root_source_file = b.path("tools/gen_parser_oracle.zig"),
728 .target = b.graph.host,
729 }),
730 });
731 const gpo_run = b.addRunArtifact(gpo_exe);
732 gpo_run.addFileArg(b.path("doc/langref/grammar.peg"));
733 gpo_run.addFileArg(b.path("lib/std/zig/parser_generated_oracle.zig"));
734 gpo_step.dependOn(&gpo_run.step);
735 }
736
722 const test_incremental_step = b.step("test-incremental", "Run the incremental compilation test cases");737 const test_incremental_step = b.step("test-incremental", "Run the incremental compilation test cases");
723 try tests.addIncrementalTests(b, test_incremental_step, test_filters);738 try tests.addIncrementalTests(b, test_incremental_step, test_filters);
724 if (!skip_test_incremental) test_step.dependOn(test_incremental_step);739 if (!skip_test_incremental) test_step.dependOn(test_incremental_step);
lib/std/zig/parser_generated_oracle.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1//! This file is generated, do not edit manually! To generate, run:1//! This file is generated, do not edit manually! To generate, run:
2//! zig run ./tools/gen_parser_oracle.zig -- ./doc/langref/grammar.peg > ./lib/std/zig/parser_generated_oracle.zig2//! zig build gen-parser-oracle
33
4const std = @import("std");4const std = @import("std");
55
tools/gen_parser_oracle.zig+9-7
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1//! Example usage:1//! Example usage:
2//! zig run ./tools/gen_parser_oracle.zig -- ./doc/langref/grammar.peg > ./lib/std/zig/parser_generated_oracle.zig2//! zig build gen-parser-oracle
33
4// This program implements a subset of the PEG grammar definition4// This program implements a subset of the PEG grammar definition
5// in the peg(1) man page.5// in the peg(1) man page.
...@@ -21,6 +21,7 @@ pub fn main(init: std.process.Init) !void {...@@ -21,6 +21,7 @@ pub fn main(init: std.process.Init) !void {
21 const args = try init.minimal.args.toSlice(arena);21 const args = try init.minimal.args.toSlice(arena);
2222
23 const grammar_path = args[1];23 const grammar_path = args[1];
24 const out_path = args[2];
2425
25 const grammar = try Io.Dir.cwd().readFileAlloc(io, grammar_path, gpa, .unlimited);26 const grammar = try Io.Dir.cwd().readFileAlloc(io, grammar_path, gpa, .unlimited);
26 defer gpa.free(grammar);27 defer gpa.free(grammar);
...@@ -52,12 +53,13 @@ pub fn main(init: std.process.Init) !void {...@@ -52,12 +53,13 @@ pub fn main(init: std.process.Init) !void {
52 return error.ParseError;53 return error.ParseError;
53 }54 }
5455
55 var stdout_buffer: [4096]u8 = undefined;56 var out_file = try Io.Dir.cwd().createFile(io, out_path, .{});
56 var stdout_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer);57 var out_buffer: [4096]u8 = undefined;
57 const stdout = &stdout_writer.interface;58 var out_writer = out_file.writer(io, &out_buffer);
59 const out = &out_writer.interface;
5860
59 try tree.render(gpa, stdout, .{});61 try tree.render(gpa, out, .{});
60 try stdout.flush();62 try out.flush();
61}63}
6264
63const Generator = struct {65const Generator = struct {
...@@ -78,7 +80,7 @@ const Generator = struct {...@@ -78,7 +80,7 @@ const Generator = struct {
78 fn genRoot(g: *Generator, node: Node.Index) Error!void {80 fn genRoot(g: *Generator, node: Node.Index) Error!void {
79 try g.w.writeAll(81 try g.w.writeAll(
80 \\//! This file is generated, do not edit manually! To generate, run:82 \\//! This file is generated, do not edit manually! To generate, run:
81 \\//! zig run ./tools/gen_parser_oracle.zig -- ./doc/langref/grammar.peg > ./lib/std/zig/parser_generated_oracle.zig83 \\//! zig build gen-parser-oracle
82 \\84 \\
83 \\const std = @import("std");85 \\const std = @import("std");
84 \\86 \\