diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-08-03 17:07:05 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-08-03 17:07:05 +0200 |
| commit | 0bc6d195195d1e126b535554a4a4105468cd06d9 (patch) | |
| tree | 6a3288e56bd306db499e597fc53762d05a7c3b82 /src/z/parser/js/grammar/root.zig | |
| parent | 77642e5081b4ed2516dc08b3ef611c3c444ec6c5 (diff) | |
add tokenizer for whitespaces in js
Diffstat (limited to 'src/z/parser/js/grammar/root.zig')
| -rw-r--r-- | src/z/parser/js/grammar/root.zig | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/z/parser/js/grammar/root.zig b/src/z/parser/js/grammar/root.zig new file mode 100644 index 0000000..e1a1e96 --- /dev/null +++ b/src/z/parser/js/grammar/root.zig @@ -0,0 +1,36 @@ +const std = @import("std"); + +const parser = @import("../../root.zig"); +pub const Lexer = parser.Lexer(Grammar); +pub const Token = parser.Token(Grammar); + +pub const Whitespace = @import("whitespace.zig").Whitespace; +pub const Literal = @import("literal.zig").Literal; +pub const Punctuator = @import("punctuator.zig").Punctuator; +pub const Identifier = @import("identifier.zig").Identifier; + +pub const Grammar = union(enum) { + whitespace: Whitespace, + literal: Literal, + punctuator: Punctuator, + identifier: Identifier, + end_of_file: void, + + pub fn tokenize(lexer: *Lexer) Lexer.Error!void { + while (lexer.peakChar()) |_| { + Whitespace.tokenize(lexer) catch { + Literal.tokenize(lexer) catch { + Punctuator.tokenize(lexer) catch { + try Identifier.tokenize(lexer); + }; + }; + }; + } + + lexer.push(lexer.token(0, .end_of_file)); + } +}; + +test { + _ = std.testing.refAllDecls(@This()); +} |