diff --git a/anselme.lua b/anselme.lua index 082fa90..fdb5a1b 100644 --- a/anselme.lua +++ b/anselme.lua @@ -116,7 +116,7 @@ local interpreter_methods = { return self end, - --- interrupt the vm on the next step, executing an expression if specified + --- interrupt the vm on the next step, executing an expression (if specified) in the current namespace -- returns self interrupt = function(self, expr) self.state.interpreter.interrupt = expr or true diff --git a/parser/preparser.lua b/parser/preparser.lua index 17e81a2..d8faa25 100644 --- a/parser/preparser.lua +++ b/parser/preparser.lua @@ -1,4 +1,4 @@ -local format_identifier, identifier_pattern, escape, special_functions_names, pretty_signature, signature +local format_identifier, identifier_pattern, escape, special_functions_names, pretty_signature, signature, copy local parse_indented @@ -202,23 +202,23 @@ local function parse_line(line, state, namespace) 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, ll) + 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 - table.insert(line.children, ll) + 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, ll) + 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, ll) + table.insert(line.children, copy(ll)) end end end @@ -233,12 +233,12 @@ local function parse_line(line, state, namespace) -- custom code injection if state.inject.checkpoint_start then for i, ll in ipairs(state.inject.checkpoint_start) do - table.insert(line.children, 1+i, ll) + table.insert(line.children, 1+i, copy(ll)) end end if state.inject.checkpoint_end then for _, ll in ipairs(state.inject.checkpoint_end) do - table.insert(line.children, ll) + table.insert(line.children, copy(ll)) end end end @@ -530,5 +530,6 @@ end package.loaded[...] = parse local common = require((...):gsub("preparser$", "common")) format_identifier, identifier_pattern, escape, special_functions_names, pretty_signature, signature = common.format_identifier, common.identifier_pattern, common.escape, common.special_functions_names, common.pretty_signature, common.signature +copy = require((...):gsub("parser%.preparser$", "common")).copy return parse