1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-28 09:09:31 +00:00
anselme/parser/expression/primary/init.lua
Étienne Reuh Fildadut 56ed6c912b Replace checkpoint system
The previous system needed to store of the scope and full AST to build a Resumable object, which means that if persisted, updating the resumable script will have no effect.
The new system instead uses an anchor token and does not require any information besides the anchor name.
2023-12-27 17:06:35 +01:00

44 lines
842 B
Lua

--- try to parse a primary expression
local function r(name)
return require("parser.expression.primary."..name), nil
end
local primaries = {
r("number"),
r("string"),
r("text"),
r("parenthesis"),
r("function_definition"),
r("symbol"),
r("identifier"),
r("anchor"),
r("block_identifier"),
r("tuple"),
r("struct"),
-- prefixes
-- 1
r("prefix.semicolon"),
r("prefix.function"),
-- 2
r("prefix.return"),
-- 3.5
r("prefix.else"),
-- 11
r("prefix.negation"),
r("prefix.not"),
r("prefix.mutable"),
r("prefix.translatable"),
}
return {
-- returns exp, rem if expression found
-- returns nil if no expression found
search = function(self, source, str, limit_pattern)
for _, primary in ipairs(primaries) do
local exp, rem = primary:search(source, str, limit_pattern)
if exp then return exp, rem end
end
end
}