commit 5446a2885f85e6748d292a3a2608324bb0ef95f7
parent c1905a40537d285d31a691f12aa39126fc769fa6
Author: citbl <citbl@citbl.org>
Date: Sun, 24 May 2026 15:53:17 +1000
wip
Diffstat:
2 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/mtcl/ast.lua b/mtcl/ast.lua
@@ -1,12 +1,9 @@
-local AST = { file = "", line = 0, col = 0 }
+local AST = {}
function AST:program(body)
return {
kind = "program",
body = body,
- file = self.file,
- line = self.line,
- col = self.col,
}
end
@@ -14,9 +11,6 @@ function AST:use(lib)
return {
kind = "use",
lib = lib,
- file = self.file,
- line = self.line,
- col = self.col,
}
end
@@ -26,8 +20,5 @@ function AST:func(name, params, ret, body)
name = name,
params = params,
body = body,
- file = self.file,
- line = self.line,
- col = self.col,
}
end
diff --git a/mtcl/parser.lua b/mtcl/parser.lua
@@ -10,12 +10,20 @@ function parser:advance()
self.pos = self.pos + 1
end
+function parser:match_ident()
+ local current = self.tokens[self.pos]
+ if current.kind ~= "keyword" then
+ unhandled(current, "EXPECTED an IDENT")
+ end
+ return current
+end
+
function parser:swallow(word)
local current = self.tokens[self.pos]
if current == word then
parser:advance()
else
- unhandled(current, "EXPECT: " .. word)
+ unhandled(current, "EXPECTED: " .. word)
end
end
@@ -26,6 +34,9 @@ end
function parser:parse_use()
print("parse use" .. self.pos)
self:swallow("use")
+ local ident = parser:match_ident()
+ return AST.use(lib)
+
end
function unhandled(token, extramsg)
@@ -45,11 +56,12 @@ end
function parser:parse_program()
while self:peek() ~= 0 do
local token = self:peek()
+ local kind = token.kind
local word = token.lexeme
print("peek:", word)
- if word == "use" then
+ if kind == "keyword" and word == "use" then
self:parse_use()
- elseif word == "fx" then
+ elseif kind == "keyword" and word == "fx" then
self:parse_function()
else
unhandled(token)