diff options
author | kdx <kikoodx@paranoici.org> | 2024-03-10 02:22:40 +0100 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2024-03-10 02:22:40 +0100 |
commit | f4e4d82452044d8678b9fe5707c668387409e981 (patch) | |
tree | 287788efd99a6c2a3943632a4124dd8e53733fb1 | |
parent | e4830e44740f0fb73b0f155316275cdbb7dbf203 (diff) | |
download | o7z-f4e4d82452044d8678b9fe5707c668387409e981.tar.gz |
lex punct
-rw-r--r-- | src/Lexer.zig | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/Lexer.zig b/src/Lexer.zig index 2fc5dc9..fc615f3 100644 --- a/src/Lexer.zig +++ b/src/Lexer.zig @@ -13,6 +13,7 @@ const number = "0123456789"; const alpha = lower ++ upper; const alnum = alpha ++ number; const whitespaces = " \t\n\r"; +const punct = "(){}=+-*/"; pub fn init( allocator: std.mem.Allocator, @@ -58,6 +59,12 @@ pub fn lex(self: *Self) !void { continue; } + if (contains(self.s[i], punct)) { + try self.tokens.append(Token.init(.punct, self.s[i .. i + 1])); + i += 1; + continue; + } + if (match(self.s[i..], number)) |len| { const postfix = match(self.s[i + len ..], alnum) orelse 0; try self.tokens.append(Token.init( @@ -87,6 +94,13 @@ fn until(s: []const u8, comptime c: []const u8) ?usize { return null; } +fn contains(s: u8, comptime c: []const u8) bool { + inline for (c) |e| + if (s == e) + return true; + return false; +} + fn match(s: []const u8, comptime c: []const u8) ?usize { for (s, 0..) |e, i| { var valid = false; |