summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2024-03-11 22:08:07 +0100
committerkdx <kikoodx@paranoici.org>2024-03-11 22:08:07 +0100
commit3079ca9f9f4c5e887a4ceef14132a3c73701faf1 (patch)
tree512f9006648203655c6cd811885d5255adef4454
parent12531c1e21a2828ef1f46abd3d60f18fcee484a9 (diff)
downloado7z-3079ca9f9f4c5e887a4ceef14132a3c73701faf1.tar.gz
lex builtin
-rw-r--r--src/Lexer.zig9
-rw-r--r--src/Token.zig1
-rw-r--r--test.o713
3 files changed, 22 insertions, 1 deletions
diff --git a/src/Lexer.zig b/src/Lexer.zig
index 6890d13..67bb94b 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,
@@ -80,6 +80,13 @@ pub fn lex(self: *Self) !void {
continue;
}
+ if (self.s[i] == '@') {
+ const len = 1 + (match(self.s[i + 1 ..], alnum ++ "_") orelse 0);
+ try self.newToken(i, len, .builtin);
+ i += len;
+ continue;
+ }
+
if (match(self.s[i..], number)) |len| {
const postfix = match(self.s[i + len ..], alnum) orelse 0;
try self.newToken(i, len + postfix, .number);
diff --git a/src/Token.zig b/src/Token.zig
index bfb1cbd..8256664 100644
--- a/src/Token.zig
+++ b/src/Token.zig
@@ -11,6 +11,7 @@ pub const Tag = enum {
number,
keyword,
word,
+ builtin,
punct,
character,
string,
diff --git a/test.o7 b/test.o7
index 531ed70..c3f540c 100644
--- a/test.o7
+++ b/test.o7
@@ -1,4 +1,17 @@
+@import("std.o7");
+
mut x = 25; # commentaire
mut y = x * x + (8 - 2);
let zied = golem("large");
let doc = @as(Prof, zied);
+
+pub fn main(argv: [][]u8) i32 {
+ std::io::puts("Hello, World!");
+ let file = std::io::open("file.txt", "rb");
+ defer file\std::io::close();
+ let content = file\std::io::read();
+}
+
+fn span(s: [*]u8) []u8 {
+ return @slice(s, std::string::len(s));
+}