From 9f89207cca864754aaad2edd2e50b3b0bf69fd07 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 2 Mar 2014 16:58:34 +0100 Subject: fix handling of locals inside itemization scanner --- src/rst_context.lua | 16 +++++------ src/rst_parser.lua | 78 ++++++++++++++++++++++++++++------------------------- 2 files changed, 50 insertions(+), 44 deletions(-) diff --git a/src/rst_context.lua b/src/rst_context.lua index 1654832..db05537 100644 --- a/src/rst_context.lua +++ b/src/rst_context.lua @@ -817,10 +817,11 @@ function rst_context.startitemize(str) return result end -local last_item = {} -- stack +local item_stack = { } + local current_itemdepth = 0 function rst_context.stopitemize(str) - last_item[current_itemdepth] = nil + item_stack[current_itemdepth] = nil current_itemdepth = current_itemdepth - 1 return str .. [[ \\stopitemize @@ -828,7 +829,6 @@ function rst_context.stopitemize(str) end function rst_context.bullet_item (tab) - local li = last_item -- The capture of the first item has the \startitemize as -- *second* element in the array. local content = #tab == 2 and tab[2] or tab[3] @@ -837,17 +837,17 @@ function rst_context.bullet_item (tab) local result = startstr or "" if startstr then current_itemdepth = current_itemdepth + 1 - li[current_itemdepth] = itemtype - elseif li[current_itemdepth] then - if helpers.list.successor(itemtype, li[current_itemdepth]) then + item_stack[current_itemdepth] = itemtype + elseif item_stack[current_itemdepth] then + if helpers.list.successor(itemtype, item_stack[current_itemdepth]) then -- just leave it alone - elseif helpers.list.greater(itemtype, li[current_itemdepth]) then + elseif helpers.list.greater(itemtype, item_stack[current_itemdepth]) then local itemnum = tonumber(stringstrip(itemtype)) or helpers.list.get_decimal(itemtype) result = result .. stringformat([[ \\setnumber[itemgroup:itemize]{%s} ]], itemnum) end - li[current_itemdepth] = itemtype + item_stack[current_itemdepth] = itemtype end return result .. [[ diff --git a/src/rst_parser.lua b/src/rst_parser.lua index 10994d9..82e906a 100644 --- a/src/rst_parser.lua +++ b/src/rst_parser.lua @@ -900,11 +900,12 @@ local rst_parser = P { * (V"blank_line"^-1 * (V"bullet_list" + V"bullet_continue"))^1 * V"bullet_stop" * Cmt(Cc(nil), function (s, i) - local t = state - warn("close", t.depth) - t.bullets[t.depth] = nil -- “pop” - t.depth = t.depth - 1 - t.lastbullet = t.lastbullets[t.depth] + local depth = state.depth + warn("close", depth) + state.bullets[depth] = nil -- “pop” + depth = depth - 1 + state.lastbullet = state.lastbullets[depth] + state.depth = depth return true end), @@ -915,30 +916,32 @@ local rst_parser = P { , bullet_first = #Cmt(V"bullet_indent", function (s, i, bullet) - local t = state - local oldbullet = t.bullets[t.depth] - local n_spaces = lpegmatch(P" "^0, bullet) + local depth = state.depth + local bullets = state.bullets + local oldbullet = state.bullets[depth] + local n_spaces = lpegmatch(P" "^0, bullet) warn("first", - t.depth, - (t.depth == 0 and n_spaces >= 1) or - (t.depth > 0 and n_spaces > 1), + depth, + (depth == 0 and n_spaces >= 1) or (depth > 0 and n_spaces > 1), bullet, oldbullet, helpers.list.conversion(bullet)) - if t.depth == 0 and n_spaces >= 1 then -- first level - t.depth = 1 -- “push” - t.bullets[1] = bullet - t.lastbullet = bullet - t.bullets.max = t.bullets.max < t.depth and t.depth or t.bullets.max + if depth == 0 and n_spaces >= 1 then -- first level + depth = 1 -- “push” + bullets[1] = bullet + state.lastbullet = bullet + bullets.max = bullets.max < depth and depth or bullets.max + state.depth = depth return true - elseif t.depth > 0 and n_spaces > 1 then -- sublist (of sublist)^0 + elseif depth > 0 and n_spaces > 1 then -- sublist (of sublist)^0 if n_spaces >= utflen(oldbullet) then - t.lastbullets[t.depth] = t.lastbullet - t.depth = t.depth + 1 - t.bullets[t.depth] = bullet - t.lastbullet = bullet - t.bullets.max = t.bullets.max < t.depth and t.depth or t.bullets.max + state.lastbullets[depth] = state.lastbullet + depth = depth + 1 + bullets[depth] = bullet + state.lastbullet = bullet + bullets.max = bullets.max < depth and depth or bullets.max + state.depth = depth return true end end @@ -951,29 +954,32 @@ local rst_parser = P { bullet_indent = V"space"^0 * V"bullet_expr" * V"space"^1, bullet_cont = Cmt(V"bullet_indent", function (s, i, bullet) - local t = state - local conversion = helpers.list.conversion + local conversion = helpers.list.conversion + local depth = state.depth + local bullets = state.bullets + local lastbullets = state.lastbullets warn("conti", - t.depth, - bullet == t.bullets[t.depth], + depth, + bullet == bullets[depth], bullet, - t.bullets[t.depth], - t.lastbullets[t.depth], - conversion(t.lastbullet), + bullets[depth], + lastbullets[depth], + conversion(state.lastbullet), conversion(bullet) ) - if utflen(t.bullets[t.depth]) ~= utflen(bullet) then + if utflen(bullets[depth]) ~= utflen(bullet) then return false - elseif not conversion(bullet) and t.bullets[t.depth] == bullet then + elseif not conversion(bullet) and bullets[depth] == bullet then return true - elseif conversion(t.lastbullet) == conversion(bullet) then -- same type + elseif conversion(state.lastbullet) == conversion(bullet) then -- same type local autoconv = conversion(bullet) == "auto" - local greater = helpers.list.greater (bullet, t.lastbullet) - t.lastbullet = bullet + local greater = helpers.list.greater (bullet, state.lastbullet) + state.lastbullet = bullet return autoconv or successor or greater end - end), + end) + , bullet_continue = Ct(C(V"bullet_cont") * V"bullet_itemrest") /rst.bullet_item @@ -1549,7 +1555,7 @@ local get_tmpfile = function (category) cnt = cnt + 1 tempfile_count[category] = cnt return luatex.registertempfile ( - stringformat ("%s_rst-%s-%d", + stringformat ("%s_rst-%s-%d.tmp", tex.jobname, category, cnt) -- cgit v1.2.3