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

Hide internal nodes from stack trace

This commit is contained in:
Étienne Fildadut 2024-01-02 15:06:24 +01:00
parent 5ff178b54c
commit 68a109391f
30 changed files with 120 additions and 26 deletions

View file

@ -68,7 +68,7 @@ local Environment = ast.abstract.Runtime {
variables = nil, -- Table of { {identifier} = variable metadata, ... }
partial = nil, -- { [name string] = true, ... }
undefine = nil, -- { [name string] = true, ... }
undefine = nil, -- { [name string] = true, ... } - variable present here will not be looked up in parent env
export = nil, -- bool
init = function(self, state, parent, partial_names, is_export)
@ -186,16 +186,6 @@ local Environment = ast.abstract.Runtime {
return self:_get_variable(state, identifier):set(state, val)
end,
-- returns a list {[symbol]=val,...} of all exported variables (evaluated) in the current strict layer
-- TODO currently unused
list_exported = function(self, state)
assert(self.export, "not an export scope layer")
local r = {}
for _, vm in self.variables:iter(state) do
r[vm.symbol] = vm:get(state)
end
return r
end,
-- return the depth of the environmenet, i.e. the number of parents
depth = function(self)
local d = 0

View file

@ -9,6 +9,7 @@ local unpack = table.unpack or unpack
local PartialScope
PartialScope = ast.abstract.Node {
type = "partial scope",
hide_in_stacktrace = true,
expression = nil,
definitions = nil, -- {[sym]=value,...}

View file

@ -10,6 +10,7 @@ local ast = require("anselme.ast")
local Quote
Quote = ast.abstract.Node {
type = "quote",
hide_in_stacktrace = true,
expression = nil,

View file

@ -5,6 +5,7 @@ local Return
local ReturnBoundary = ast.abstract.Node {
type = "return boundary",
hide_in_stacktrace = true,
expression = nil,

View file

@ -7,6 +7,7 @@ local translation_manager
local Translatable = ast.abstract.Node {
type = "translatable",
hide_in_stacktrace = true,
expression = nil,

View file

@ -27,8 +27,12 @@ local function cutoff_text(str)
return str
end
local function format_error(state, node, message)
local ctx = cutoff_text(node:format(state)) -- get some context code around error
return fmt("%{red}%s%{reset}\n\t↳ from %{underline}%s%{reset} in %s: %{dim}%s", message, node.source, node.type, ctx)
if node.hide_in_stacktrace then
return message
else
local ctx = cutoff_text(node:format(state)) -- get some context code around error
return fmt("%{red}%s%{reset}\n\t↳ from %{underline}%s%{reset} in %s: %{dim}%s", message, node.source, node.type, ctx)
end
end
-- traverse helpers
@ -58,6 +62,7 @@ Node = class {
type = "node",
source = "?",
mutable = false,
hide_in_stacktrace = false,
-- abstract class
-- must be redefined