aboutsummaryrefslogtreecommitdiff
path: root/src/z/parser/js/ast/lit.zig
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2026-07-30 10:24:19 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2026-07-30 10:24:19 +0200
commit00920ddd36a8ebb851b52c3c048c0017753176bd (patch)
tree8498e65ca6c055333aa95b6c3a0d28c8370cb0ef /src/z/parser/js/ast/lit.zig
parente8259360516078517a2fbeddbf781f701f35d0d0 (diff)
complete js parser + minifierjs-parser
Diffstat (limited to 'src/z/parser/js/ast/lit.zig')
-rw-r--r--src/z/parser/js/ast/lit.zig48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/z/parser/js/ast/lit.zig b/src/z/parser/js/ast/lit.zig
new file mode 100644
index 0000000..3a5149f
--- /dev/null
+++ b/src/z/parser/js/ast/lit.zig
@@ -0,0 +1,48 @@
+const std = @import("std");
+const Loc = @import("loc.zig").Loc;
+const Formatter = @import("../formatter.zig").Formatter;
+
+pub const LitType = union(enum) {
+ null: void,
+ bool: bool,
+ number: f64,
+ string: []const u8,
+ regex: Regex,
+ bigint: []const u8,
+};
+
+pub const Lit = struct {
+ loc: Loc,
+ data: LitType,
+
+ pub fn fmt(self: @This(), f: *Formatter) void {
+ switch (self.data) {
+ .null => f.write("null"),
+ .bool => |b| f.write(if (b) "true" else "false"),
+ .number => |n| {
+ var buf: [64]u8 = undefined;
+ f.write(std.fmt.bufPrint(&buf, "{d}", .{n}) catch "0");
+ },
+ .string => |s| {
+ f.writeChar('"');
+ f.write(s);
+ f.writeChar('"');
+ },
+ .regex => |r| {
+ f.writeChar('/');
+ f.write(r.pattern);
+ f.writeChar('/');
+ f.write(r.flags);
+ },
+ .bigint => |s| {
+ f.write(s);
+ f.writeChar('n');
+ },
+ }
+ }
+};
+
+pub const Regex = struct {
+ pattern: []const u8,
+ flags: []const u8,
+};