Skip to content

Commit

Permalink
Enhance debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
zepinglee committed Jul 10, 2024
1 parent 640cc06 commit f2f5c05
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .busted
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ return {
},
citeproc = {
ROOT = {"tests/citeproc_test.lua"},
output = "tests/bust-output.lua",
-- output = "tests/bust-output.lua",
},
}
27 changes: 17 additions & 10 deletions citeproc/citeproc-output.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,28 @@ function InlineElement:new(inlines)
end


function InlineElement:_debug()
local text = self._type .. "("
function InlineElement:_debug(level)
level = level or 0
local text = ""
if level == 0 then
text = "\n"
end
text = text .. self._type
if self.formatting then
text = text .. "["
for attr, value in pairs(self.formatting) do
text = text .. attr .. '="' .. value .. '"'
end
text = text .. "]"
end
text = text .. "("
if self.value then
text = text .. '"' .. self.value .. '"'
elseif self.inlines then
local inlines_text = ""
for _, inline in ipairs(self.inlines) do
if inlines_text ~= "" then
inlines_text = inlines_text .. ", "
end
inlines_text = inlines_text .. inline:_debug()
text = text .. "\n" .. string.rep(" ", level + 1) .. inline:_debug(level + 1) .. ", "
end
text = text .. inlines_text
text = text .. "\n" .. string.rep(" ", level)
end
text = text .. ")"
return text
Expand Down Expand Up @@ -1273,7 +1282,6 @@ function OutputFormat:flip_flop(inlines, state)
elseif inline._type == "Code" or
inline._type == "MathML" or
inline._type == "MathTeX" then
return

elseif inline.inlines then -- Div, ...
self:flip_flop(inline.inlines, state)
Expand Down Expand Up @@ -1336,7 +1344,6 @@ function OutputFormat:flip_flop_micro_inlines(inlines, state)
elseif inline._type == "Code" or
inline._type == "MathML" or
inline._type == "MathTeX" then
return

elseif inline.inlines then -- Div, ...
self:flip_flop_micro_inlines(inline.inlines, state)
Expand Down
11 changes: 9 additions & 2 deletions citeproc/citeproc-util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,15 @@ local remove_all_metatables = nil

function util.debug(obj)
local text
if type(obj) == "table" and obj._debug then
text = obj:_debug()
if type(obj) == "table" and (obj._debug or (obj[1] and obj[1]._debug)) then
if obj._debug then
text = obj:_debug()
else
text = ""
for _, child in ipairs(obj) do
text = text .. child:_debug()
end
end
else
if not inspect then
inspect = require("inspect")
Expand Down
2 changes: 2 additions & 0 deletions tests/latex/config-luatex-1.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ testfiledir = "./tests/latex/luatex-1"

checkengines = {"luatex"}
stdengine = "luatex"
-- Since LuaTeX 2024-01-04, the `debug` library must be enabled with `--luadebug` argument.
checkopts = "-interaction=nonstopmode --luadebug"

checkruns = 1
2 changes: 2 additions & 0 deletions tests/latex/config-luatex-2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ testfiledir = "./tests/latex/luatex-2"

checkengines = {"luatex"}
stdengine = "luatex"
-- Since LuaTeX 2024-01-04, the `debug` library must be enabled with `--luadebug` argument.
checkopts = "-interaction=nonstopmode --luadebug"

checkruns = 2

0 comments on commit f2f5c05

Please sign in to comment.