summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2024-03-11 12:21:46 +0100
committerkdx <kikoodx@paranoici.org>2024-03-11 12:21:46 +0100
commit12531c1e21a2828ef1f46abd3d60f18fcee484a9 (patch)
treeb275e0b51b0f9e677a436f2494b6fae5627cb107
parenteacd6024a1d9a06cf34cf7c9b4ca00b2438dbb3a (diff)
downloado7z-12531c1e21a2828ef1f46abd3d60f18fcee484a9.tar.gz
plan for punct expansion
-rw-r--r--src/Lexer.zig13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/Lexer.zig b/src/Lexer.zig
index 08ae6a8..6890d13 100644
--- a/src/Lexer.zig
+++ b/src/Lexer.zig
@@ -15,7 +15,7 @@ const number = "0123456789";
const alpha = lower ++ upper;
const alnum = alpha ++ number;
const whitespaces = " \t\n\r";
-const punct = "@(){}=+-*/.;";
+const punct = "@(){}=+-*/%.;|&^";
pub const Error = error{
UnclosedCharLitteral,
UnclosedStringLitteral,
@@ -71,12 +71,11 @@ pub fn lex(self: *Self) !void {
if (self.s[i] == '#') {
i += until(self.s[i..], "\n") orelse break;
- self.nextLine(i);
continue;
}
- if (contains(self.s[i], punct)) {
- try self.newToken(i, 1, .punct);
+ if (punctAt(self.s[i..])) |len| {
+ try self.newToken(i, len, .punct);
i += 1;
continue;
}
@@ -153,3 +152,9 @@ fn match(s: []const u8, comptime c: []const u8) ?usize {
}
return if (s.len == 0) null else s.len;
}
+
+fn punctAt(s: []const u8) ?usize {
+ if (contains(s[0], punct))
+ return 1;
+ return null;
+}