Browse Source

zencode debug improvements

master
Jaromil 3 years ago
parent
commit
4dbfe3f892
  1. 13
      src/lua/zencode.lua
  2. 14
      src/lua/zencode_debug.lua
  3. 8
      src/lua/zenroom_ast.lua
  4. 2
      src/zen_parse.c

13
src/lua/zencode.lua

@ -270,11 +270,14 @@ function zencode.heap()
end
function zencode.debug()
I.warn(ZEN.traceback)
I.warn({ HEAP = { IN = IN,
TMP = TMP,
ACK = ACK,
OUT = OUT }})
debug_traceback()
debug_heap_dump()
-- I.warn(ZEN.traceback)
-- I.warn({ HEAP = { IN = IN,
-- TMP = TMP,
-- ACK = ACK,
-- OUT = OUT }})
end
function zencode.debug_json()

14
src/lua/zencode_debug.lua

@ -16,10 +16,20 @@
-- You should have received a copy of the GNU Affero General Public License
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
-- limit output of string if too long
function limit(anystr)
local t = luatype(anystr)
ZEN.assert(t=='string',"Argument to limit on-screen not a string")
if #anystr > 32 then
return(string.sub(anystr,1,32).."..")
end
return(anystr)
end
-- debug functions
local function debug_traceback()
function debug_traceback()
for k,v in pairs(ZEN.traceback) do
act(v)
warn(v)
end
end
Given("backtrace", function() debug_traceback() end)

8
src/lua/zenroom_ast.lua

@ -45,7 +45,7 @@ function set_sentence(self, event, from, to, ctx)
end
-- TODO: optimize in c
-- remove '' contents, lower everything, expunge prefixes
local tt = string.gsub(ctx.msg,"'(.-)'","''")
local tt = string.gsub(trim(ctx.msg),"'(.-)'","''")
tt = string.gsub(tt:lower() ,"when " ,"", 1)
tt = string.gsub(tt,"then " ,"", 1)
tt = string.gsub(tt,"given ","", 1)
@ -71,9 +71,9 @@ function set_sentence(self, event, from, to, ctx)
end
end
if not ctx.Z.OK and CONF.parser.strict_match then
print(ZEN_traceback)
debug_traceback()
exitcode(1)
error("Zencode pattern not found: "..ctx.msg, 2)
error("Zencode pattern not found: "..trim(ctx.msg), 1)
return false
end
end
@ -133,6 +133,8 @@ function set_rule(text)
res = true
end
-- TODO: rule debug [ format | encoding ]
elseif rule[2] == 'unknown' and rule[3] then
if rule[3] == 'ignore' then
CONF.parser.strict_match = false

2
src/zen_parse.c

@ -84,7 +84,7 @@ static int lua_strcasecmp(lua_State *L) {
return 1;
}
// trim whitespace or single quote in front and at end of string
// trim whitespace in front and at end of string
static int lua_trim_spaces(lua_State* L) {
const char* front;
const char* end;

Loading…
Cancel
Save