commit 6f86995144a177699b918a252ecf573acf625ba0
parent 5446a2885f85e6748d292a3a2608324bb0ef95f7
Author: citbl <citbl@citbl.org>
Date: Sun, 24 May 2026 17:00:46 +1000
ast wip
Diffstat:
2 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/mtcl/ast.lua b/mtcl/ast.lua
@@ -22,3 +22,5 @@ function AST:func(name, params, ret, body)
body = body,
}
end
+
+return AST
diff --git a/mtcl/parser.lua b/mtcl/parser.lua
@@ -1,4 +1,4 @@
-local parser = { pos = 1 }
+local parser = { pos = 1, nodes = {} }
local ast = require("ast")
local node = {}
@@ -12,7 +12,7 @@ end
function parser:match_ident()
local current = self.tokens[self.pos]
- if current.kind ~= "keyword" then
+ if current.kind ~= "ident" then
unhandled(current, "EXPECTED an IDENT")
end
return current
@@ -28,15 +28,20 @@ function parser:swallow(word)
end
function parser:parse_function()
- print("parse function" .. self.pos)
+ print("parse function decl")
+end
+
+function parser:add(ast)
+ table.insert(self.nodes, ast)
end
function parser:parse_use()
- print("parse use" .. self.pos)
- self:swallow("use")
+ print("parse use")
+ self:advance()
local ident = parser:match_ident()
- return AST.use(lib)
-
+ local node = ast.use(lib)
+ table.insert(self.nodes, node)
+ parser:advance()
end
function unhandled(token, extramsg)