From 311fc80cac4b39f772e7b75176fce455d33a6630 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 12 Sep 2010 22:06:53 +0200 Subject: handling of escaped spaces in string.strip --- rst_context.lua | 29 +++++++++++++++++++---------- rst_helpers.lua | 5 ++++- rst_parser.lua | 3 ++- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/rst_context.lua b/rst_context.lua index 1f49bff..96e7f89 100644 --- a/rst_context.lua +++ b/rst_context.lua @@ -25,12 +25,14 @@ local dbg_write = help.dbg_writef local C, Cb, Cc, Cg, Cmt, Cp, Cs, Ct, P, R, S, V, match = lpeg.C, lpeg.Cb, lpeg.Cc, lpeg.Cg, lpeg.Cmt, lpeg.Cp, lpeg.Cs, lpeg.Ct, lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.match -if not context then -- standard context lpeg stripper from l-string.lua +-- This one should ignore escaped spaces. +do local stripper = P{ [1] = "stripper", - stripper = V"space"^0 * C((V"space"^0 * V"nospace"^1)^0), + stripper = V"space"^0 * C((V"space"^0 * (V"escaped" + V"nospace")^1)^0), space = S(" \t\v\n"), nospace = 1 - V"space", + escaped = P"\\" * V"space" } function string.strip(str) return stripper:match(str) or "" @@ -359,12 +361,17 @@ function rst_context.bullet_marker(str) return "marker" end +-- This one should ignore escaped spaces. do - local space = lpeg.S(" \t\v\n") - local nospace = 1 - space - local stripper = space^0 * lpeg.C((space^0 * nospace^1)^0) + local stripper = P{ + [1] = "stripper", + stripper = V"space"^0 * C((V"space"^0 * V"nospace"^1)^0), + space = S(" \t\v\n"), + escaped = P"\\" * V"space", + nospace = V"escaped" + (1 - V"space"), + } function string.strip(str) - return match(stripper,str) or "" + return stripper:match(str) or "" end end @@ -745,10 +752,11 @@ function rst_context.simple_table(tab) head = head .. [[\\bTR]] for nc,cell in ipairs(row) do dbg_write("%7s | ", cell.content) + local celltext = inline_parser:match(cell.content) if cell.span then - head = head .. string.format([=[\\bTH[nc=%s]%s\\eTH]=], cell.span.x, cell.content) + head = head .. string.format([=[\\bTH[nc=%s]%s\\eTH]=], cell.span.x, celltext) else - head = head .. [[\\bTH ]] .. cell.content .. [[\\eTH]] + head = head .. [[\\bTH ]] .. celltext .. [[\\eTH]] end end dbg_write("\n") @@ -784,10 +792,11 @@ function rst_context.simple_table(tab) body = body .. [[\\bTR]] for nc,cell in ipairs(row) do dbg_write("%7s | ", cell.content) + local celltext = inline_parser:match(cell.content) if cell.span then - body = body .. string.format([=[\\bTC[nc=%s]%s\\eTC]=], cell.span.x, cell.content) + body = body .. string.format([=[\\bTC[nc=%s]%s\\eTC]=], cell.span.x, celltext) else - body = body .. [[\\bTC ]] .. cell.content .. [[\\eTC]] + body = body .. [[\\bTC ]] .. celltext .. [[\\eTC]] end end dbg_write("\n") diff --git a/rst_helpers.lua b/rst_helpers.lua index 4faecbd..a635996 100644 --- a/rst_helpers.lua +++ b/rst_helpers.lua @@ -530,13 +530,15 @@ function helpers.table.simple(raw) end for nc, start in ipairs(starts) do - local stop = stops[nc] + -- last column can exceed layout width + local stop = nc ~= #starts and stops[nc] or #row local cell = { content = "", span = { x = 1, y = 1 }, --ignore = false } cell.content = string.strip(row:sub(start, stop)) + print(">>".. row:sub(start, stop) .."<<", ">>"..cell.content.."<<") if check_span then local start_at, stop_at for colnr, slice in ipairs(bounds.slices) do @@ -555,6 +557,7 @@ function helpers.table.simple(raw) end end cell.span.x = 1 + stop_at - start_at + print(start_at, stop_at, cell.span.x) end newrow[nc] = cell end diff --git a/rst_parser.lua b/rst_parser.lua index f9f29c1..ddd13a8 100644 --- a/rst_parser.lua +++ b/rst_parser.lua @@ -260,7 +260,8 @@ local parser = P{ st_other_rows = (V"st_content"^1 * V"st_separator")^1, - st_content = C(V"st_matchlayout"), + st_content = V"blank_line"^-1 + * C(V"st_matchlayout"), st_matchlayout = -#V"st_separator" * Cmt((1 - V"eol")^1, function (s, i, content) -- Don't check for matching indent but if the rest is -- cgit v1.2.3