| ... | @@ -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.zig | 2 | //! zig build gen-parser-oracle |
| 3 | | 3 | |
| 4 | // This program implements a subset of the PEG grammar definition | 4 | // 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); |
| 22 | | 22 | |
| 23 | const grammar_path = args[1]; | 23 | const grammar_path = args[1]; |
| | 24 | const out_path = args[2]; |
| 24 | | 25 | |
| 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 | } |
| 54 | | 55 | |
| 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; |
| 58 | | 60 | |
| 59 | try tree.render(gpa, stdout, .{}); | 61 | try tree.render(gpa, out, .{}); |
| 60 | try stdout.flush(); | 62 | try out.flush(); |
| 61 | } | 63 | } |
| 62 | | 64 | |
| 63 | const Generator = struct { | 65 | const 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.zig | 83 | \\//! zig build gen-parser-oracle |
| 82 | \\ | 84 | \\ |
| 83 | \\const std = @import("std"); | 85 | \\const std = @import("std"); |
| 84 | \\ | 86 | \\ |