mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 16:49:31 +00:00
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.
40 lines
1 KiB
Lua
40 lines
1 KiB
Lua
local ast = require("ast")
|
|
local Nil, Choice, AttachBlock, ArgumentTuple = ast.Nil, ast.Choice, ast.AttachBlock, ast.ArgumentTuple
|
|
|
|
local event_manager = require("state.event_manager")
|
|
local translation_manager = require("state.translation_manager")
|
|
local tag_manager = require("state.tag_manager")
|
|
|
|
return {
|
|
-- text
|
|
{
|
|
"_!", "(txt::text)",
|
|
function(state, text)
|
|
event_manager:write(state, text)
|
|
return Nil:new()
|
|
end
|
|
},
|
|
|
|
-- choice
|
|
{
|
|
"_|>_", "(txt::text, fn)",
|
|
function(state, text, func)
|
|
if func:contains_resume_target(state) then
|
|
func:call(state, ArgumentTuple:new())
|
|
event_manager:write_and_discard_on_flush(state, Choice:new(text, func))
|
|
else
|
|
event_manager:write(state, Choice:new(text, func))
|
|
end
|
|
return Nil:new()
|
|
end
|
|
},
|
|
|
|
-- translation
|
|
{
|
|
"_->_", "(original::is(\"quote\"), translated::is(\"quote\"))",
|
|
function(state, original, translated)
|
|
translation_manager:set(state, tag_manager:get(state), original.expression, AttachBlock:preserve(state, translated.expression))
|
|
return Nil:new()
|
|
end
|
|
}
|
|
}
|