mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-28 09:09:31 +00:00
Separate function and class injections
This commit is contained in:
parent
c43266260d
commit
e017a391ec
4 changed files with 31 additions and 13 deletions
|
|
@ -494,6 +494,8 @@ local vm_mt = {
|
||||||
-- * `"function return"`: injected at the end of each return's children that is contained in a non-scoped function
|
-- * `"function return"`: injected at the end of each return's children that is contained in a non-scoped function
|
||||||
-- * `"checkpoint start"`: injected at the start of every checkpoint
|
-- * `"checkpoint start"`: injected at the start of every checkpoint
|
||||||
-- * `"checkpoint end"`: injected at the end of every checkpoint
|
-- * `"checkpoint end"`: injected at the end of every checkpoint
|
||||||
|
-- * `"class start"`: injected at the start of every class
|
||||||
|
-- * `"class end"`: injected at the end of every class
|
||||||
-- * `"scoped function start"`: injected at the start of every scoped function
|
-- * `"scoped function start"`: injected at the start of every scoped function
|
||||||
-- * `"scoped function end"`: injected at the end of every scoped function
|
-- * `"scoped function end"`: injected at the end of every scoped function
|
||||||
-- * `"scoped function return"`: injected at the end of each return's children that is contained in a scoped function
|
-- * `"scoped function return"`: injected at the end of each return's children that is contained in a scoped function
|
||||||
|
|
|
||||||
|
|
@ -106,3 +106,5 @@ Disadvantages:
|
||||||
* could do something like `$ ()(l::list(?), i::number)::?`, but then can't return nil on not found...
|
* could do something like `$ ()(l::list(?), i::number)::?`, but then can't return nil on not found...
|
||||||
|
|
||||||
TODO: write a translation guide/simplify translation process
|
TODO: write a translation guide/simplify translation process
|
||||||
|
|
||||||
|
TODO: make injection nicer. Some decorator-like syntax? to select specific functions to inject to
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,8 @@ common = {
|
||||||
injections = {
|
injections = {
|
||||||
["function start"] = "function_start", ["function end"] = "function_end", ["function return"] = "function_return",
|
["function start"] = "function_start", ["function end"] = "function_end", ["function return"] = "function_return",
|
||||||
["scoped function start"] = "scoped_function_start", ["scoped function end"] = "scoped_function_end", ["scoped function return"] = "scoped_function_return",
|
["scoped function start"] = "scoped_function_start", ["scoped function end"] = "scoped_function_end", ["scoped function return"] = "scoped_function_return",
|
||||||
["checkpoint start"] = "checkpoint_start", ["checkpoint end"] = "checkpoint_end"
|
["checkpoint start"] = "checkpoint_start", ["checkpoint end"] = "checkpoint_end",
|
||||||
|
["class start"] = "class_start", ["class end"] = "class_end"
|
||||||
},
|
},
|
||||||
--- escape a string to be used as an exact match pattern
|
--- escape a string to be used as an exact match pattern
|
||||||
escape = function(str)
|
escape = function(str)
|
||||||
|
|
|
||||||
|
|
@ -225,6 +225,18 @@ local function parse_line(line, state, namespace, parent_function)
|
||||||
table.insert(line.children, 1, { content = ":🔖=()", source = line.source })
|
table.insert(line.children, 1, { content = ":🔖=()", source = line.source })
|
||||||
end
|
end
|
||||||
-- custom code injection
|
-- custom code injection
|
||||||
|
if r.subtype == "class" then
|
||||||
|
if state.inject.class_start then
|
||||||
|
for i, ll in ipairs(state.inject.class_start) do
|
||||||
|
table.insert(line.children, 1+i, copy(ll))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if state.inject.class_end then
|
||||||
|
for _, ll in ipairs(state.inject.class_end) do
|
||||||
|
table.insert(line.children, copy(ll))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
if r.scoped then
|
if r.scoped then
|
||||||
if state.inject.scoped_function_start then
|
if state.inject.scoped_function_start then
|
||||||
for i, ll in ipairs(state.inject.scoped_function_start) do
|
for i, ll in ipairs(state.inject.scoped_function_start) do
|
||||||
|
|
@ -248,6 +260,7 @@ local function parse_line(line, state, namespace, parent_function)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
elseif r.subtype == "checkpoint" then
|
elseif r.subtype == "checkpoint" then
|
||||||
-- define 🏁 variable
|
-- define 🏁 variable
|
||||||
local reached_alias = state.global_state.builtin_aliases["🏁"]
|
local reached_alias = state.global_state.builtin_aliases["🏁"]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue