[latex3-commits] [git/LaTeX3-latex3-latex2e] callback_rules: Better debuging and error recovery for cycle detection (25fd3e5b)
Marcel Fabian Krüger
tex at 2krueger.de
Sun Sep 4 14:17:55 CEST 2022
Repository : https://github.com/latex3/latex2e
On branch : callback_rules
Link : https://github.com/latex3/latex2e/commit/25fd3e5b776ade77be8ec5856977a4a43c556819
>---------------------------------------------------------------
commit 25fd3e5b776ade77be8ec5856977a4a43c556819
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date: Sun Sep 4 14:14:22 2022 +0200
Better debuging and error recovery for cycle detection
>---------------------------------------------------------------
25fd3e5b776ade77be8ec5856977a4a43c556819
base/ltluatex.dtx | 35 ++++++++++++++++++++++++++++++++++-
1 file changed, 34 insertions(+), 1 deletion(-)
diff --git a/base/ltluatex.dtx b/base/ltluatex.dtx
index 9d9b85ff..8e9883e6 100644
--- a/base/ltluatex.dtx
+++ b/base/ltluatex.dtx
@@ -1373,6 +1373,7 @@ local callbacklist = setmetatable({}, {
for i=1, count do -- The actual sort begins
local current = list[i]
if current then
+ meta[current.value.description] = nil
for j, cur in ipairs(current) do
local count = cur.count
if count == 1 then
@@ -1386,7 +1387,39 @@ local callbacklist = setmetatable({}, {
else
-- Cycle occured. TODO: Show cycle for debugging
-- list[i] = ...
- error'Cycle occured'
+ local remaining = {}
+ for name, entry in next, meta do
+ local value = entry.value
+ list[#list + 1] = entry.value
+ remaining[#remaining + 1] = name
+ end
+ table.sort(remaining)
+ local first_name = remaining[1]
+ for j, name in ipairs(remaining) do
+ local entry = meta[name]
+ list[i + j - 1] = entry.value
+ for _, post_entry in ipairs(entry) do
+ local post_name = post_entry.value.description
+ if not remaining[post_name] then
+ remaining[post_name] = name
+ end
+ end
+ end
+ local cycle = {first_name}
+ local index = 1
+ local last_name = first_name
+ repeat
+ cycle[last_name] = index
+ last_name = remaining[last_name]
+ index = index + 1
+ cycle[index] = last_name
+ until cycle[last_name]
+ local length = index - cycle[last_name] + 1
+ table.move(cycle, cycle[last_name], index, 1)
+ for i=2, length//2 do
+ cycle[i], cycle[length + 1 - i] = cycle[length + 1 - i], cycle[i]
+ end
+ error('Cycle occured at ' .. table.concat(cycle, ' -> ', 1, length))
end
end
end
More information about the latex3-commits
mailing list.