mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-28 17:19:31 +00:00
Woke up and felt like changing a couple things. It's actually been worked on for a while, little at a time... The goal was to make the language and implementation much simpler. Well I don't know if it really ended up being simpler but it sure is more robust. Main changes: * proper first class functions and closures supports! proper scoping rules! no more namespace shenanigans! * everything is an expression, no more statements! make the implementation both simpler and more complex, but it's much more consistent now! the syntax has massively changed as a result though. * much more organized and easy to modify codebase: one file for each AST node, no more random fields or behavior set by some random node exceptionally, everything should now follow the same API defined in ast.abstract.Node Every foundational feature should be implemented right now. The vast majority of things that were possible in v2 are possible now; some things aren't, but that's usually because v2 is a bit more sane. The main missing things before a proper release are tests and documentation. There's a few other things that might be implemented later, see the ideas.md file.
32 lines
1.2 KiB
Lua
32 lines
1.2 KiB
Lua
-- same as infix, but skip if no valid expression after the operator instead of erroring
|
|
-- useful for operators that are both valid as infix and as suffix
|
|
|
|
local infix = require("parser.expression.secondary.infix.infix")
|
|
local escape = require("common").escape
|
|
local expression_to_ast = require("parser.expression.to_ast")
|
|
|
|
return infix {
|
|
-- returns exp, rem if expression found
|
|
-- returns nil if no expression found
|
|
search = function(self, source, str, limit_pattern, current_priority, operating_on_primary)
|
|
if not self:match(str, current_priority, operating_on_primary) then
|
|
return nil
|
|
end
|
|
return self:maybe_parse(source, str, limit_pattern, current_priority, operating_on_primary)
|
|
end,
|
|
|
|
parse = function() error("no guaranteed parse for this operator") end,
|
|
|
|
-- return AST, rem
|
|
-- return nil
|
|
maybe_parse = function(self, source, str, limit_pattern, current_priority, primary)
|
|
local start_source = source:clone()
|
|
local escaped = escape(self.operator)
|
|
|
|
local sright = source:consume(str:match("^("..escaped..")(.*)$"))
|
|
local s, right, rem = pcall(expression_to_ast, source, sright, limit_pattern, self.priority)
|
|
if not s then return nil end
|
|
|
|
return self:build_ast(primary, right):set_source(start_source), rem
|
|
end,
|
|
}
|