summaryrefslogtreecommitdiff
path: root/mod/tex/context/third/rst/rst_parser.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <megas.kapaneus@gmail.com>2011-08-28 14:30:54 +0200
committerPhilipp Gesang <megas.kapaneus@gmail.com>2011-08-28 14:30:54 +0200
commit001738e26e1b841a4042b3597ba28d9c3d04aef6 (patch)
tree6e1898eed40ac96a7677206109e6395ddd98f619 /mod/tex/context/third/rst/rst_parser.lua
parent258db63993a69f76301faefa7e7a5727f23d2614 (diff)
downloadcontext-rst-001738e26e1b841a4042b3597ba28d9c3d04aef6.tar.gz
fixed solitary substitution bug (reported by Philipp A.)
Diffstat (limited to 'mod/tex/context/third/rst/rst_parser.lua')
-rw-r--r--mod/tex/context/third/rst/rst_parser.lua57
1 files changed, 34 insertions, 23 deletions
diff --git a/mod/tex/context/third/rst/rst_parser.lua b/mod/tex/context/third/rst/rst_parser.lua
index 42d8a11..ff5d648 100644
--- a/mod/tex/context/third/rst/rst_parser.lua
+++ b/mod/tex/context/third/rst/rst_parser.lua
@@ -28,22 +28,35 @@ rst.expandtab = false
rst.shiftwidth = 4
helpers.rst_debug = false
-local warn = function(str, ...)
- if not helpers.rst_debug then return false end
- local slen = #str + 3
- str = "*["..str.."]"
- for i,j in ipairs({...}) do
- if 80 - i * 8 - slen < 0 then
- local indent = ""
- for i=1, slen do
- indent = indent .. " "
+local iowrite = io.write
+local fmt = string.format
+local stringlen = string.len
+local stringstrip = string.strip
+local utf = unicode.utf8
+local utflen = utf.len
+
+local warn
+do
+ local ndebug = 0
+ warn = function(str, ...)
+ if not helpers.rst_debug then return false end
+ ndebug = ndebug + 1
+ local slen = #str + 3
+ --str = "*["..str.."]"
+ str = fmt("*[%4d][%s]", ndebug, str)
+ for i,j in ipairs({...}) do
+ if 80 - i * 8 - slen < 0 then
+ local indent = ""
+ for i=1, slen do
+ indent = indent .. " "
+ end
+ str = str .. "\n" .. indent
end
- str = str .. "\n" .. indent
+ str = str .. fmt(" |%6s", stringstrip(tostring(j)))
end
- str = str .. string.format(" |%6s", string.strip(tostring(j)))
+ iowrite(str .. " |\n")
+ return 0
end
- iowrite(str .. " |\n")
- return 0
end
local C, Cb, Cc, Cg, Cmt, Cp, Cs, Ct
@@ -54,8 +67,6 @@ local P, R, S, V, match
local utf = unicode.utf8
-local iowrite = io.write
-
local eol = P"\n"
state = {}
@@ -544,7 +555,7 @@ local parser = P{
block_quote_attri_first = Cmt(V"space"^1 * V"attrib_dash" * V"space", function (s, i, indent)
local t = state
- warn("bqa-i", utf.len(indent), #t.currentindent,
+ warn("bqa-i", utflen(indent), #t.currentindent,
indent, t.currentindent, i)
local ret = indent:match(" *") == t.currentindent
t.currentindent = ret and indent or t.currentindent
@@ -555,9 +566,9 @@ local parser = P{
,
block_quote_attri_other = Cmt(V"space"^1, function (s, i, indent)
- warn("bqa-m", #indent, utf.len(state.currentindent),
+ warn("bqa-m", #indent, utflen(state.currentindent),
indent, state.currentindent, i)
- return utf.len(state.currentindent) == #indent
+ return utflen(state.currentindent) == #indent
end) / ""
* (1 - V"eol")^1
* V"eol"
@@ -881,7 +892,7 @@ local parser = P{
t.bullets.max = t.bullets.max < t.depth and t.depth or t.bullets.max
return true
elseif t.depth > 0 and n_spaces > 1 then -- sublist (of sublist)^0
- if n_spaces >= utf.len(oldbullet) then
+ if n_spaces >= utflen(oldbullet) then
t.lastbullets[t.depth] = t.lastbullet
t.depth = t.depth + 1
t.bullets[t.depth] = bullet
@@ -911,7 +922,7 @@ local parser = P{
conversion(bullet)
)
- if utf.len(t.bullets[t.depth]) ~= utf.len(bullet) then
+ if utflen(t.bullets[t.depth]) ~= utflen(bullet) then
return false
elseif not conversion(bullet) and t.bullets[t.depth] == bullet then
return true
@@ -944,9 +955,9 @@ local parser = P{
local t = state
warn("match",
t.depth,
- string.len(this) == utf.len(t.bullets[t.depth]),
- utf.len(t.bullets[t.depth]), string.len(this) )
- return string.len(this) == utf.len(t.bullets[t.depth])
+ stringlen(this) == utflen(t.bullets[t.depth]),
+ utflen(t.bullets[t.depth]), stringlen(this) )
+ return stringlen(this) == utflen(t.bullets[t.depth])
end)
,