summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkiv/trac-deb.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/trac-deb.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/mkiv/trac-deb.lua290
1 files changed, 177 insertions, 113 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/trac-deb.lua b/Master/texmf-dist/tex/context/base/mkiv/trac-deb.lua
index 95f3052fe6f..71055eafac9 100644
--- a/Master/texmf-dist/tex/context/base/mkiv/trac-deb.lua
+++ b/Master/texmf-dist/tex/context/base/mkiv/trac-deb.lua
@@ -6,11 +6,14 @@ if not modules then modules = { } end modules ['trac-deb'] = {
license = "see context related readme files"
}
-local lpeg, status = lpeg, status
+-- This is an old mechanism, a result of some experiments in the early days of
+-- luatex and mkiv, but still nice anyway.
-local lpegmatch = lpeg.match
+local status = status
+
+local tonumber, tostring, type = tonumber, tostring, type
local format, concat, match, find, gsub = string.format, table.concat, string.match, string.find, string.gsub
-local tonumber, tostring = tonumber, tostring
+local lpegmatch = lpeg.match
-- maybe tracers -> tracers.tex (and tracers.lua for current debugger)
@@ -31,11 +34,33 @@ local strings = tracers.strings
local texgetdimen = tex.getdimen
local texgettoks = tex.gettoks
local texgetcount = tex.getcount
+local texgethelp = tex.gethelptext or function() end
+local fatalerror = tex.fatalerror
local implement = interfaces.implement
+-- this is used in lmx files but needs to be redone
+
strings.undefined = "undefined"
+function tracers.dimen(name)
+ local d = texgetdimen(name)
+ return d and number.topoints(d) or strings.undefined
+end
+
+function tracers.count(name)
+ return texgetcount(name) or strings.undefined
+end
+
+function tracers.toks(name,limit)
+ local t = texgettoks(name)
+ return t and string.limit(t,tonumber(limit) or 40) or strings.undefined
+end
+
+function tracers.primitive(name)
+ return tex[name] or strings.undefined
+end
+
lists.scratch = {
0, 2, 4, 6, 8
}
@@ -58,15 +83,15 @@ local types = {
}
local splitboth = lpeg.splitat(":")
-local splittype = lpeg.firstofsplit(":")
-local splitname = lpeg.secondofsplit(":")
function tracers.type(csname)
- return lpegmatch(splittype,csname)
+ local tag, name = lpegmatch(splitboth,csname)
+ return tag or ""
end
function tracers.name(csname)
- return lpegmatch(splitname,csname) or csname
+ local tag, name = lpegmatch(splitboth,csname)
+ return name or csname
end
function tracers.cs(csname)
@@ -78,30 +103,14 @@ function tracers.cs(csname)
end
end
-function tracers.dimen(name)
- local d = texgetdimen(name)
- return d and number.topoints(d) or strings.undefined
-end
-
-function tracers.count(name)
- return texgetcount(name) or strings.undefined
-end
-
-function tracers.toks(name,limit)
- local t = texgettoks(name)
- return t and string.limit(t,tonumber(limit) or 40) or strings.undefined
-end
-
-function tracers.primitive(name)
- return tex[name] or strings.undefined
-end
-
function tracers.knownlist(name)
local l = lists[name]
return l and #l > 0
end
local savedluaerror = nil
+local usescitelexer = nil
+local quitonerror = true
local function errorreporter(luaerror)
local category = luaerror and "lua error" or "tex error"
@@ -121,41 +130,46 @@ function tracers.showlines(filename,linenumber,offset,luaerrorline)
end
end
end
- local lines = data and string.splitlines(data)
- if lines and #lines > 0 then
- if luaerrorline and luaerrorline > 0 then
- -- lua error: linenumber points to last line
- local start = "\\startluacode"
- local stop = "\\stopluacode"
- local n = linenumber
- for i=n,1,-1 do
- local line = lines[i]
- if not line then
- break
- elseif find(line,start) then
- n = i + luaerrorline - 1
- if n <= linenumber then
- linenumber = n
+ local scite = usescitelexer and require("util-sci")
+ if scite then
+ return utilities.scite.tohtml(data,"tex",linenumber or true,false)
+ else
+ local lines = data and string.splitlines(data)
+ if lines and #lines > 0 then
+ if luaerrorline and luaerrorline > 0 then
+ -- lua error: linenumber points to last line
+ local start = "\\startluacode"
+ local stop = "\\stopluacode"
+ local n = linenumber
+ for i=n,1,-1 do
+ local line = lines[i]
+ if not line then
+ break
+ elseif find(line,start) then
+ n = i + luaerrorline - 1
+ if n <= linenumber then
+ linenumber = n
+ end
+ break
end
- break
end
end
- end
- offset = tonumber(offset) or 10
- linenumber = tonumber(linenumber) or 10
- local start = math.max(linenumber - offset,1)
- local stop = math.min(linenumber + offset,#lines)
- if stop > #lines then
- return "<linenumber past end of file>"
- else
- local result, fmt = { }, "%" .. #tostring(stop) .. "d %s %s"
- for n=start,stop do
- result[#result+1] = format(fmt,n,n == linenumber and ">>" or " ",lines[n])
+ offset = tonumber(offset) or 10
+ linenumber = tonumber(linenumber) or 10
+ local start = math.max(linenumber - offset,1)
+ local stop = math.min(linenumber + offset,#lines)
+ if stop > #lines then
+ return "<linenumber past end of file>"
+ else
+ local result, fmt = { }, "%" .. #tostring(stop) .. "d %s %s"
+ for n=start,stop do
+ result[#result+1] = format(fmt,n,n == linenumber and ">>" or " ",lines[n])
+ end
+ return concat(result,"\n")
end
- return concat(result,"\n")
+ else
+ return "<empty file>"
end
- else
- return "<empty file>"
end
end
@@ -169,7 +183,7 @@ end
-- todo: \starttext bla \blank[foo] bla \stoptext
local nop = function() end
-local resetmessages = status.resetmessages() or nop
+local resetmessages = status.resetmessages or nop
local function processerror(offset)
-- print("[[ last tex error: " .. tostring(status.lasterrorstring or "<unset>") .. " ]]")
@@ -178,12 +192,11 @@ local function processerror(offset)
-- print("[[ last location : " .. tostring(status.lastwarninglocation or "<unset>") .. " ]]")
-- print("[[ last context : " .. tostring(status.lasterrorcontext or "<unset>") .. " ]]")
- local inputstack = resolvers.inputstack
- local filename = inputstack[#inputstack] or status.filename
+ local filename = status.filename
local linenumber = tonumber(status.linenumber) or 0
local lastcontext = status.lasterrorcontext
local lasttexerror = status.lasterrorstring or "?"
- local lastluaerror = status.lastluaerrorstring or lasttexerror
+ local lastluaerror = status.lastluaerrorstring or "?" -- lasttexerror
local luaerrorline = match(lastluaerror,[[lua%]?:.-(%d+)]]) or (lastluaerror and find(lastluaerror,"?:0:",1,true) and 0)
local lastmpserror = match(lasttexerror,[[^.-mp%serror:%s*(.*)$]])
resetmessages()
@@ -194,69 +207,108 @@ local function processerror(offset)
offset = tonumber(offset) or 10,
lasttexerror = lasttexerror,
lastmpserror = lastmpserror,
- lastluaerror = lastluaerror,
+ lastluaerror = lastluaerror, -- can be the same as lasttexerror
luaerrorline = luaerrorline,
lastcontext = lastcontext,
+ lasttexhelp = tex.gethelptext and tex.gethelptext() or nil,
}
end
-- so one can overload the printer if (really) needed
+if fatalerror then
+ callback.register("terminal_input",function(what)
+ if what == "*" then
+ fatalerror("some kind of input expected, file ends too soon, quitting now")
+ else
+ fatalerror("bad input, quitting now")
+ end
+ end)
+else
+ -- tex.print("\\nonstopmode")
+end
+
+directives.register("system.quitonerror",function(v)
+ quitonerror = toboolean(v)
+ -- tex.print("\\errorstopmode")
+end)
+
+directives.register("system.usescitelexer",function(v)
+ usescitelexer = toboolean(v)
+end)
+
+local busy = false
+
function tracers.printerror(specification)
- local filename = specification.filename
- local linenumber = specification.linenumber
- local lasttexerror = specification.lasttexerror
- local lastmpserror = specification.lastmpserror
- local lastluaerror = specification.lastluaerror
- local lastcontext = specification.lasterrorcontext
- local luaerrorline = specification.luaerrorline
- local errortype = specification.errortype
- local offset = specification.offset
- local report = errorreporter(luaerrorline)
- if not filename then
- report("error not related to input file: %s ...",lasttexerror)
- elseif type(filename) == "number" then
- report("error on line %s of filehandle %s: %s ...",linenumber,lasttexerror)
- else
- report_nl()
- if luaerrorline then
- if linenumber == 0 or not filename or filename == "" then
- print("\nfatal lua error:\n\n",lastluaerror,"\n")
- os.exit(1)
- return
+ if not busy then
+ busy = true
+ local filename = specification.filename
+ local linenumber = specification.linenumber
+ local lasttexerror = specification.lasttexerror
+ local lastmpserror = specification.lastmpserror
+ local lastluaerror = specification.lastluaerror
+ local lastcontext = specification.lasterrorcontext
+ local luaerrorline = specification.luaerrorline
+ local errortype = specification.errortype
+ local offset = specification.offset
+ local report = errorreporter(luaerrorline)
+ if not filename then
+ report("error not related to input file:")
+ report(" tex: %s",lasttexerror or "-")
+ report(" lua: %s",lastluaerror or "-")
+ report(" mps: %s",lastmpserror or "-")
+ elseif type(filename) == "number" then
+ report("error on line %s of filehandle %s: %s ...",linenumber,lasttexerror)
+ else
+ report_nl()
+ if luaerrorline then
+ if linenumber == 0 or not filename or filename == "" then
+ print("\nfatal lua error:\n\n",lastluaerror,"\n")
+ luatex.abort()
+ return
+ else
+ report("lua error on line %s in file %s:\n\n%s",linenumber,filename,lastluaerror)
+ end
+ elseif lastmpserror then
+ report("mp error on line %s in file %s:\n\n%s",linenumber,filename,lastmpserror)
else
- report("lua error on line %s in file %s:\n\n%s",linenumber,filename,lastluaerror)
+ report("tex error on line %s in file %s: %s",linenumber,filename,lasttexerror)
+ if lastcontext then
+ report_nl()
+ report_str(lastcontext)
+ report_nl()
+ elseif tex.show_context then
+ report_nl()
+ tex.show_context()
+ end
end
- elseif lastmpserror then
- report("mp error on line %s in file %s:\n\n%s",linenumber,filename,lastmpserror)
- else
- report("tex error on line %s in file %s: %s",linenumber,filename,lasttexerror)
- if lastcontext then
+ report_nl()
+ report_str(tracers.showlines(filename,linenumber,offset,tonumber(luaerrorline)))
+ report_nl()
+ end
+ local errname = file.addsuffix(tex.jobname .. "-error","log")
+ if quitonerror then
+ table.save(errname,specification)
+ local help = specification.lasttexhelp
+ if help and #help > 0 then
report_nl()
- report_str(lastcontext)
+ report_str(help)
report_nl()
- elseif tex.show_context then
report_nl()
- tex.show_context()
end
+ luatex.abort()
end
- report_nl()
- report_str(tracers.showlines(filename,linenumber,offset,tonumber(luaerrorline)))
- report_nl()
+ busy = false
end
end
+luatex.wrapup(function() os.remove(file.addsuffix(tex.jobname .. "-error","log")) end)
+
local function processwarning(offset)
- -- local inputstack = resolvers.inputstack
- -- local filename = inputstack[#inputstack] or status.filename
- -- local linenumber = tonumber(status.linenumber) or 0
local lastwarning = status.lastwarningstring or "?"
local lastlocation = status.lastwarningtag or "?"
resetmessages()
tracers.printwarning {
- -- filename = filename,
- -- linenumber = linenumber,
- -- offset = tonumber(offset) or 10,
lastwarning = lastwarning ,
lastlocation = lastlocation,
}
@@ -272,7 +324,7 @@ directives.register("system.errorcontext", function(v)
register('show_error_message', nop)
register('show_warning_message',function() processwarning(v) end)
register('show_error_hook', function() processerror(v) end)
- register('show_lua_error_hook', nop)
+ register('show_lua_error_hook', function() processerror(v) end)
else
register('show_error_message', nil)
register('show_error_hook', nil)
@@ -288,20 +340,27 @@ lmx = lmx or { }
lmx.htmfile = function(name) return environment.jobname .. "-status.html" end
lmx.lmxfile = function(name) return resolvers.findfile(name,'tex') end
+local function reportback(lmxname,default,variables)
+ if lmxname == false then
+ return variables
+ else
+ local name = lmx.show(type(lmxname) == "string" and lmxname or default,variables)
+ if name then
+ logs.report("context report","file: %s",name)
+ end
+ end
+end
+
function lmx.showdebuginfo(lmxname)
local variables = {
['title'] = 'ConTeXt Debug Information',
['color-background-one'] = lmx.get('color-background-green'),
['color-background-two'] = lmx.get('color-background-blue'),
}
- if lmxname == false then
- return variables
- else
- lmx.show(lmxname or 'context-debug.lmx',variables)
- end
+ reportback(lmxname,"context-debug.lmx",variables)
end
-function lmx.showerror(lmxname)
+local function showerror(lmxname)
local filename, linenumber, errorcontext = status.filename, tonumber(status.linenumber) or 0, ""
if not filename then
filename, errorcontext = 'unknown', 'error in filename'
@@ -319,15 +378,18 @@ function lmx.showerror(lmxname)
['filename'] = filename,
['errorcontext'] = errorcontext,
}
- if lmxname == false then
- return variables
- else
- lmx.show(lmxname or 'context-error.lmx',variables)
- end
+ reportback(lmxname,"context-error.lmx",variables)
+ luatex.abort()
end
-function lmx.overloaderror()
- callback.register('show_error_hook', function() lmx.showerror() end) -- prevents arguments being passed
+lmx.showerror = showerror
+
+function lmx.overloaderror(v)
+ if v == "scite" then
+ usescitelexer = true
+ end
+ callback.register('show_error_hook', function() showerror() end) -- prevents arguments being passed
+ callback.register('show_lua_error_hook', function() showerror() end) -- prevents arguments being passed
end
directives.register("system.showerror", lmx.overloaderror)
@@ -367,6 +429,8 @@ directives.register("system.showerror", lmx.overloaderror)
-- end
-- end)
+local implement = interfaces.implement
+
implement { name = "showtrackers", actions = trackers.show }
implement { name = "enabletrackers", actions = trackers.enable, arguments = "string" }
implement { name = "disabletrackers", actions = trackers.disable, arguments = "string" }