diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-10-05 15:33:46 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-10-05 15:33:46 +0200 |
| commit | 02582cc490fc0d753dd153211cc172eb28fbee5d (patch) | |
| tree | 4add149d5e1ecf28cf20ecb497626fef85cdbd75 /src/z/parser/js/grammar/root.zig | |
| parent | 2f3199622d9e7a97da4b5c31a2d81b170b7cdaa6 (diff) | |
first sketch of wasm environment
Diffstat (limited to 'src/z/parser/js/grammar/root.zig')
| -rw-r--r-- | src/z/parser/js/grammar/root.zig | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/src/z/parser/js/grammar/root.zig b/src/z/parser/js/grammar/root.zig deleted file mode 100644 index f732b7f..0000000 --- a/src/z/parser/js/grammar/root.zig +++ /dev/null @@ -1,66 +0,0 @@ -//! This is a Javascript parser and tokenizer. -//! It is and probably will never be complete, -//! since js is a very strange language and I want -//! to move forward and code on more interesting things -//! I started something called mujs (micro-js). It's a -//! subset of the javascript language. It does not support -//! the regex literal and currently also not template strings. -//! It is chosen like that to make parsing easier and also less -//! context-dependent. - -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 Keyword = @import("keyword.zig").Keyword; -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, - keyword: Keyword, - literal: Literal, - punctuator: Punctuator, - identifier: Identifier, - end_of_file: void, - - pub const Context = struct { - template_nesting: usize = 0, - regex_possible: bool = true, - }; - - pub inline fn tokenize(comptime lexer: *Lexer) Lexer.Error!void { - @setEvalBranchQuota(lexer.buffer.len * 1000); - comptime { - while (lexer.peekChar()) |_| { - Whitespace.tokenize(lexer) catch { - Keyword.tokenize(lexer) catch { - Literal.tokenize(lexer) catch { - Punctuator.tokenize(lexer) catch { - try Identifier.tokenize(lexer); - }; - }; - }; - }; - } - - lexer.commit(lexer.start(.end_of_file)); - } - } -}; - -test { - _ = std.testing.refAllDecls(@This()); -} - -test "z.js" { - comptime var lexer: Lexer = .init(@embedFile("../../../z.js")); - Grammar.tokenize(&lexer) catch |err| { - std.debug.print("error: {} at {s}", .{ err, lexer.buffer }); - }; -} |