diff options
Diffstat (limited to 'Master/texmf-dist/scripts/context/lua/mtx-check.lua')
-rw-r--r-- | Master/texmf-dist/scripts/context/lua/mtx-check.lua | 168 |
1 files changed, 86 insertions, 82 deletions
diff --git a/Master/texmf-dist/scripts/context/lua/mtx-check.lua b/Master/texmf-dist/scripts/context/lua/mtx-check.lua index 4266ddf0d46..e0ab3b88276 100644 --- a/Master/texmf-dist/scripts/context/lua/mtx-check.lua +++ b/Master/texmf-dist/scripts/context/lua/mtx-check.lua @@ -6,91 +6,99 @@ if not modules then modules = { } end modules ['mtx-check'] = { license = "see context related readme files" } +local helpinfo = [[ +--convert check tex file for errors +]] + +local application = logs.application { + name = "mtx-check", + banner = "Basic ConTeXt Syntax Checking 0.10", + helpinfo = helpinfo, +} + +local report = application.report + scripts = scripts or { } scripts.checker = scripts.checker or { } local validator = { } -do - - validator.n = 1 - validator.errors = { } - validator.trace = false - validator.direct = false +validator.n = 1 +validator.errors = { } +validator.trace = false +validator.direct = false - validator.printer = print - validator.tracer = print +validator.printer = print +validator.tracer = print - local message = function(position, kind) - local ve = validator.errors - ve[#ve+1] = { kind, position, validator.n } - if validator.direct then - validator.printer(string.format("%s error at position %s (line %s)", kind, position, validator.n)) - end +local message = function(position, kind) + local ve = validator.errors + ve[#ve+1] = { kind, position, validator.n } + if validator.direct then + validator.printer(string.format("%s error at position %s (line %s)", kind, position, validator.n)) end - local progress = function(position, data, kind) - if validator.trace then - validator.tracer(string.format("%s at position %s: %s", kind, position, data or "")) - 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 "")) 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("}") - - local okay = lpeg.P("{[}") + lpeg.P("{]}") - - local esc = P("\\") - local cr = P("\r") - local lf = P("\n") - local crlf = P("\r\n") - local space = S(" \t\f\v") - 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 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, - } - - function validator.check(str) - validator.n = 1 - validator.errors = { } - grammar:match(str) - 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("}") + +local okay = lpeg.P("{[}") + lpeg.P("{]}") + +local esc = P("\\") +local cr = P("\r") +local lf = P("\n") +local crlf = P("\r\n") +local space = S(" \t\f\v") +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 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, +} +function validator.check(str) + validator.n = 1 + validator.errors = { } + grammar:match(str) end --~ str = [[ @@ -117,7 +125,7 @@ function scripts.checker.check(filename) ["\t"] = " <tab> ", }) data = data:gsub("^ *","") - print(string.format("% 5i %s %s", line,string.rpadd(kind,10," "),data)) + print(string.format("% 5i %-10s %s", line, kind, data)) end else print("no error") @@ -127,17 +135,13 @@ function scripts.checker.check(filename) end end -logs.extendbanner("Basic ConTeXt Syntax Checking 0.10",true) - -messages.help = [[ ---convert check tex file for errors -]] - if environment.argument("check") then scripts.checker.check(environment.files[1]) elseif environment.argument("help") then - logs.help(messages.help) + application.help() elseif environment.files[1] then scripts.checker.check(environment.files[1]) +else + application.help() end |