From 0526f4b53574cd916c133899b611422d487c6047 Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 27 Sep 2011 23:00:27 +0300 Subject: beta 2011.09.27 20:05 --- scripts/context/lua/mtx-check.lua | 107 ++++++++++++++++++++------------- scripts/context/lua/mtx-context.lua | 2 +- scripts/context/lua/mtx-epub.lua | 11 ++-- scripts/context/lua/mtxrun.lua | 4 +- scripts/context/stubs/mswin/mtxrun.lua | 4 +- scripts/context/stubs/unix/mtxrun | 4 +- 6 files changed, 79 insertions(+), 53 deletions(-) (limited to 'scripts') diff --git a/scripts/context/lua/mtx-check.lua b/scripts/context/lua/mtx-check.lua index e0ab3b882..38ab2254a 100644 --- a/scripts/context/lua/mtx-check.lua +++ b/scripts/context/lua/mtx-check.lua @@ -6,6 +6,9 @@ if not modules then modules = { } end modules ['mtx-check'] = { license = "see context related readme files" } +local P, R, S, V, C, CP, CC, lpegmatch = lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.C, lpeg.Cp, lpeg.Cc, lpeg.match +local gsub, sub, format = string.gsub, string.sub, string.format + local helpinfo = [[ --convert check tex file for errors ]] @@ -31,21 +34,23 @@ validator.direct = false validator.printer = print validator.tracer = print -local message = function(position, kind) +local message = function(position, kind, extra) local ve = validator.errors - ve[#ve+1] = { kind, position, validator.n } + ve[#ve+1] = { kind, position, validator.n, extra } if validator.direct then - validator.printer(string.format("%s error at position %s (line %s)", kind, position, validator.n)) + if extra then + validator.printer(format("%s error at position %s (line %s) (%s)",kind,position,validator.n,extra)) + else + validator.printer(format("%s error at position %s (line %s)",kind,position,validator.n)) + end end end local progress = function(position, data, kind) if validator.trace then - validator.tracer(string.format("%s at position %s: %s", kind, position, data or "")) + validator.tracer(format("%s at position %s: %s", kind, position, data or "")) end end -local P, R, S, V, C, CP, CC = lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.C, lpeg.Cp, lpeg.Cc - local i_m, d_m = P("$"), P("$$") local l_s, r_s = P("["), P("]") local l_g, r_g = P("{"), P("}") @@ -61,44 +66,56 @@ local newline = crlf + cr + lf local line = newline / function() validator.n = validator.n + 1 end --- local grammar = P { "tokens", --- ["tokens"] = (V("whatever") + V("grouped") + V("setup") + V("display") + V("inline") + V("errors") + 1)^0, --- ["whatever"] = line + esc * 1 + C(P("%") * (1-line)^0), --- ["grouped"] = CP() * C(l_g * (V("whatever") + V("grouped") + V("setup") + V("display") + V("inline") + (1 - l_g - r_g))^0 * r_g) * CC("group") / progress, --- ["setup"] = CP() * C(l_s * (V("whatever") + V("grouped") + V("setup") + V("display") + V("inline") + (1 - l_s - r_s))^0 * r_s) * CC("setup") / progress, --- ["display"] = CP() * C(d_m * (V("whatever") + V("grouped") + (1 - d_m))^0 * d_m) * CC("display") / progress, --- ["inline"] = CP() * C(i_m * (V("whatever") + V("grouped") + (1 - i_m))^0 * i_m) * CC("inline") / progress, --- ["errors"] = (V("gerror") + V("serror") + V("derror") + V("ierror")) * true, --- ["gerror"] = CP() * (l_g + r_g) * CC("grouping") / message, --- ["serror"] = CP() * (l_s + r_g) * CC("setup error") / message, --- ["derror"] = CP() * d_m * CC("display math error") / message, --- ["ierror"] = CP() * i_m * CC("inline math error") / message, --- } - local startluacode = P("\\startluacode") local stopluacode = P("\\stopluacode") local somecode = startluacode * (1-stopluacode)^1 * stopluacode +local stack = { } + +local function push(p,s) +-- print("start",p,s) + table.insert(stack,{ p, s }) +end + +local function pop(p,s) +-- print("stop",p,s) + local top = table.remove(stack) + if not top then + message(p,"missing start") + elseif top[2] ~= s then + message(p,"missing stop",format("see line %s",top[1])) + else + -- okay + end +end + +local cstoken = R("az","AZ","\127\255") + +local start = CP() * P("\\start") * C(cstoken^0) / push +local stop = CP() * P("\\stop") * C(cstoken^0) / pop + local grammar = P { "tokens", - ["tokens"] = (V("ignore") + V("whatever") + V("grouped") + V("setup") + V("display") + V("inline") + V("errors") + 1)^0, - ["whatever"] = line + esc * 1 + C(P("%") * (1-line)^0), - ["grouped"] = l_g * (V("whatever") + V("grouped") + V("setup") + V("display") + V("inline") + (1 - l_g - r_g))^0 * r_g, - ["setup"] = l_s * (okay + V("whatever") + V("grouped") + V("setup") + V("display") + V("inline") + (1 - l_s - r_s))^0 * r_s, - ["display"] = d_m * (V("whatever") + V("grouped") + (1 - d_m))^0 * d_m, - ["inline"] = i_m * (V("whatever") + V("grouped") + (1 - i_m))^0 * i_m, - ["errors"] = (V("gerror")+ V("serror") + V("derror") + V("ierror")), - ["gerror"] = CP() * (l_g + r_g) * CC("grouping") / message, - ["serror"] = CP() * (l_s + r_g) * CC("setup error") / message, - ["derror"] = CP() * d_m * CC("display math error") / message, - ["ierror"] = CP() * i_m * CC("inline math error") / message, - ["ignore"] = somecode, + ["tokens"] = (V("ignore") + V("start") + V("stop") + V("whatever") + V("grouped") + V("setup") + V("display") + V("inline") + V("errors") + 1)^0, + ["start"] = start, + ["stop"] = stop, + ["whatever"] = line + esc * 1 + C(P("%") * (1-line)^0), + ["grouped"] = l_g * (V("whatever") + V("grouped") + V("setup") + V("display") + V("inline") + (1 - l_g - r_g))^0 * r_g, + ["setup"] = l_s * (okay + V("whatever") + V("grouped") + V("setup") + V("display") + V("inline") + (1 - l_s - r_s))^0 * r_s, + ["display"] = d_m * (V("whatever") + V("grouped") + (1 - d_m))^0 * d_m, + ["inline"] = i_m * (V("whatever") + V("grouped") + (1 - i_m))^0 * i_m, + ["errors"] = (V("gerror")+ V("serror") + V("derror") + V("ierror")), + ["gerror"] = CP() * (l_g + r_g) * CC("grouping") / message, + ["serror"] = CP() * (l_s + r_g) * CC("setup error") / message, + ["derror"] = CP() * d_m * CC("display math error") / message, + ["ierror"] = CP() * i_m * CC("inline math error") / message, + ["ignore"] = somecode, } function validator.check(str) validator.n = 1 validator.errors = { } - grammar:match(str) + lpegmatch(grammar,str) end --~ str = [[ @@ -109,6 +126,12 @@ end --~ ]] --~ str = string.rep(str,10) +local remapper = { + ["\n"] = " ", + ["\r"] = " ", + ["\t"] = " ", +} + function scripts.checker.check(filename) local str = io.loaddata(filename) if str then @@ -117,15 +140,15 @@ function scripts.checker.check(filename) if #errors > 0 then for k=1,#errors do local v = errors[k] - local kind, position, line = v[1], v[2], v[3] - local data = str:sub(position-30,position+30) - data = data:gsub("(.)", { - ["\n"] = " ", - ["\r"] = " ", - ["\t"] = " ", - }) - data = data:gsub("^ *","") - print(string.format("% 5i %-10s %s", line, kind, data)) + local kind, position, line, extra = v[1], v[2], v[3], v[4] + local data = sub(str,position-30,position+30) + data = gsub(data,".", remapper) + data = gsub(data,"^ *","") + if extra then + print(format("% 5i %-10s %s (%s)", line, kind, data, extra)) + else + print(format("% 5i %-10s %s", line, kind, data)) + end end else print("no error") diff --git a/scripts/context/lua/mtx-context.lua b/scripts/context/lua/mtx-context.lua index 43dcd3455..82346f394 100644 --- a/scripts/context/lua/mtx-context.lua +++ b/scripts/context/lua/mtx-context.lua @@ -626,7 +626,7 @@ scripts.context.interfaces = { de = "cont-de", fr = "cont-fr", nl = "cont-nl", - cz = "cont-cz", + cs = "cont-cs", it = "cont-it", ro = "cont-ro", pe = "cont-pe", diff --git a/scripts/context/lua/mtx-epub.lua b/scripts/context/lua/mtx-epub.lua index a4b96d3be..0dc533c4a 100644 --- a/scripts/context/lua/mtx-epub.lua +++ b/scripts/context/lua/mtx-epub.lua @@ -62,7 +62,7 @@ local package = [[ en urn:uuid:%s MySelf - %s + %s @@ -168,13 +168,13 @@ function scripts.epub.make() local filename = environment.files[1] - if filename and filename ~= "" then + if filename and filename ~= "" and type(filename) == "string" then filename = file.basename(filename) local specfile = file.replacesuffix(filename,"specification") local specification = lfs.isfile(specfile) and dofile(specfile) or { } - -- inspect(specification) +-- inspect(specification) local name = specification.name or file.removesuffix(filename) local identifier = specification.identifier or os.uuid(true) @@ -215,7 +215,10 @@ function scripts.epub.make() local function copythem(files) for i=1,#files do - copyone(files[i]) + local filename = files[i] + if type(filename) == "string" then + copyone(filename) + end end end diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index 7061c54d5..3e6d9e303 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -3719,7 +3719,7 @@ local function utf16_to_utf8_be(t) if right then local now = 256*left + right if more > 0 then - now = (more-0xD800)*0x400 + (now-0xDC00) + 0x10000 + now = (more-0xD800)*0x400 + (now-0xDC00) + 0x10000 -- the 0x10000 smells wrong more = 0 r = r + 1 result[r] = utfchar(now) @@ -3747,7 +3747,7 @@ local function utf16_to_utf8_le(t) if right then local now = 256*right + left if more > 0 then - now = (more-0xD800)*0x400 + (now-0xDC00) + 0x10000 + now = (more-0xD800)*0x400 + (now-0xDC00) + 0x10000 -- the 0x10000 smells wrong more = 0 r = r + 1 result[r] = utfchar(now) diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index 7061c54d5..3e6d9e303 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -3719,7 +3719,7 @@ local function utf16_to_utf8_be(t) if right then local now = 256*left + right if more > 0 then - now = (more-0xD800)*0x400 + (now-0xDC00) + 0x10000 + now = (more-0xD800)*0x400 + (now-0xDC00) + 0x10000 -- the 0x10000 smells wrong more = 0 r = r + 1 result[r] = utfchar(now) @@ -3747,7 +3747,7 @@ local function utf16_to_utf8_le(t) if right then local now = 256*right + left if more > 0 then - now = (more-0xD800)*0x400 + (now-0xDC00) + 0x10000 + now = (more-0xD800)*0x400 + (now-0xDC00) + 0x10000 -- the 0x10000 smells wrong more = 0 r = r + 1 result[r] = utfchar(now) diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index 7061c54d5..3e6d9e303 100644 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -3719,7 +3719,7 @@ local function utf16_to_utf8_be(t) if right then local now = 256*left + right if more > 0 then - now = (more-0xD800)*0x400 + (now-0xDC00) + 0x10000 + now = (more-0xD800)*0x400 + (now-0xDC00) + 0x10000 -- the 0x10000 smells wrong more = 0 r = r + 1 result[r] = utfchar(now) @@ -3747,7 +3747,7 @@ local function utf16_to_utf8_le(t) if right then local now = 256*right + left if more > 0 then - now = (more-0xD800)*0x400 + (now-0xDC00) + 0x10000 + now = (more-0xD800)*0x400 + (now-0xDC00) + 0x10000 -- the 0x10000 smells wrong more = 0 r = r + 1 result[r] = utfchar(now) -- cgit v1.2.3