1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-27 16:49:31 +00:00

Separate function and class injections

This commit is contained in:
Étienne Fildadut 2022-09-16 21:55:06 +09:00
parent c43266260d
commit e017a391ec
4 changed files with 31 additions and 13 deletions

View file

@ -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
-- * `"checkpoint start"`: injected at the start 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 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

View file

@ -106,3 +106,5 @@ Disadvantages:
* 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: make injection nicer. Some decorator-like syntax? to select specific functions to inject to

View file

@ -66,7 +66,8 @@ common = {
injections = {
["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",
["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 = function(str)

View file

@ -225,26 +225,39 @@ local function parse_line(line, state, namespace, parent_function)
table.insert(line.children, 1, { content = ":🔖=()", source = line.source })
end
-- custom code injection
if r.scoped then
if state.inject.scoped_function_start then
for i, ll in ipairs(state.inject.scoped_function_start) do
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.scoped_function_end then
for _, ll in ipairs(state.inject.scoped_function_end) do
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 state.inject.function_start then
for i, ll in ipairs(state.inject.function_start) do
table.insert(line.children, 1+i, copy(ll))
if r.scoped then
if state.inject.scoped_function_start then
for i, ll in ipairs(state.inject.scoped_function_start) do
table.insert(line.children, 1+i, copy(ll))
end
end
end
if state.inject.function_end then
for _, ll in ipairs(state.inject.function_end) do
table.insert(line.children, copy(ll))
if state.inject.scoped_function_end then
for _, ll in ipairs(state.inject.scoped_function_end) do
table.insert(line.children, copy(ll))
end
end
else
if state.inject.function_start then
for i, ll in ipairs(state.inject.function_start) do
table.insert(line.children, 1+i, copy(ll))
end
end
if state.inject.function_end then
for _, ll in ipairs(state.inject.function_end) do
table.insert(line.children, copy(ll))
end
end
end
end