aboutsummaryrefslogtreecommitdiff
path: root/src/z/parser/js/grammar/punctuator.zig
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2026-10-05 15:33:46 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2026-10-05 15:33:46 +0200
commit02582cc490fc0d753dd153211cc172eb28fbee5d (patch)
tree4add149d5e1ecf28cf20ecb497626fef85cdbd75 /src/z/parser/js/grammar/punctuator.zig
parent2f3199622d9e7a97da4b5c31a2d81b170b7cdaa6 (diff)
first sketch of wasm environment
Diffstat (limited to 'src/z/parser/js/grammar/punctuator.zig')
-rw-r--r--src/z/parser/js/grammar/punctuator.zig122
1 files changed, 0 insertions, 122 deletions
diff --git a/src/z/parser/js/grammar/punctuator.zig b/src/z/parser/js/grammar/punctuator.zig
deleted file mode 100644
index b085ce1..0000000
--- a/src/z/parser/js/grammar/punctuator.zig
+++ /dev/null
@@ -1,122 +0,0 @@
-const std = @import("std");
-
-const root = @import("root.zig");
-const Lexer = root.Lexer;
-const Token = root.Token;
-
-pub const Punctuator = enum {
- @"+",
- @"-",
- @"*",
- @"/",
- @"%",
- @"**",
- @"++",
- @"--",
- @"=",
- @"+=",
- @"-=",
- @"*=",
- @"/=",
- @"%=",
- @"**=",
- @"&=",
- @"|=",
- @"^=",
- @"<<=",
- @">>=",
- @">>>=",
- @"&&=",
- @"||=",
- @"??=",
- @"==",
- @"===",
- @"!=",
- @"!==",
- @"<",
- @"<=",
- @">",
- @">=",
- @"&&",
- @"||",
- @"??",
- @"&",
- @"|",
- @"^",
- @"~",
- @"<<",
- @">>",
- @">>>",
- @"!",
- @"?",
- @":",
- @";",
- @",",
- @".",
- @"...",
- @"=>",
- @"(",
- @")",
- @"[",
- @"]",
- @"{",
- @"}",
- @"?.",
- @"#",
- @"@",
-
- const Self = @This();
-
- const punctuatormap: std.StaticStringMap(Self) = .initComptime(kws: {
- var punctuators: []const struct { []const u8, Self } = &.{};
-
- for (@typeInfo(Self).@"enum".fields) |field| {
- const name: []const u8 = field.name;
- const value: Self = @field(Self, field.name);
-
- punctuators = punctuators ++ .{.{ name, value }};
- }
-
- break :kws punctuators;
- });
-
- pub inline fn tokenize(comptime lexer: *Lexer) Lexer.Error!void {
- comptime {
- @setEvalBranchQuota(10_000);
- defer lexer.revert();
-
- lexer.context.regex_possible = true;
-
- if (punctuatormap.getLongestPrefix(lexer.buffer)) |pair| {
-
- if (std.mem.eql(u8, pair.key, "}") and lexer.context.template_nesting > 0) {
- return Lexer.Error.UnexpectedToken;
- }
-
- const token = lexer.start(.{ .punctuator = pair.value });
- try lexer.skipTo(pair.key.len);
- lexer.commit(token);
- } else {
- return Lexer.Error.UnexpectedToken;
- }
- }
- }
-};
-
-test "simple" {
- inline for (comptime Punctuator.punctuatormap.keys()) |key| {
- comptime var lexer: Lexer = .init(key);
- try Punctuator.tokenize(&lexer);
- try std.testing.expectEqual(1, lexer.tokens.len);
- try std.testing.expectEqual(key.len, lexer.tokens[0].slice.len);
- }
-}
-
-test "ending" {
- inline for (comptime Punctuator.punctuatormap.keys()) |key| {
- comptime var lexer: Lexer = .init(key ++ "a");
- try Punctuator.tokenize(&lexer);
- try std.testing.expectEqual(1, lexer.tokens.len);
- try std.testing.expectEqual(key.len, lexer.tokens[0].slice.len);
- }
-}