mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-28 00:59: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.
44 lines
1.2 KiB
Lua
44 lines
1.2 KiB
Lua
-- intended to be wrapped in a Function, so that when resuming from the function, will keep resuming to where the function was called from
|
|
-- used in Choices to resume back from where the event was flushed
|
|
-- note: when resuming, the return value will be discarded, instead returning what the parent function will return
|
|
|
|
local ast = require("ast")
|
|
local ArgumentTuple
|
|
|
|
local resumable_manager
|
|
|
|
local ResumeParentFunction = ast.abstract.Node {
|
|
type = "resume parent function",
|
|
|
|
expression = nil,
|
|
|
|
init = function(self, expression)
|
|
self.expression = expression
|
|
self.format_priority = expression.format_priority
|
|
end,
|
|
|
|
_format = function(self, ...)
|
|
return self.expression:format(...)
|
|
end,
|
|
|
|
traverse = function(self, fn, ...)
|
|
fn(self.expression, ...)
|
|
end,
|
|
|
|
_eval = function(self, state)
|
|
if resumable_manager:resuming(state, self) then
|
|
self.expression:eval(state)
|
|
return resumable_manager:get_data(state, self):call(state, ArgumentTuple:new())
|
|
else
|
|
resumable_manager:set_data(state, self, resumable_manager:capture(state, 1))
|
|
return self.expression:eval(state)
|
|
end
|
|
end
|
|
}
|
|
|
|
package.loaded[...] = ResumeParentFunction
|
|
ArgumentTuple = ast.ArgumentTuple
|
|
|
|
resumable_manager = require("state.resumable_manager")
|
|
|
|
return ResumeParentFunction
|