diff --git a/build.zig b/build.zig index 1441ddc..4030430 100644 --- a/build.zig +++ b/build.zig @@ -5,10 +5,13 @@ pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - // Create options module for tracing + // Create options module for conditional compilation const executionTracing = b.option(bool, "tracing", "enable execution tracing") orelse false; + const json_serialization = b.option(bool, "json", "enable JSON serialization of the compiler outputs") orelse false; + const options = b.addOptions(); options.addOption(bool, "tracing", executionTracing); + options.addOption(bool, "json", json_serialization); // Create the options module that will be shared const options_module = options.createModule(); diff --git a/src/main.zig b/src/main.zig index ae2e565..a8a7e52 100644 --- a/src/main.zig +++ b/src/main.zig @@ -5,7 +5,9 @@ const errors = @import("errors"); const cli = @import("cli.zig"); -const tracing = @import("config").tracing; +const config = @import("config"); +const tracing = config.tracing; +const json = config.json; const thp_version: []const u8 = "0.0.1"; @@ -18,12 +20,16 @@ fn repl() !void { var args = std.process.args(); defer args.deinit(); + // If compiling for JSON serialization, enable the binary `lex` command + // ignore executable _ = args.next(); if (args.next()) |arg| { - if (std.mem.eql(u8, "lex", arg)) { - try cli.tokenize_to_json(); - return; + if (json) { + if (std.mem.eql(u8, "lex", arg)) { + try cli.tokenize_to_json(); + return; + } } }