diff options
author | Hans Hagen <pragma@wxs.nl> | 2010-08-20 00:00:00 +0200 |
---|---|---|
committer | Hans Hagen <pragma@wxs.nl> | 2010-08-20 00:00:00 +0200 |
commit | bbc8970958af29626335568414a4278d852e086f (patch) | |
tree | cc349c9c7902716090f1e587be04e8cc4546c67b /tex | |
parent | 174663b0081dd76f91c45fd705262a262a7b1f49 (diff) | |
download | context-bbc8970958af29626335568414a4278d852e086f.tar.gz |
beta 2010.08.20 00:00
Diffstat (limited to 'tex')
121 files changed, 1135 insertions, 1304 deletions
diff --git a/tex/context/base/attr-col.lua b/tex/context/base/attr-col.lua index 0f40b8b99..1ff1a07ed 100644 --- a/tex/context/base/attr-col.lua +++ b/tex/context/base/attr-col.lua @@ -318,7 +318,7 @@ function colors.value(id) return values[id] end -attributes.colors.handler = nodes.install_attribute_handler { +attributes.colors.handler = nodes.installattributehandler { name = "color", namespace = colors, initializer = states.initialize, @@ -424,7 +424,7 @@ function transparencies.value(id) return values[id] end -attributes.transparencies.handler = nodes.install_attribute_handler { +attributes.transparencies.handler = nodes.installattributehandler { name = "transparency", namespace = transparencies, initializer = states.initialize, @@ -487,7 +487,7 @@ function colorintents.register(stamp) return registered[stamp] or registered.overprint end -attributes.colorintents.handler = nodes.install_attribute_handler { +attributes.colorintents.handler = nodes.installattributehandler { name = "colorintent", namespace = colorintents, initializer = states.initialize, diff --git a/tex/context/base/attr-eff.lua b/tex/context/base/attr-eff.lua index 2dba1b459..4759ad1fa 100644 --- a/tex/context/base/attr-eff.lua +++ b/tex/context/base/attr-eff.lua @@ -60,7 +60,7 @@ function effects.register(effect,stretch,rulethickness) return n end -attributes.effects.handler = nodes.install_attribute_handler { +attributes.effects.handler = nodes.installattributehandler { name = "effect", namespace = effects, initializer = states.initialize, diff --git a/tex/context/base/attr-lay.lua b/tex/context/base/attr-lay.lua index 80e54df77..dd74698ef 100644 --- a/tex/context/base/attr-lay.lua +++ b/tex/context/base/attr-lay.lua @@ -91,7 +91,7 @@ viewerlayers.register = function(name,lw) -- if not inimode redefine data[n] in return registered[stamp] -- == n end -attributes.viewerlayers.handler = nodes.install_attribute_handler { +attributes.viewerlayers.handler = nodes.installattributehandler { name = "viewerlayer", namespace = viewerlayers, initializer = initializer, diff --git a/tex/context/base/attr-neg.lua b/tex/context/base/attr-neg.lua index ab62fbab5..ba95382ce 100644 --- a/tex/context/base/attr-neg.lua +++ b/tex/context/base/attr-neg.lua @@ -58,7 +58,7 @@ function negatives.register(stamp) return registered[stamp] or registered.positive end -attributes.negatives.handler = nodes.install_attribute_handler { +attributes.negatives.handler = nodes.installattributehandler { name = "negative", namespace = negatives, initializer = states.initialize, diff --git a/tex/context/base/bibl-bib.lua b/tex/context/base/bibl-bib.lua index 3bf005201..8de1ac23a 100644 --- a/tex/context/base/bibl-bib.lua +++ b/tex/context/base/bibl-bib.lua @@ -16,12 +16,14 @@ local utf = unicode.utf8 local lower, format, gsub, concat = string.lower, string.format, string.gsub, table.concat local next = next local utfchar = utf.char -local lpegmatch = lpeg.match +local lpegmatch, lpegpatterns = lpeg.match, lpeg.patterns local textoutf = characters and characters.tex.toutf local variables = interfaces and interfaces.variables local settings_to_hash = utilities.parsers.settings_to_hash local finalizers = xml.finalizers.tex -local xmlfilter, xmltext = xml.filter, xml.text +local xmlfilter, xmltext, getid = xml.filter, xml.text, lxml.getid + +local P, R, S, C, Cc, Cs, Ct = lpeg.P, lpeg.R, lpeg.S, lpeg.C, lpeg.Cc, lpeg.Cs, lpeg.Ct local trace_bibxml = false trackers.register("publications.bibxml", function(v) trace_bibtex = v end) @@ -30,9 +32,12 @@ local report_publications = logs.new("publications") bibtex = bibtex or { } local bibtex = bibtex -bibtex.size = 0 -bibtex.definitions = 0 -bibtex.shortcuts = 0 +bibtex.statistics = bibtex.statistics or { } +local bibtexstats = bibtex.statistics + +bibtexstats.nofbytes = 0 +bibtexstats.nofdefinitions = 0 +bibtexstats.nofshortcuts = 0 local defaultshortcuts = { jan = "1", @@ -58,7 +63,7 @@ local entries -- hashed again. local function do_shortcut(tag,key,value) - bibtex.shortcuts = bibtex.shortcuts + 1 + bibtexstats.nofshortcuts = bibtexstats.nofshortcuts + 1 if lower(tag) == "@string" then shortcuts[key] = value end @@ -66,7 +71,7 @@ end local function do_definition(tag,key,tab) -- maybe check entries here (saves memory) if not entries or entries[key] then - bibtex.definitions = bibtex.definitions + 1 + bibtexstats.nofdefinitions = bibtexstats.nofdefinitions + 1 local t = { } for i=1,#tab,2 do t[tab[i]] = tab[i+1] @@ -84,8 +89,6 @@ local function resolve(s) return shortcuts[s] or defaultshortcuts[s] or s -- can be number end -local P, R, S, C, Cc, Cs, Ct = lpeg.P, lpeg.R, lpeg.S, lpeg.C, lpeg.Cc, lpeg.Cs, lpeg.Ct - local percent = P("%") local start = P("@") local comma = P(",") @@ -104,10 +107,10 @@ local collapsed = (space^1)/ " " local function add(a,b) if b then return a..b else return a end end -local keyword = C((R("az","AZ","09") + S("@_:-"))^1) -- lpeg.C((1-space)^1) +local keyword = C((R("az","AZ","09") + S("@_:-"))^1) -- C((1-space)^1) local s_quoted = ((escape*single) + collapsed + (1-single))^0 local d_quoted = ((escape*double) + collapsed + (1-double))^0 -local balanced = lpeg.patterns.balanced +local balanced = lpegpatterns.balanced local s_value = (single/"") * s_quoted * (single/"") local d_value = (double/"") * d_quoted * (double/"") @@ -119,7 +122,7 @@ local value = Cs((somevalue * ((spacing * hash * spacing)/"" * somevalue)^0 local assignment = spacing * keyword * spacing * equal * spacing * value * spacing local shortcut = keyword * spacing * left * spacing * (assignment * comma^0)^0 * spacing * right -local definition = keyword * spacing * left * spacing * keyword * comma * lpeg.Ct((assignment * comma^0)^0) * spacing * right +local definition = keyword * spacing * left * spacing * keyword * comma * Ct((assignment * comma^0)^0) * spacing * right local comment = keyword * spacing * left * (1-right)^0 * spacing * right local forget = percent^1 * (1-lineending)^0 @@ -130,9 +133,8 @@ local grammar = (space + forget + shortcut/do_shortcut + definition/do_definitio function bibtex.convert(session,content) statistics.starttiming(bibtex) data, shortcuts, entries = session.data, session.shortcuts, session.entries - -- session.size = session.size + #content - bibtex.size = bibtex.size + #content - session.size = session.size + #content + bibtexstats.nofbytes = bibtexstats.nofbytes + #content + session.nofbytes = session.nofbytes + #content lpegmatch(grammar,content or "") statistics.stoptiming(bibtex) end @@ -152,16 +154,16 @@ end function bibtex.new() return { - data = { }, + data = { }, shortcuts = { }, - xml = xml.convert("<?xml version='1.0' standalone='yes'?>\n<bibtex></bibtex>"), - size = 0, - entries = nil, - loaded = false, + xml = xml.convert("<?xml version='1.0' standalone='yes'?>\n<bibtex></bibtex>"), + nofbytes = 0, + entries = nil, + loaded = false, } end -local escaped_pattern = xml.escaped_pattern +local escaped_pattern = lpegpatterns.xml.escaped local ihatethis = { f = "\\f", @@ -243,10 +245,10 @@ function bibtex.toxml(session,options) end statistics.register("bibtex load time", function() - local size = bibtex.size - if size > 0 then + local nofbytes = bibtexstats.nofbytes + if nofbytes > 0 then return format("%s seconds (%s bytes, %s definitions, %s shortcuts)", - statistics.elapsedtime(bibtex),size,bibtex.definitions,bibtex.shortcuts) + statistics.elapsedtime(bibtex),nofbytes,bibtexstats.nofdefinitions,bibtexstats.nofshortcuts) else return nil end @@ -267,14 +269,14 @@ end) --~ local session = bibtex.new() --~ bibtex.convert(session,str) --~ bibtex.toxml(session) ---~ print(session.size,statistics.elapsedtime(bibtex)) +--~ print(session.nofbytes,statistics.elapsedtime(bibtex)) --~ local session = bibtex.new() --~ bibtex.load(session,"IEEEabrv.bib") --~ bibtex.load(session,"IEEEfull.bib") --~ bibtex.load(session,"IEEEexample.bib") --~ bibtex.toxml(session) ---~ print(session.size,statistics.elapsedtime(bibtex)) +--~ print(session.nofbytes,statistics.elapsedtime(bibtex)) --~ local session = bibtex.new() --~ bibtex.load(session,"gut.bib") @@ -287,7 +289,7 @@ end) --~ bibtex.load(session,"texnique.bib") --~ bibtex.load(session,"tugboat.bib") --~ bibtex.toxml(session) ---~ print(session.size,statistics.elapsedtime(bibtex)) +--~ print(session.nofbytes,statistics.elapsedtime(bibtex)) --~ print(table.serialize(session.data)) --~ print(table.serialize(session.shortcuts)) @@ -298,14 +300,16 @@ if not characters then dofile(resolvers.find_file("char-def.lua")) end local chardata = characters.data local concat = table.concat -local P, Ct, lpegmatch = lpeg.P, lpeg.Ct, lpeg.match +local lpeg = lpeg + +local P, Ct, lpegmatch, lpegpatterns = lpeg.P, lpeg.Ct, lpeg.match, lpeg.patterns local space, comma = P(" "), P(",") local andsplitter = Ct(lpeg.splitat(space^1 * "and" * space^1)) local commasplitter = Ct(lpeg.splitat(space^0 * comma * space^0)) local spacesplitter = Ct(lpeg.splitat(space^1)) -local firstcharacter = lpeg.patterns.utf8byte +local firstcharacter = lpegpatterns.utf8byte local function is_upper(str) local first = lpegmatch(firstcharacter,str) @@ -582,7 +586,7 @@ end local function collectauthoryears(id,list) list = settings_to_hash(list) - id = lxml.get_id(id) + id = getid(id) local found = { } for e in xml.collected(id,"/bibtex/entry") do if list[e.at.tag] then @@ -732,7 +736,7 @@ if commands then end end - function bibtex.singular_or_plural(singular,plural) + function bibtex.singularorplural(singular,plural) if lastconcatsize and lastconcatsize > 1 then texsprint(ctxcatcodes,plural) else diff --git a/tex/context/base/bibl-bib.mkiv b/tex/context/base/bibl-bib.mkiv index 6f2863fd8..0ac60cfe1 100644 --- a/tex/context/base/bibl-bib.mkiv +++ b/tex/context/base/bibl-bib.mkiv @@ -118,9 +118,9 @@ \newtoks \everysetupbibtexsession \setfalse \tracebibtexformat -\unexpanded\def\definebibtexsession {\dosingleargument\dodefinebibtexsession} +\unexpanded\def\definebibtexsession{\dosingleargument\dodefinebibtexsession} \def\preparebibtexsession {\dodoubleempty \dopreparebibtexsession} -\unexpanded\def\setupbibtexsession {\dodoubleargument\dosetupbibtexsession} +\unexpanded\def\setupbibtexsession {\dodoubleargument\dosetupbibtexsession} \def\dodefinebibtexsession [#1]{\edef\currentbibtexsession{#1}% \ctxlua{commands.definebibtexsession("#1")}% @@ -956,7 +956,7 @@ \def\dodobibtexauthoryearref #1{\ctxlua{bibtex.authoryearref ("bibtex:\currentbibtexsession","#1","normal","author")}} \def\dodobibtexauthoryearsref#1{\ctxlua{bibtex.authoryearsref("bibtex:\currentbibtexsession","#1","normal","author")}} -\unexpanded\def\bibtexsingularplural#1#2{\ctxlua{bibtex.singular_or_plural(\!!bs#1\!!es,\!!bs#2\!!es)}} +\unexpanded\def\bibtexsingularplural#1#2{\ctxlua{bibtex.singularorplural(\!!bs#1\!!es,\!!bs#2\!!es)}} \protect \endinput diff --git a/tex/context/base/buff-ini.lua b/tex/context/base/buff-ini.lua index 70d187f1a..2baae18b0 100644 --- a/tex/context/base/buff-ini.lua +++ b/tex/context/base/buff-ini.lua @@ -869,3 +869,9 @@ end --~ str = [[test 123 test $oeps$]] --~ lpegmatch(pattern,str) + +buffers.obsolete = buffers.obsolete or { } +local obsolete = buffers.obsolete + +buffers.finish_state = buffers.finishstate obsolete.finish_state = buffers.finishstate +buffers.change_state = buffers.finishstate obsolete.change_state = buffers.finishstate diff --git a/tex/context/base/char-ini.lua b/tex/context/base/char-ini.lua index 99afe6ec4..a24de6e23 100644 --- a/tex/context/base/char-ini.lua +++ b/tex/context/base/char-ini.lua @@ -333,13 +333,7 @@ characters.bidi = { on = "Other Neutrals", } -local _empty_table_ = { __index = function(t,k) return "" end } - -function table.set_empty_metatable(t) - setmetatable(t,_empty_table_) -end - -table.set_empty_metatable(data) +table.setemptymetatable(data) -- so each key resolves to "" --[[ldx-- <p>At this point we assume that the big data table is loaded. From this @@ -617,7 +611,7 @@ function characters.remapentity(chr,slot) texsprint(format("{\\catcode%s=13\\xdef%s{\\string%s}}",slot,utfchar(slot),chr)) end -characters.active_offset = 0x10000 -- there will be remapped in that byte range +characters.activeoffset = 0x10000 -- there will be remapped in that byte range -- xml.entities = xml.entities or { } -- @@ -632,9 +626,9 @@ characters.active_offset = 0x10000 -- there will be remapped in that byte range -- -- function characters.setmkiientities() -- local entities = xml.entities --- entities.lt = utfchar(characters.active_offset + utfbyte("<")) --- entities.amp = utfchar(characters.active_offset + utfbyte("&")) --- entities.gt = utfchar(characters.active_offset + utfbyte(">")) +-- entities.lt = utfchar(characters.activeoffset + utfbyte("<")) +-- entities.amp = utfchar(characters.activeoffset + utfbyte("&")) +-- entities.gt = utfchar(characters.activeoffset + utfbyte(">")) -- end -- some day we will make a table diff --git a/tex/context/base/char-utf.lua b/tex/context/base/char-utf.lua index 71e2805ad..680d426b0 100644 --- a/tex/context/base/char-utf.lua +++ b/tex/context/base/char-utf.lua @@ -21,7 +21,7 @@ over a string.</p> local utf = unicode.utf8 local utfchar, utfbyte, utfgsub = utf.char, utf.byte, utf.gsub -local concat, gmatch = table.concat, string.gmatch +local concat, gmatch, gsub = table.concat, string.gmatch, string.gsub local utfcharacters, utfvalues = string.utfcharacters, string.utfvalues local ctxcatcodes = tex.ctxcatcodes local texsprint = tex.sprint @@ -152,9 +152,9 @@ end private.set = set +function private.escape (str) return gsub(str,"(.)", escapes) end function private.replace(str) return utfgsub(str,"(.)", low ) end -function private.revert(str) return utfgsub(str,"(.)", high ) end -function private.escape(str) return utfgsub(str,"(.)", escapes) end +function private.revert (str) return utfgsub(str,"(.)", high ) end for ch in gmatch(special,".") do set(ch) end diff --git a/tex/context/base/cont-new.mkiv b/tex/context/base/cont-new.mkiv index 81baf2923..e400dfaa0 100644 --- a/tex/context/base/cont-new.mkiv +++ b/tex/context/base/cont-new.mkiv @@ -37,7 +37,7 @@ \let\\=\crlf -% for a while +% for a while as these can be used in user modules \startluacode jobregisters = logs.obsolete("jobregisters", "structures.registers") diff --git a/tex/context/base/cont-new.tex b/tex/context/base/cont-new.tex index b9f8747dd..8c0852955 100644 --- a/tex/context/base/cont-new.tex +++ b/tex/context/base/cont-new.tex @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2010.08.19 01:08} +\newcontextversion{2010.08.20 00:00} %D This file is loaded at runtime, thereby providing an %D excellent place for hacks, patches, extensions and new diff --git a/tex/context/base/context.mkiv b/tex/context/base/context.mkiv index 1cf1aeacc..c8271fcb1 100644 --- a/tex/context/base/context.mkiv +++ b/tex/context/base/context.mkiv @@ -377,10 +377,7 @@ \to \everyjob \appendtoks - \ctxlua { - statistics.report_storage("log") - statistics.save_fmt_status("\jobname","\contextversion","context.tex") - }% + \ctxlua{statistics.savefmtstatus("\jobname","\contextversion","context.tex")}% can become automatic \to \everydump \protect \errorstopmode \dump \endinput diff --git a/tex/context/base/context.tex b/tex/context/base/context.tex index 27eb2b55e..351667d9d 100644 --- a/tex/context/base/context.tex +++ b/tex/context/base/context.tex @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2010.08.19 01:08} +\edef\contextversion{2010.08.20 00:00} %D For those who want to use this: diff --git a/tex/context/base/core-uti.lua b/tex/context/base/core-uti.lua index 538feb959..c8dc0f73d 100644 --- a/tex/context/base/core-uti.lua +++ b/tex/context/base/core-uti.lua @@ -48,7 +48,7 @@ job.comment(format("version: %1.2f",jobs.version)) function job.initialize(loadname,savename) job.load(loadname) -- has to come after structure is defined ! - luatex.register_stop_actions(function() + luatex.registerstopactions(function() if not status.lasterrorstring or status.lasterrorstring == "" then job.save(savename) end @@ -113,10 +113,10 @@ local jobpacker = packers.new(packlist,1.01) job.pack = true -job._save_, job._load_ = { }, { } -- registers timing +local _save_, _load_ = { }, { } -- registers timing function job.save(filename) - statistics.starttiming(job._save_) + statistics.starttiming(_save_) local f = io.open(filename,'w') if f then for c=1,#comment do @@ -141,11 +141,11 @@ function job.save(filename) end f:close() end - statistics.stoptiming(job._save_) + statistics.stoptiming(_save_) end function job.load(filename) - statistics.starttiming(job._load_) + statistics.starttiming(_load_) local data = io.loaddata(filename) if data and data ~= "" then local version = tonumber(match(data,"^-- version: ([%d%.]+)")) @@ -167,7 +167,7 @@ function job.load(filename) job.packed = nil end end - statistics.stoptiming(job._load_) + statistics.stoptiming(_load_) end -- eventually this will end up in strc-ini @@ -177,8 +177,8 @@ statistics.register("startup time", function() end) statistics.register("jobdata time",function() - if statistics.elapsedindeed(job._save_) or statistics.elapsedindeed(job._load_) then - return format("%s seconds saving, %s seconds loading", statistics.elapsedtime(job._save_), statistics.elapsedtime(job._load_)) + if statistics.elapsedindeed(_save_) or statistics.elapsedindeed(_load_) then + return format("%s seconds saving, %s seconds loading", statistics.elapsedtime(_save_), statistics.elapsedtime(_load_)) end end) diff --git a/tex/context/base/data-con.lua b/tex/context/base/data-con.lua index a38440fbf..05f1b07de 100644 --- a/tex/context/base/data-con.lua +++ b/tex/context/base/data-con.lua @@ -80,7 +80,7 @@ function containers.define(category, subcategory, version, enabled) end function containers.is_usable(container, name) - return container.enabled and caches and caches.iswritable(container.writable, name) + return container.enabled and caches and caches.is_writable(container.writable, name) end function containers.is_valid(container, name) diff --git a/tex/context/base/data-ini.lua b/tex/context/base/data-ini.lua index 80a01c588..63329b6e2 100644 --- a/tex/context/base/data-ini.lua +++ b/tex/context/base/data-ini.lua @@ -87,7 +87,7 @@ end do - local args = environment.original_arguments or arg -- this needs a cleanup + local args = environment.originalarguments or arg -- this needs a cleanup local ownbin = environment.ownbin or args[-2] or arg[-2] or args[-1] or arg[-1] or arg[0] or "luatex" local ownpath = environment.ownpath or os.selfdir diff --git a/tex/context/base/data-lua.lua b/tex/context/base/data-lua.lua index 754dbddb5..f163361fe 100644 --- a/tex/context/base/data-lua.lua +++ b/tex/context/base/data-lua.lua @@ -51,11 +51,11 @@ end local p_libpaths, a_libpaths = { }, { } -function package.append_libpath(...) +function package.appendtolibpath(...) insert(a_libpath,thepath(...)) end -function package.prepend_libpath(...) +function package.prependtolibpath(...) insert(p_libpaths,1,thepath(...)) end @@ -154,3 +154,13 @@ package.loaders[2] = function(name) -- was [#package.loaders+1] end resolvers.loadlualib = require + +-- -- -- -- + +package.obsolete = package.obsolete or { } + +package.append_libpath = appendtolibpath -- will become obsolete +package.prepend_libpath = prependtolibpath -- will become obsolete + +package.obsolete.append_libpath = appendtolibpath -- will become obsolete +package.obsolete.prepend_libpath = prependtolibpath -- will become obsolete diff --git a/tex/context/base/data-tmp.lua b/tex/context/base/data-tmp.lua index ebb5c3e5e..aeca105a0 100644 --- a/tex/context/base/data-tmp.lua +++ b/tex/context/base/data-tmp.lua @@ -60,18 +60,18 @@ local function identify() cachepath = file.collapse_path(cachepath) local valid = isdir(cachepath) if valid then - if file.isreadable(cachepath) then + if file.is_readable(cachepath) then readables[#readables+1] = cachepath - if not writable and file.iswritable(cachepath) then + if not writable and file.is_writable(cachepath) then writable = cachepath end end elseif not writable and caches.force then local cacheparent = file.dirname(cachepath) - if file.iswritable(cacheparent) then + if file.is_writable(cacheparent) then if not caches.ask or io.ask(format("\nShould I create the cache path %s?",cachepath), "no", { "yes", "no" }) == "yes" then mkdirs(cachepath) - if isdir(cachepath) and file.iswritable(cachepath) then + if isdir(cachepath) and file.is_writable(cachepath) then report_cache("created: %s",cachepath) writable = cachepath readables[#readables+1] = cachepath @@ -92,8 +92,8 @@ local function identify() if cachepath ~= "" then cachepath = resolvers.clean_path(cachepath) local valid = isdir(cachepath) - if valid and file.isreadable(cachepath) then - if not writable and file.iswritable(cachepath) then + if valid and file.is_readable(cachepath) then + if not writable and file.is_writable(cachepath) then readables[#readables+1] = cachepath writable = cachepath break @@ -112,7 +112,7 @@ local function identify() os.exit() end -- why here - writable = dir.expand_name(resolvers.clean_path(writable)) -- just in case + writable = dir.expandname(resolvers.clean_path(writable)) -- just in case -- moved here local base, more, tree = caches.base, caches.more, caches.tree or caches.treehash() -- we have only one writable tree if tree then @@ -219,7 +219,7 @@ function caches.getfirstreadablefile(filename,...) for i=1,#rd do local path = rd[i] local fullname = file.join(path,filename) - if file.isreadable(fullname) then + if file.is_readable(fullname) then usedreadables[i] = true return fullname, path end @@ -260,9 +260,9 @@ function caches.loaddata(readables,name) return false end -function caches.iswritable(filepath,filename) +function caches.is_writable(filepath,filename) local tmaname, tmcname = caches.setluanames(filepath,filename) - return file.iswritable(tmaname) + return file.is_writable(tmaname) end function caches.savedata(filepath,filename,data,raw) diff --git a/tex/context/base/data-use.lua b/tex/context/base/data-use.lua index 3d2dbe190..75f2ebff2 100644 --- a/tex/context/base/data-use.lua +++ b/tex/context/base/data-use.lua @@ -56,7 +56,7 @@ statistics.register("used cache path", function() return caches.usedpaths() end -- experiment (code will move) -function statistics.save_fmt_status(texname,formatbanner,sourcefile) -- texname == formatname +function statistics.savefmtstatus(texname,formatbanner,sourcefile) -- texname == formatname local enginebanner = status.list().banner if formatbanner and enginebanner and sourcefile then local luvname = file.replacesuffix(texname,"luv") @@ -70,7 +70,7 @@ function statistics.save_fmt_status(texname,formatbanner,sourcefile) -- texname end end -function statistics.check_fmt_status(texname) +function statistics.checkfmtstatus(texname) local enginebanner = status.list().banner if enginebanner and texname then local luvname = file.replacesuffix(texname,"luv") diff --git a/tex/context/base/font-afm.lua b/tex/context/base/font-afm.lua index e29363c11..8a9fabed1 100644 --- a/tex/context/base/font-afm.lua +++ b/tex/context/base/font-afm.lua @@ -210,7 +210,7 @@ local function get_indexes(data,pfbname) end end -function afm.read_afm(filename) +local function readafm(filename) local ok, afmblob, size = resolvers.loadbinfile(filename) -- has logging -- local ok, afmblob = true, file.readdata(filename) if ok and afmblob then @@ -284,7 +284,7 @@ function afm.load(filename) if not data or data.verbose ~= fonts.verbose or data.size ~= size or data.time ~= time or data.pfbsize ~= pfbsize or data.pfbtime ~= pfbtime then report_afm( "reading %s",filename) - data = afm.read_afm(filename) + data = readafm(filename) if data then -- data.luatex = data.luatex or { } if pfbname ~= "" then @@ -482,7 +482,7 @@ end fonts.formats.afm = "type1" fonts.formats.pfb = "type1" -function afm.copy_to_tfm(data) +local function copytotfm(data) if data then local glyphs = data.glyphs if glyphs then @@ -610,7 +610,7 @@ end afmfeatures.register = register_feature -function afm.set_features(tfmdata) +local function setfeatures(tfmdata) local shared = tfmdata.shared local afmdata = shared.afmdata local features = shared.features @@ -670,7 +670,7 @@ function afm.set_features(tfmdata) end end -function afm.check_features(specification) +local function checkfeatures(specification) local features, done = fonts.define.check(specification.features.normal,afmfeatures.default) if done then specification.features.normal = features @@ -678,7 +678,7 @@ function afm.check_features(specification) end end -function afm.afm_to_tfm(specification) +local function afmtotfm(specification) local afmname = specification.filename or specification.name if specification.forced == "afm" or specification.format == "afm" then -- move this one up if trace_loading then @@ -696,7 +696,7 @@ function afm.afm_to_tfm(specification) if afmname == "" then return nil else - afm.check_features(specification) + checkfeatures(specification) specification = fonts.define.resolve(specification) -- new, was forgotten local features = specification.features.normal local cache_id = specification.hash @@ -705,14 +705,14 @@ function afm.afm_to_tfm(specification) local afmdata = afm.load(afmname) if afmdata and next(afmdata) then add_dimensions(afmdata) - tfmdata = afm.copy_to_tfm(afmdata) + tfmdata = copytotfm(afmdata) if tfmdata and next(tfmdata) then local shared = tfmdata.shared local unique = tfmdata.unique if not shared then shared = { } tfmdata.shared = shared end if not unique then unique = { } tfmdata.unique = unique end shared.afmdata, shared.features = afmdata, features - afm.set_features(tfmdata) + setfeatures(tfmdata) end elseif trace_loading then report_afm("no (valid) afm file found with name %s",afmname) @@ -750,7 +750,7 @@ function tfm.set_normal_feature(specification,name,value) end function tfm.read_from_afm(specification) - local tfmtable = afm.afm_to_tfm(specification) + local tfmtable = afmtotfm(specification) if tfmtable then tfmtable.name = specification.name tfmtable = tfm.scale(tfmtable, specification.size, specification.relativeid) @@ -820,9 +820,6 @@ local function prepare_kerns(tfmdata,kerns,value) end end -afmfeatures.prepare_kerns = prepare_kerns -afmfeatures.prepare_ligatures = prepare_ligatures - -- hm, register? local base_initializers = fonts.initializers.base.afm diff --git a/tex/context/base/font-ctx.lua b/tex/context/base/font-ctx.lua index 727142db2..f95d78668 100644 --- a/tex/context/base/font-ctx.lua +++ b/tex/context/base/font-ctx.lua @@ -601,7 +601,7 @@ fonts.map.reset() -- resets the default file local nounicode = byte("?") -local function name_to_slot(name) -- maybe some day rawdata +local function nametoslot(name) -- maybe some day rawdata local tfmdata = fonts.ids[font.current()] local shared = tfmdata and tfmdata.shared local fntdata = shared and shared.otfdata or shared.afmdata @@ -618,11 +618,11 @@ local function name_to_slot(name) -- maybe some day rawdata return nounicode end -fonts.name_to_slot = name_to_slot +fonts.nametoslot = nametoslot function fonts.char(n) -- todo: afm en tfm if type(n) == "string" then - n = name_to_slot(n) + n = nametoslot(n) end if type(n) == "number" then texsprint(ctxcatcodes,format("\\char%s ",n)) @@ -631,15 +631,15 @@ end -- this will become obsolete: -fonts.otf.name_to_slot = name_to_slot -fonts.afm.name_to_slot = name_to_slot +fonts.otf.nametoslot = nametoslot +fonts.afm.nametoslot = nametoslot fonts.otf.char = fonts.char fonts.afm.char = fonts.char -- this will change ... -function fonts.show_char_data(n) +function fonts.showchardata(n) local tfmdata = fonts.ids[font.current()] if tfmdata then if type(n) == "string" then @@ -652,7 +652,7 @@ function fonts.show_char_data(n) end end -function fonts.show_font_parameters() +function fonts.showfontparameters() local tfmdata = fonts.ids[font.current()] if tfmdata then local parameters, mathconstants = tfmdata.parameters, tfmdata.MathConstants @@ -699,7 +699,7 @@ function fonts.report_defined_fonts() end end -luatex.register_stop_actions(fonts.report_defined_fonts) +luatex.registerstopactions(fonts.report_defined_fonts) function fonts.report_used_features() -- numbers, setups, merged @@ -722,4 +722,4 @@ function fonts.report_used_features() end end end -luatex.register_stop_actions(fonts.report_used_features) +luatex.registerstopactions(fonts.report_used_features) diff --git a/tex/context/base/font-dum.lua b/tex/context/base/font-dum.lua index 0a9bcd301..bac4f51af 100644 --- a/tex/context/base/font-dum.lua +++ b/tex/context/base/font-dum.lua @@ -263,7 +263,7 @@ end -- bonus -function fonts.otf.name_to_slot(name) +function fonts.otf.nametoslot(name) local tfmdata = fonts.ids[font.current()] if tfmdata and tfmdata.shared then local otfdata = tfmdata.shared.otfdata @@ -274,7 +274,7 @@ end function fonts.otf.char(n) if type(n) == "string" then - n = fonts.otf.name_to_slot(n) + n = fonts.otf.nametoslot(n) end if type(n) == "number" then tex.sprint("\\char" .. n) diff --git a/tex/context/base/font-enh.lua b/tex/context/base/font-enh.lua index 7a585a7d1..27e4e8b75 100644 --- a/tex/context/base/font-enh.lua +++ b/tex/context/base/font-enh.lua @@ -62,10 +62,10 @@ function tfm.enhance(tfmdata,specification) features.encoding = encoding end end - tfm.set_features(tfmdata) + tfm.setfeatures(tfmdata) end -function tfm.set_features(tfmdata) +function tfm.setfeatures(tfmdata) -- todo: no local functions local shared = tfmdata.shared -- local tfmdata = shared.tfmdata diff --git a/tex/context/base/font-gds.lua b/tex/context/base/font-gds.lua index f25458110..80dc0ca55 100644 --- a/tex/context/base/font-gds.lua +++ b/tex/context/base/font-gds.lua @@ -79,7 +79,7 @@ fontgoodies.get = getgoodies local preset_context = fonts.define.specify.preset_context -local function set_goodies(tfmdata,value) +local function setgoodies(tfmdata,value) local goodies = tfmdata.goodies or { } -- future versions might store goodies in the cached instance for filename in gmatch(value,"[^, ]+") do -- we need to check for duplicates @@ -95,13 +95,13 @@ end -- featuresets -local function flattened_features(t,tt) +local function flattenedfeatures(t,tt) -- first set value dominates local tt = tt or { } for i=1,#t do local ti = t[i] if type(ti) == "table" then - flattened_features(ti,tt) + flattenedfeatures(ti,tt) elseif tt[ti] == nil then tt[ti] = true end @@ -109,7 +109,7 @@ local function flattened_features(t,tt) for k, v in next, t do if type(k) ~= "number" then -- not tonumber(k) if type(v) == "table" then - flattened_features(v,tt) + flattenedfeatures(v,tt) elseif tt[k] == nil then tt[k] = v end @@ -118,11 +118,11 @@ local function flattened_features(t,tt) return tt end -fonts.flattened_features = flattened_features +fonts.flattenedfeatures = flattenedfeatures function fontgoodies.prepare_features(goodies,name,set) if set then - local ff = flattened_features(set) + local ff = flattenedfeatures(set) local fullname = goodies.name .. "::" .. name local n, s = preset_context(fullname,"",ff) goodies.featuresets[name] = s -- set @@ -148,7 +148,7 @@ end fontgoodies.register("featureset",initialize) -local function set_featureset(tfmdata,set) +local function setfeatureset(tfmdata,set) local goodies = tfmdata.goodies -- shared ? if goodies then local features = tfmdata.shared.features @@ -259,11 +259,11 @@ table.insert(fonts.triggers, "colorscheme") local base_initializers = fonts.initializers.base.otf local node_initializers = fonts.initializers.node.otf -base_initializers.goodies = set_goodies -node_initializers.goodies = set_goodies +base_initializers.goodies = setgoodies +node_initializers.goodies = setgoodies -base_initializers.featureset = set_featureset -node_initializers.featureset = set_featureset +base_initializers.featureset = setfeatureset +node_initializers.featureset = setfeatureset base_initializers.colorscheme = set_colorscheme node_initializers.colorscheme = set_colorscheme @@ -278,7 +278,7 @@ local function initialize(goodies) local maplines = mathgoodies and mathgoodies.maplines if virtuals then for name, specification in next, virtuals do - mathematics.make_font(name,specification) + mathematics.makefont(name,specification) end end if mapfiles then diff --git a/tex/context/base/font-ini.mkiv b/tex/context/base/font-ini.mkiv index ef2eadbcb..4b813d7f6 100644 --- a/tex/context/base/font-ini.mkiv +++ b/tex/context/base/font-ini.mkiv @@ -3962,8 +3962,8 @@ %D goodies: -\def\showchardata#1{\ctxlua{fonts.show_char_data("#1")}} -\def\showfontdata {\ctxlua{fonts.show_font_parameters()}} +\def\showchardata#1{\ctxlua{fonts.showchardata("#1")}} +\def\showfontdata {\ctxlua{fonts.showfontparameters()}} %D some low level helpers %D diff --git a/tex/context/base/font-otb.lua b/tex/context/base/font-otb.lua index 7c9a28e38..ea46ebdbc 100644 --- a/tex/context/base/font-otb.lua +++ b/tex/context/base/font-otb.lua @@ -263,7 +263,7 @@ local function prepare_base_substitutions(tfmdata,kind,value) -- we can share so end end -local function prepare_base_kerns(tfmdata,kind,value) -- todo what kind of kerns, currently all +local function preparebasekerns(tfmdata,kind,value) -- todo what kind of kerns, currently all if value then local otfdata = tfmdata.shared.otfdata local validlookups, lookuplist = otf.collect_lookups(otfdata,kind,tfmdata.script,tfmdata.language) @@ -333,10 +333,10 @@ local supported_gpos = { 'kern' } -function otf.features.register_base_substitution(tag) +function otf.features.registerbasesubstitution(tag) supported_gsub[#supported_gsub+1] = tag end -function otf.features.register_base_kern(tag) +function otf.features.registerbasekern(tag) supported_gsub[#supported_gpos+1] = tag end @@ -360,7 +360,7 @@ function fonts.initializers.base.otf.features(tfmdata,value) for f=1,#supported_gpos do local feature = supported_gpos[f] local value = features[feature] - prepare_base_kerns(tfmdata,feature,features[feature]) + preparebasekerns(tfmdata,feature,features[feature]) if value then h[#h+1] = feature .. "=" .. tostring(value) end diff --git a/tex/context/base/font-otc.lua b/tex/context/base/font-otc.lua index b57b5b880..3280d8161 100644 --- a/tex/context/base/font-otc.lua +++ b/tex/context/base/font-otc.lua @@ -201,11 +201,11 @@ features['tlig'] = 'TeX Ligatures' features['trep'] = 'TeX Replacements' features['anum'] = 'Arabic Digits' -local register_base_substitution = otf.features.register_base_substitution +local registerbasesubstitution = otf.features.registerbasesubstitution -register_base_substitution('tlig') -register_base_substitution('trep') -register_base_substitution('anum') +registerbasesubstitution('tlig') +registerbasesubstitution('trep') +registerbasesubstitution('anum') -- the functionality is defined elsewhere diff --git a/tex/context/base/font-otd.lua b/tex/context/base/font-otd.lua index 8e770a128..f23ef8eb4 100644 --- a/tex/context/base/font-otd.lua +++ b/tex/context/base/font-otd.lua @@ -20,10 +20,12 @@ otf.features.default = otf.features.default or { } local context_setups = fonts.define.specify.context_setups local context_numbers = fonts.define.specify.context_numbers +-- todo: dynamics namespace + local a_to_script = { } otf.a_to_script = a_to_script local a_to_language = { } otf.a_to_language = a_to_language -function otf.set_dynamics(font,dynamics,attribute) +function otf.setdynamics(font,dynamics,attribute) local features = context_setups[context_numbers[attribute]] -- can be moved to caller if features then local script = features.script or 'dflt' @@ -62,7 +64,7 @@ function otf.set_dynamics(font,dynamics,attribute) tfmdata.shared.features = { } -- end of save local set = fonts.define.check(features,otf.features.default) - dsla = otf.set_features(tfmdata,set) + dsla = otf.setfeatures(tfmdata,set) if trace_dynamics then report_otf("setting dynamics %s: attribute %s, script %s, language %s, set: %s",context_numbers[attribute],attribute,script,language,table.sequenced(set)) end diff --git a/tex/context/base/font-otf.lua b/tex/context/base/font-otf.lua index 9134f95be..cda1cfdd2 100644 --- a/tex/context/base/font-otf.lua +++ b/tex/context/base/font-otf.lua @@ -1390,7 +1390,7 @@ local lists = { -- why local fonts.manipulators, } -function otf.set_features(tfmdata,features) +function otf.setfeatures(tfmdata,features) local processes = { } if features and next(features) then local mode = tfmdata.mode or features.mode or "base" @@ -1452,52 +1452,6 @@ tfmdata.mode = mode return processes, features end -function otf.otf_to_tfm(specification) - local name = specification.name - local sub = specification.sub - local filename = specification.filename - local format = specification.format - local features = specification.features.normal - local cache_id = specification.hash - local tfmdata = containers.read(tfm.cache,cache_id) ---~ print(cache_id) - if not tfmdata then - local otfdata = otf.load(filename,format,sub,features and features.featurefile) - if otfdata and next(otfdata) then - otfdata.shared = otfdata.shared or { - featuredata = { }, - anchorhash = { }, - initialized = false, - } - tfmdata = otf.copy_to_tfm(otfdata,cache_id) - if tfmdata and next(tfmdata) then - tfmdata.unique = tfmdata.unique or { } - tfmdata.shared = tfmdata.shared or { } -- combine - local shared = tfmdata.shared - shared.otfdata = otfdata - shared.features = features -- default - shared.dynamics = { } - shared.processes = { } - shared.set_dynamics = otf.set_dynamics -- fast access and makes other modules independent - -- this will be done later anyway, but it's convenient to have - -- them already for fast access - tfmdata.luatex = otfdata.luatex - tfmdata.indices = otfdata.luatex.indices - tfmdata.unicodes = otfdata.luatex.unicodes - tfmdata.marks = otfdata.luatex.marks - tfmdata.originals = otfdata.luatex.originals - tfmdata.changed = { } - tfmdata.has_italic = otfdata.metadata.has_italic - if not tfmdata.language then tfmdata.language = 'dflt' end - if not tfmdata.script then tfmdata.script = 'dflt' end - shared.processes, shared.features = otf.set_features(tfmdata,fonts.define.check(features,otf.features.default)) - end - end - containers.write(tfm.cache,cache_id,tfmdata) - end - return tfmdata -end - --~ { --~ ['boundingbox']={ 95, -458, 733, 1449 }, --~ ['class']="base", @@ -1528,7 +1482,7 @@ fonts.formats.ttc = "truetype" fonts.formats.ttf = "truetype" fonts.formats.otf = "opentype" -function otf.copy_to_tfm(data,cache_id) -- we can save a copy when we reorder the tma to unicode (nasty due to one->many) +local function copytotfm(data,cache_id) -- we can save a copy when we reorder the tma to unicode (nasty due to one->many) if data then local glyphs, pfminfo, metadata = data.glyphs or { }, data.pfminfo or { }, data.metadata or { } local luatex = data.luatex @@ -1695,10 +1649,56 @@ function otf.copy_to_tfm(data,cache_id) -- we can save a copy when we reorder th end end +local function otftotfm(specification) + local name = specification.name + local sub = specification.sub + local filename = specification.filename + local format = specification.format + local features = specification.features.normal + local cache_id = specification.hash + local tfmdata = containers.read(tfm.cache,cache_id) +--~ print(cache_id) + if not tfmdata then + local otfdata = otf.load(filename,format,sub,features and features.featurefile) + if otfdata and next(otfdata) then + otfdata.shared = otfdata.shared or { + featuredata = { }, + anchorhash = { }, + initialized = false, + } + tfmdata = copytotfm(otfdata,cache_id) + if tfmdata and next(tfmdata) then + tfmdata.unique = tfmdata.unique or { } + tfmdata.shared = tfmdata.shared or { } -- combine + local shared = tfmdata.shared + shared.otfdata = otfdata + shared.features = features -- default + shared.dynamics = { } + shared.processes = { } + shared.setdynamics = otf.setdynamics -- fast access and makes other modules independent + -- this will be done later anyway, but it's convenient to have + -- them already for fast access + tfmdata.luatex = otfdata.luatex + tfmdata.indices = otfdata.luatex.indices + tfmdata.unicodes = otfdata.luatex.unicodes + tfmdata.marks = otfdata.luatex.marks + tfmdata.originals = otfdata.luatex.originals + tfmdata.changed = { } + tfmdata.has_italic = otfdata.metadata.has_italic + if not tfmdata.language then tfmdata.language = 'dflt' end + if not tfmdata.script then tfmdata.script = 'dflt' end + shared.processes, shared.features = otf.setfeatures(tfmdata,fonts.define.check(features,otf.features.default)) + end + end + containers.write(tfm.cache,cache_id,tfmdata) + end + return tfmdata +end + otf.features.register('mathsize') -function tfm.read_from_open_type(specification) - local tfmtable = otf.otf_to_tfm(specification) +function tfm.read_from_open_type(specification) -- wrong namespace + local tfmtable = otftotfm(specification) if tfmtable then local otfdata = tfmtable.shared.otfdata tfmtable.name = specification.name diff --git a/tex/context/base/font-oth.lua b/tex/context/base/font-oth.lua index 62ff41c40..448d54b90 100644 --- a/tex/context/base/font-oth.lua +++ b/tex/context/base/font-oth.lua @@ -15,7 +15,7 @@ local collect_lookups = fonts.otf.collect_lookups -- happen when I get the feeling that there is a performance -- penalty involved. -function fonts.otf.get_alternate(tfmdata,k,kind,value) +function fonts.otf.getalternate(tfmdata,k,kind,value) if value then local shared = tfmdata.shared local otfdata = shared and shared.otfdata diff --git a/tex/context/base/font-ott.lua b/tex/context/base/font-ott.lua index 34802de9f..379032f18 100644 --- a/tex/context/base/font-ott.lua +++ b/tex/context/base/font-ott.lua @@ -635,9 +635,9 @@ local baselines = { ['romn'] = 'Roman baseline' } -local to_scripts = table.reverse_hash(scripts ) -local to_languages = table.reverse_hash(languages) -local to_features = table.reverse_hash(features ) +local to_scripts = table.swaphash(scripts ) +local to_languages = table.swaphash(languages) +local to_features = table.swaphash(features ) tables.scripts = scripts tables.languages = languages diff --git a/tex/context/base/font-syn.lua b/tex/context/base/font-syn.lua index 8a18f07b7..39e3df5ea 100644 --- a/tex/context/base/font-syn.lua +++ b/tex/context/base/font-syn.lua @@ -785,10 +785,10 @@ end function names.is_permitted(name) return containers.is_usable(names.cache, name) end -function names.write_data(name,data) +function names.writedata(name,data) containers.write(names.cache,name,data) end -function names.read_data(name) +function names.readdata(name) return containers.read(names.cache,name) end @@ -797,13 +797,13 @@ function names.load(reload,verbose) if reload then if names.is_permitted(names.basename) then names.identify(verbose) - names.write_data(names.basename,names.data) + names.writedata(names.basename,names.data) else report_names("unable to access database cache") end names.saved = true end - local data = names.read_data(names.basename) + local data = names.readdata(names.basename) names.data = data if not names.saved then if not data or not next(data) or not data.specifications or not next(data.specifications) then diff --git a/tex/context/base/grph-inc.lua b/tex/context/base/grph-inc.lua index c8ad5995e..b1eccca08 100644 --- a/tex/context/base/grph-inc.lua +++ b/tex/context/base/grph-inc.lua @@ -87,7 +87,7 @@ end local validsizes = table.tohash(img.boxes()) local validtypes = table.tohash(img.types()) -function img.check_size(size) +function img.checksize(size) if size then size = gsub(size,"box","") return (validsizes[size] and size) or "crop" @@ -112,7 +112,7 @@ figures.defaultsearch = true figures.defaultwidth = 0 figures.defaultheight = 0 figures.defaultdepth = 0 -figures.n = 0 +figures.nofprocessed = 0 figures.prefer_quality = true -- quality over location figures.localpaths = { @@ -293,7 +293,7 @@ do -- can be determined; at some point the handlers might set them to numbers instead -- local w, h = tonumber(request.width), tonumber(request.height) request.page = math.max(tonumber(request.page) or 1,1) - request.size = img.check_size(request.size) + request.size = img.checksize(request.size) request.object = iv[request.object] == variables.yes request["repeat"] = iv[request["repeat"]] == variables.yes request.preview = iv[request.preview] == variables.yes @@ -666,7 +666,7 @@ figures.identifiers = figures.identifiers or { } local identifiers = figures.identifiers figures.programs = figures.programs or { } -programs = figures.programs +local programs = figures.programs function identifiers.default(data) local dr, du, ds = data.request, data.used, data.status @@ -713,7 +713,7 @@ function figures.scale(data) -- will become lua code return data end function figures.done(data) - figures.n = figures.n + 1 + figures.nofprocessed = figures.nofprocessed + 1 data = data or figures.current() --~ print(table.serialize(figures.current())) local dr, du, ds, nr = data.request, data.used, data.status, figures.boxnumber @@ -1140,9 +1140,9 @@ identifiers.list = { -- tracing statistics.register("graphics processing time", function() - local n = figures.n - if n > 0 then - return format("%s seconds including tex, n=%s", statistics.elapsedtime(figures),n) + local nofprocessed = figures.nofprocessed + if nofprocessed > 0 then + return format("%s seconds including tex, %s processed images", statistics.elapsedtime(figures),nofprocessed) else return nil end diff --git a/tex/context/base/java-ini.lua b/tex/context/base/java-ini.lua index 98c7145af..0c7cdcfa4 100644 --- a/tex/context/base/java-ini.lua +++ b/tex/context/base/java-ini.lua @@ -10,6 +10,8 @@ local format = string.format local concat = table.concat local lpegmatch, lpegP, lpegR, lpegS, lpegC = lpeg.match, lpeg.P, lpeg.R, lpeg.S, lpeg.C +-- todo: don't flush scripts if no JS key + interactions.javascripts = interactions.javascripts or { } local javascripts = interactions.javascripts javascripts.codes = javascripts.codes or { } @@ -89,6 +91,8 @@ end local splitter = lpeg.Ct(lpeg.splitat(lpeg.patterns.commaspacer)) +local used = false + function javascripts.code(name,arguments) local c = codes[name] if c then @@ -99,10 +103,12 @@ function javascripts.code(name,arguments) preambles[p][1] = "now" end end + used = true return code end local f = functions[name] if f then + used = true if arguments then local args = lpegmatch(splitter,arguments) for i=1,#args do -- can be a helper @@ -117,10 +123,12 @@ end function javascripts.flushpreambles() local t = { } - for i=1,#preambles do - local preamble = preambles[i] - if preamble[2] == "now" then - t[#t+1] = { preamble[1], preamble[3] } + if used then + for i=1,#preambles do + local preamble = preambles[i] + if preamble[2] == "now" then + t[#t+1] = { preamble[1], preamble[3] } + end end end return t diff --git a/tex/context/base/l-dir.lua b/tex/context/base/l-dir.lua index 04b3925e7..455f71b53 100644 --- a/tex/context/base/l-dir.lua +++ b/tex/context/base/l-dir.lua @@ -6,7 +6,7 @@ if not modules then modules = { } end modules ['l-dir'] = { license = "see context related readme files" } --- dir.expand_name will be merged with cleanpath and collapsepath +-- dir.expandname will be merged with cleanpath and collapsepath local type = type local find, gmatch, match, gsub = string.find, string.gmatch, string.match, string.gsub @@ -35,7 +35,7 @@ end -- optimizing for no find (*) does not save time -local function glob_pattern(path,patt,recurse,action) +local function globpattern(path,patt,recurse,action) local ok, scanner if path == "/" then ok, scanner = xpcall(function() return walkdir(path..".") end, function() end) -- kepler safe @@ -52,15 +52,15 @@ local function glob_pattern(path,patt,recurse,action) action(full) end elseif recurse and (mode == "directory") and (name ~= '.') and (name ~= "..") then - glob_pattern(full,patt,recurse,action) + globpattern(full,patt,recurse,action) end end end end -dir.glob_pattern = glob_pattern +dir.globpattern = globpattern -local function collect_pattern(path,patt,recurse,result) +local function collectpattern(path,patt,recurse,result) local ok, scanner result = result or { } if path == "/" then @@ -79,7 +79,7 @@ local function collect_pattern(path,patt,recurse,result) result[name] = attr end elseif recurse and (mode == "directory") and (name ~= '.') and (name ~= "..") then - attr.list = collect_pattern(full,patt,recurse) + attr.list = collectpattern(full,patt,recurse) result[name] = attr end end @@ -87,7 +87,7 @@ local function collect_pattern(path,patt,recurse,result) return result end -dir.collect_pattern = collect_pattern +dir.collectpattern = collectpattern local pattern = Ct { [1] = (C(P(".") + P("/")^1) + C(R("az","AZ") * P(":") * P("/")^0) + Cc("./")) * V(2) * V(3), @@ -120,7 +120,7 @@ local function glob(str,t) local recurse = find(base,"%*%*") local start = root .. path local result = lpegmatch(filter,start .. base) - glob_pattern(start,result,recurse,t) + globpattern(start,result,recurse,t) end end else @@ -143,7 +143,7 @@ local function glob(str,t) local recurse = find(base,"%*%*") local start = root .. path local result = lpegmatch(filter,start .. base) - glob_pattern(start,result,recurse,action) + globpattern(start,result,recurse,action) return t else return { } @@ -277,7 +277,7 @@ if find(os.getenv("PATH"),";") then -- os.type == "windows" --~ print(dir.mkdirs("///a/b/c")) --~ print(dir.mkdirs("a/bbb//ccc/")) - function dir.expand_name(str) -- will be merged with cleanpath and collapsepath + function dir.expandname(str) -- will be merged with cleanpath and collapsepath local first, nothing, last = match(str,"^(//)(//*)(.*)$") if first then first = dir.current() .. "/" @@ -357,7 +357,7 @@ else --~ print(dir.mkdirs("///a/b/c")) --~ print(dir.mkdirs("a/bbb//ccc/")) - function dir.expand_name(str) -- will be merged with cleanpath and collapsepath + function dir.expandname(str) -- will be merged with cleanpath and collapsepath if not find(str,"^/") then str = currentdir() .. "/" .. str end diff --git a/tex/context/base/l-file.lua b/tex/context/base/l-file.lua index 1b4e91f77..edc1dc9e4 100644 --- a/tex/context/base/l-file.lua +++ b/tex/context/base/l-file.lua @@ -8,13 +8,13 @@ if not modules then modules = { } end modules ['l-file'] = { -- needs a cleanup -file = file or { } +file = file or { } local file = file local insert, concat = table.insert, table.concat local find, gmatch, match, gsub, sub, char = string.find, string.gmatch, string.match, string.gsub, string.sub, string.char local lpegmatch = lpeg.match -local getcurrentdir = lfs.currentdir +local getcurrentdir, attributes = lfs.currentdir, lfs.attributes local P, R, S, C, Cs, Cp, Cc = lpeg.P, lpeg.R, lpeg.S, lpeg.C, lpeg.Cs, lpeg.Cp, lpeg.Cc @@ -146,18 +146,18 @@ end --~ print(file.join("http:///a","/y")) --~ print(file.join("//nas-1","/y")) -function file.iswritable(name) - local a = lfs.attributes(name) or lfs.attributes(dirname(name,".")) +function file.is_writable(name) + local a = attributes(name) or attributes(dirname(name,".")) return a and sub(a.permissions,2,2) == "w" end -function file.isreadable(name) - local a = lfs.attributes(name) +function file.is_readable(name) + local a = attributes(name) return a and sub(a.permissions,1,1) == "r" end -file.is_readable = file.isreadable -file.is_writable = file.iswritable +file.isreadable = file.is_readable -- depricated +file.iswritable = file.is_writable -- depricated -- todo: lpeg @@ -189,7 +189,7 @@ end --~ function file.old_collapse_path(str) -- fails on b.c/.. --~ str = gsub(str,"\\","/") --~ if find(str,"/") then ---~ str = gsub(str,"^%./",(gsub(lfs.currentdir(),"\\","/")) .. "/") -- ./xx in qualified +--~ str = gsub(str,"^%./",(gsub(getcurrentdir(),"\\","/")) .. "/") -- ./xx in qualified --~ str = gsub(str,"/%./","/") --~ local n, m = 1, 1 --~ while n > 0 or m > 0 do @@ -418,8 +418,8 @@ end --~ -- todo: --~ --~ if os.type == "windows" then ---~ local currentdir = lfs.currentdir ---~ function lfs.currentdir() +--~ local currentdir = getcurrentdir +--~ function getcurrentdir() --~ return (gsub(currentdir(),"\\","/")) --~ end --~ end diff --git a/tex/context/base/l-string.lua b/tex/context/base/l-string.lua index cc04168e9..d0f58b37d 100644 --- a/tex/context/base/l-string.lua +++ b/tex/context/base/l-string.lua @@ -30,7 +30,9 @@ if not string.split then end -local chr_to_esc = { +string.patterns = { } + +local escapes = { ["%"] = "%%", ["."] = "%.", ["+"] = "%+", ["-"] = "%-", ["*"] = "%*", @@ -40,10 +42,10 @@ local chr_to_esc = { ["{"] = "%{", ["}"] = "%}" } -string.chr_to_esc = chr_to_esc +string.patterns.escapes = escapes function string:esc() -- variant 2 - return (gsub(self,"(.)",chr_to_esc)) + return (gsub(self,"(.)",escapes)) end function string:unquote() @@ -110,21 +112,6 @@ function string:enhance(pattern,action) return self, n end -local chr_to_hex, hex_to_chr = { }, { } - -for i=0,255 do - local c, h = char(i), format("%02X",i) - chr_to_hex[c], hex_to_chr[h] = h, c -end - -function string:to_hex() - return (gsub(self or "","(.)",chr_to_hex)) -end - -function string:from_hex() - return (gsub(self or "","(..)",hex_to_chr)) -end - if not string.characters then local function nextchar(str, index) @@ -144,8 +131,6 @@ if not string.characters then end --- we can use format for this (neg n) - function string:rpadd(n,chr) local m = n-#self if m > 0 then @@ -166,18 +151,6 @@ end string.padd = string.rpadd -function string:split_settings() -- no {} handling, see l-aux for lpeg variant - if find(self,"=") then - local t = { } - for k,v in gmatch(self,"(%a+)=([^%,]*)") do - t[k] = v - end - return t - else - return nil - end -end - local patterns_escapes = { ["-"] = "%-", ["."] = "%.", @@ -190,7 +163,7 @@ local patterns_escapes = { ["]"] = "%]", } -function string:pattesc() +function string:escapedpattern() return (gsub(self,".",patterns_escapes)) end @@ -201,7 +174,7 @@ local simple_escapes = { ["*"] = ".*", } -function string:simpleesc() +function string:partialescapedpattern() return (gsub(self,".",simple_escapes)) end diff --git a/tex/context/base/l-table.lua b/tex/context/base/l-table.lua index 67216d1f5..331bd9ca0 100644 --- a/tex/context/base/l-table.lua +++ b/tex/context/base/l-table.lua @@ -264,15 +264,11 @@ function table.is_empty(t) -- obolete, use inline code instead return not t or not next(t) end -function table.one_entry(t) -- obolete, use inline code instead +function table.has_one_entry(t) local n = next(t) return n and not next(t,n) end ---~ function table.starts_at(t) -- obsolete, not nice anyway ---~ return ipairs(t,1)(t,0) ---~ end - function table.tohash(t,value) local h = { } if t then @@ -694,7 +690,7 @@ function table.unnest(t) -- bad name return f end -table.flatten_one_level = table.unnest +table.flattenonelevel = table.unnest -- a better one: @@ -714,51 +710,6 @@ end table.flattened = flattened --- the next three may disappear - -function table.remove_value(t,value) -- todo: n - if value then - for i=1,#t do - if t[i] == value then - remove(t,i) - -- remove all, so no: return - end - end - end -end - -function table.insert_before_value(t,value,str) - if str then - if value then - for i=1,#t do - if t[i] == value then - insert(t,i,str) - return - end - end - end - insert(t,1,str) - elseif value then - insert(t,1,value) - end -end - -function table.insert_after_value(t,value,str) - if str then - if value then - for i=1,#t do - if t[i] == value then - insert(t,i+1,str) - return - end - end - end - t[#t+1] = str - elseif value then - t[#t+1] = value - end -end - local function are_equal(a,b,n,m) -- indexed if a and b and #a == #b then n = n or 1 @@ -873,7 +824,7 @@ function table.hexed(t,seperator) return concat(tt,seperator or " ") end -function table.reverse_hash(h) -- needs another name +function table.swaphash(h) -- needs another name local r = { } for k,v in next, h do r[v] = lower(gsub(k," ","")) @@ -891,36 +842,6 @@ function table.reverse(t) return tt end -function table.insert_before_value(t,value,extra) - for i=1,#t do - if t[i] == extra then - remove(t,i) - end - end - for i=1,#t do - if t[i] == value then - insert(t,i,extra) - return - end - end - insert(t,1,extra) -end - -function table.insert_after_value(t,value,extra) - for i=1,#t do - if t[i] == extra then - remove(t,i) - end - end - for i=1,#t do - if t[i] == value then - insert(t,i+1,extra) - return - end - end - insert(t,#t+1,extra) -end - function table.sequenced(t,sep,simple) -- hash only local s = { } for k, v in sortedhash(t) do diff --git a/tex/context/base/lang-wrd.lua b/tex/context/base/lang-wrd.lua index 43e91f09d..5e6cf7934 100644 --- a/tex/context/base/lang-wrd.lua +++ b/tex/context/base/lang-wrd.lua @@ -34,7 +34,7 @@ local kerncodes = nodes.kerncodes local glyph_node = nodecodes.glyph local disc_node = nodecodes.disc -local kern_no de = nodecodes.kern +local kern_node = nodecodes.kern local kerning_code = kerncodes.kerning diff --git a/tex/context/base/lpdf-fld.lua b/tex/context/base/lpdf-fld.lua index f05dcaa85..01c791d69 100644 --- a/tex/context/base/lpdf-fld.lua +++ b/tex/context/base/lpdf-fld.lua @@ -13,6 +13,7 @@ if not modules then modules = { } end modules ['lpdf-fld'] = { local gmatch, lower, format = string.gmatch, string.lower, string.format local lpegmatch = lpeg.match local texsprint, ctxcatcodes = tex.sprint, tex.ctxcatcodes +local bpfactor, todimen = number.dimenfactors.bp, string.todimen local trace_fields = false trackers.register("widgets.fields", function(v) trace_fields = v end) @@ -40,6 +41,7 @@ local pdfstring = lpdf.string local pdfconstant = lpdf.constant local pdftoeight = lpdf.toeight local pdfflushobject = lpdf.flushobject +local pdfsharedobject = lpdf.sharedobject local pdfreserveobject = lpdf.reserveobject local nodepool = nodes.pool @@ -193,10 +195,10 @@ local function fieldsurrounding(specification) alternative, a = "tf", s.tf end local tag = style .. alternative - size = string.todimen(size) + size = todimen(size) local stream = pdfstream { pdfconstant(tag), - format("%0.4f Tf",(size and (number.dimenfactors.bp * size)) or 12), + format("%0.4f Tf",(size and (bpfactor * size)) or 12), } usedfonts[tag] = a -- the name -- add color to stream: 0 g @@ -252,7 +254,7 @@ local function fieldappearances(specification) local appearance = pdfdictionary { -- cache this one N = registeredsymbol(n), R = registeredsymbol(r), D = registeredsymbol(d), } - return lpdf.sharedobj(tostring(appearance)) + return pdfsharedobject(tostring(appearance)) end local function fieldstates(specification,forceyes,values,default) @@ -314,7 +316,7 @@ local function fieldstates(specification,forceyes,values,default) R = pdfdictionary { [forceyes or yesr] = registeredsymbol(yesr), Off = registeredsymbol(offr) }, D = pdfdictionary { [forceyes or yesd] = registeredsymbol(yesd), Off = registeredsymbol(offd) } } - local appearanceref = lpdf.sharedobj(tostring(appearance)) + local appearanceref = pdfsharedobject(tostring(appearance)) return appearanceref, default end @@ -668,7 +670,6 @@ function methods.line(name,specification,variant,extras) F = fieldplus(specification), Ff = fieldflag(specification), OC = fieldlayer(specification), - MK = fieldsurrounding(specification), -- needed ? DA = fieldsurrounding(specification), AA = fieldactions(specification), FT = pdf_tx, @@ -690,7 +691,6 @@ function methods.line(name,specification,variant,extras) F = fieldplus(specification), DA = fieldattributes(specification), OC = fieldlayer(specification), - MK = fieldsurrounding(specification), DA = fieldsurrounding(specification), AA = fieldactions(specification), Q = fieldalignment(specification), @@ -870,13 +870,14 @@ function methods.sub(name,specification,variant) -- enhance(specification,"Radio,RadiosInUnison") enhance(specification,"RadiosInUnison") -- maybe also PushButton as acrobat does local d = pdfdictionary { - T = parent.name, - FT = pdf_btn, - Rect = pdf_no_rect, - F = fieldplus(specification), - Ff = fieldflag(specification), - H = pdf_n, - V = default, + Subtype = pdf_widget, + T = parent.name, + FT = pdf_btn, + Rect = pdf_no_rect, + F = fieldplus(specification), + Ff = fieldflag(specification), + H = pdf_n, + V = default, } save_parent(parent,specification,d) end diff --git a/tex/context/base/lpdf-ini.lua b/tex/context/base/lpdf-ini.lua index 55da04da4..07e1962cd 100644 --- a/tex/context/base/lpdf-ini.lua +++ b/tex/context/base/lpdf-ini.lua @@ -409,7 +409,7 @@ function lpdf.flushobject(name,data) end end -function lpdf.sharedobj(content) +function lpdf.sharedobject(content) local r = cache[content] if not r then r = pdfreference(pdfimmediateobject(content)) diff --git a/tex/context/base/lpdf-tag.lua b/tex/context/base/lpdf-tag.lua index 48140f53d..4e297b91c 100644 --- a/tex/context/base/lpdf-tag.lua +++ b/tex/context/base/lpdf-tag.lua @@ -386,8 +386,7 @@ function nodeinjections.addtags(head) end function codeinjections.enabletags(tg,lb) - taglist = tg - usedlabels = lb + taglist, usedlabels = tg, lb structures.tags.handler = nodeinjections.addtags tasks.enableaction("shipouts","structures.tags.handler") tasks.enableaction("shipouts","nodes.handlers.accessibility") diff --git a/tex/context/base/luat-cbk.lua b/tex/context/base/luat-cbk.lua index 9ecf64264..454c89425 100644 --- a/tex/context/base/luat-cbk.lua +++ b/tex/context/base/luat-cbk.lua @@ -53,40 +53,31 @@ local delayed = table.tohash { } -if not callback.original_register then - - callback.original_register = register_callback - - local original_register = register_callback - - if trace_calls then +if trace_calls then - local functions = { } + local functions = { } + local original = register_callback - register_callback = function(name,func) - if type(func) == "function" then - if functions[name] then - functions[name] = func - return find_callback(name) - else - functions[name] = func - local cnuf = function(...) - list[name] = list[name] + 1 - return functions[name](...) - end - return original_register(name,cnuf) - end + register_callback = function(name,func) + if type(func) == "function" then + if functions[name] then + functions[name] = func + return find_callback(name) else - return original_register(name,func) + functions[name] = func + local cnuf = function(...) + list[name] = list[name] + 1 + return functions[name](...) + end + return original(name,cnuf) end + else + return original(name,func) end - end end -callback.register = register_callback - local function frozen_message(what,name) report_callbacks("not %s frozen '%s' (%s)",what,name,frozen[name]) end @@ -133,7 +124,7 @@ end function callbacks.freeze(name,freeze) freeze = type(freeze) == "string" and freeze if find(name,"%*") then - local pattern = name -- string.simpleesc(name) + local pattern = name -- string.partialescapedpattern(name) for name, _ in next, list do if find(name,pattern) then frozen[name] = freeze or frozen[name] or "frozen" diff --git a/tex/context/base/luat-cnf.lua b/tex/context/base/luat-cnf.lua index 8d9c33739..4e723afee 100644 --- a/tex/context/base/luat-cnf.lua +++ b/tex/context/base/luat-cnf.lua @@ -15,7 +15,7 @@ texconfig.shell_escape = 't' luatex = luatex or { } local luatex = luatex -luatex.variablenames = { +local variablenames = { -- most of this becomes obsolete 'buf_size', -- 3000 'dvi_buf_size', -- 16384 'error_line', -- 79 @@ -36,21 +36,19 @@ luatex.variablenames = { 'strings_free', -- 100 } -function luatex.variables() - local t = { } - for _,v in next, luatex.variablenames do - local x = resolvers.var_value(v) - t[v] = tonumber(x) or x +local function initialize() + local t, var_value = { }, resolvers.var_value + for i=1,#variablenames do + local name = variablenames[i] + local value = var_value(name) + value = tonumber(value) or value + texconfig[name], t[name] = value, value end + initialize = nil return t end -if not luatex.variables_set then - for k, v in next, luatex.variables() do - texconfig[k] = v - end - luatex.variables_set = true -end +luatex.variables = initialize() local stub = [[ @@ -160,7 +158,7 @@ local function makestub() "-- this file is generated, don't change it\n", "-- configuration (can be overloaded later)\n" } - for _,v in next, luatex.variablenames do + for _,v in next, variablenames do local tv = texconfig[v] if tv and tv ~= "" then t[#t+1] = format("texconfig.%s=%s",v,tv) @@ -170,8 +168,3 @@ local function makestub() end lua.registerfinalizer(makestub,"create stub file") - --- to be moved here: --- --- statistics.report_storage("log") --- statistics.save_fmt_status("\jobname","\contextversion","context.tex") diff --git a/tex/context/base/luat-dum.lua b/tex/context/base/luat-dum.lua index 614c7d8f8..a8eed5d88 100644 --- a/tex/context/base/luat-dum.lua +++ b/tex/context/base/luat-dum.lua @@ -104,7 +104,7 @@ do cachepaths = string.split(cachepaths,os.type == "windows" and ";" or ":") for i=1,#cachepaths do - if file.iswritable(cachepaths[i]) then + if file.is_writable(cachepaths[i]) then writable = file.join(cachepaths[i],"luatex-cache") lfs.mkdir(writable) writable = file.join(writable,caches.namespace) @@ -114,7 +114,7 @@ do end for i=1,#cachepaths do - if file.isreadable(cachepaths[i]) then + if file.is_readable(cachepaths[i]) then readables[#readables+1] = file.join(cachepaths[i],"luatex-cache",caches.namespace) end end @@ -157,9 +157,9 @@ local function makefullname(path,name) end end -function caches.iswritable(path,name) +function caches.is_writable(path,name) local fullname = makefullname(path,name) - return fullname and file.iswritable(fullname) + return fullname and file.is_writable(fullname) end function caches.loaddata(paths,name) diff --git a/tex/context/base/luat-env.lua b/tex/context/base/luat-env.lua index 975950118..5fa9550f7 100644 --- a/tex/context/base/luat-env.lua +++ b/tex/context/base/luat-env.lua @@ -77,7 +77,7 @@ local mt = { setmetatable(environment,mt) -function environment.initialize_arguments(arg) +function environment.initializearguments(arg) local arguments, files = { }, { } environment.arguments, environment.files, environment.sortedflags = arguments, files, nil for index=1,#arg do @@ -131,11 +131,11 @@ function environment.argument(name,partial) return nil end -function environment.split_arguments(separator) -- rather special, cut-off before separator +function environment.splitarguments(separator) -- rather special, cut-off before separator local done, before, after = false, { }, { } - local original_arguments = environment.original_arguments - for k=1,#original_arguments do - local v = original_arguments[k] + local originalarguments = environment.originalarguments + for k=1,#originalarguments do + local v = originalarguments[k] if not done and v == separator then done = true elseif done then @@ -147,8 +147,8 @@ function environment.split_arguments(separator) -- rather special, cut-off befor return before, after end -function environment.reconstruct_commandline(arg,noquote) - arg = arg or environment.original_arguments +function environment.reconstructcommandline(arg,noquote) + arg = arg or environment.originalarguments if noquote and #arg == 1 then local a = arg[1] a = resolvers.resolve(a) @@ -198,9 +198,10 @@ if arg then newarg[i] = arg[i] end - environment.initialize_arguments(newarg) - environment.original_arguments = newarg - environment.raw_arguments = arg + environment.initializearguments(newarg) + + environment.originalarguments = newarg + environment.rawarguments = arg arg = { } -- prevent duplicate handling diff --git a/tex/context/base/luat-fmt.lua b/tex/context/base/luat-fmt.lua index 14727d894..13f751215 100644 --- a/tex/context/base/luat-fmt.lua +++ b/tex/context/base/luat-fmt.lua @@ -41,7 +41,7 @@ function environment.make_format(name) else logs.simple("using tex source file: %s",fulltexsourcename) end - local texsourcepath = dir.expand_name(file.dirname(fulltexsourcename)) -- really needed + local texsourcepath = dir.expandname(file.dirname(fulltexsourcename)) -- really needed -- check specification local specificationname = file.replacesuffix(fulltexsourcename,"lus") local fullspecificationname = resolvers.find_file(specificationname,"tex") or "" diff --git a/tex/context/base/luat-iop.lua b/tex/context/base/luat-iop.lua index 5d0d1f6c9..e6f8a7433 100644 --- a/tex/context/base/luat-iop.lua +++ b/tex/context/base/luat-iop.lua @@ -29,10 +29,10 @@ local function o_permit (name) out_permitted[#out_permitted+1] = name end ioinp.inhibit, ioinp.permit = i_inhibit, o_permit ioout.inhibit, ioout.permit = o_inhibit, o_permit -local blocked_openers = { } -- *.open(name,method) +local blockedopeners = { } -- *.open(name,method) -function io.register_opener(func) - blocked_openers[#blocked_openers+1] = func +function io.registeropener(func) + blockedopeners[#blockedopeners+1] = func end local function checked(name,blocked,permitted) @@ -50,7 +50,7 @@ local function checked(name,blocked,permitted) return true end -function io.finalize_openers(func) +function io.finalizeopeners(func) if #out_blocked > 0 or #inp_blocked > 0 then local open = func -- why not directly? return function(name,method) @@ -78,7 +78,7 @@ end --~ io.inp.inhibit('/winnt/') --~ io.inp.permit('c:/windows/wmsetup.log') ---~ io.open = io.finalize_openers(io.open) +--~ io.open = io.finalizeopeners(io.open) --~ f = io.open('.tex') print(f) --~ f = io.open('tufte.tex') print(f) diff --git a/tex/context/base/luat-lua.lua b/tex/context/base/luat-lua.lua index b964bf8e8..50492540d 100644 --- a/tex/context/base/luat-lua.lua +++ b/tex/context/base/luat-lua.lua @@ -10,11 +10,7 @@ if lua then do local delayed = { } - function lua.delay(f) - delayed[#delayed+1] = f - end - - function lua.flush_delayed(...) + local function flushdelayed(...) local t = delayed delayed = { } for i=1, #t do @@ -22,8 +18,12 @@ if lua then do end end + function lua.delay(f) + delayed[#delayed+1] = f + end + function lua.flush(...) - tex.sprint("\\directlua0{lua.flush_delayed(",table.concat({...},','),")}") + tex.sprint("\\directlua{flushdelayed(",table.concat({...},','),")}") end end end diff --git a/tex/context/base/luat-run.lua b/tex/context/base/luat-run.lua index 00ed54bfd..46173ecf8 100644 --- a/tex/context/base/luat-run.lua +++ b/tex/context/base/luat-run.lua @@ -7,6 +7,7 @@ if not modules then modules = { } end modules ['luat-run'] = { } local format, rpadd = string.format, string.rpadd +local insert = table.insert local trace_lua_dump = false trackers .register("system.dump", function(v) trace_lua_dump = v end) @@ -15,32 +16,32 @@ local report_lua_dump = logs.new("lua dump actions") luatex = luatex or { } local luatex = luatex -local start_actions = { } -local stop_actions = { } +local startactions = { } +local stopactions = { } -function luatex.register_start_actions(...) table.insert(start_actions, ...) end -function luatex.register_stop_actions (...) table.insert(stop_actions, ...) end +function luatex.registerstartactions(...) insert(startactions, ...) end +function luatex.registerstopactions (...) insert(stopactions, ...) end -luatex.show_tex_stat = luatex.show_tex_stat or function() end -luatex.show_job_stat = luatex.show_job_stat or statistics.show_job_stat +luatex.showtexstat = luatex.showtexstat or function() end +luatex.showjobstat = luatex.showjobstat or statistics.showjobstat local function start_run() if logs.start_run then logs.start_run() end - for _, action in next, start_actions do - action() + for i=1,#startactions do + startactions[i]() end end local function stop_run() - for _, action in next, stop_actions do - action() + for i=1,#stopactions do + stopactions[i]() end - if luatex.show_job_stat then + if luatex.showjobstat then statistics.show(logs.report_job_stat) end - if luatex.show_tex_stat then + if luatex.showtexstat then for k,v in next, status.list() do logs.report_tex_stat(k,v) end @@ -66,6 +67,8 @@ end local function pre_dump_actions() lua.finalize(trace_lua_dump and report_lua_dump or nil) + statistics.reportstorage("log") + -- statistics.savefmtstatus("\jobname","\contextversion","context.tex") end -- this can be done later diff --git a/tex/context/base/luat-sto.lua b/tex/context/base/luat-sto.lua index f234a0628..0c810021d 100644 --- a/tex/context/base/luat-sto.lua +++ b/tex/context/base/luat-sto.lua @@ -113,7 +113,7 @@ if lua.bytedata then storage.register("lua/bytedata",lua.bytedata,"lua.bytedata") end -function statistics.report_storage(whereto) +function statistics.reportstorage(whereto) whereto = whereto or "term and log" write_nl(whereto," ","stored tables:"," ") for k,v in table.sortedhash(storage.data) do diff --git a/tex/context/base/lxml-aux.lua b/tex/context/base/lxml-aux.lua index 4ac3f0359..f2e3ee61e 100644 --- a/tex/context/base/lxml-aux.lua +++ b/tex/context/base/lxml-aux.lua @@ -15,8 +15,9 @@ local report_xml = logs.new("xml") local xml = xml -local xmlparseapply, xmlconvert, xmlcopy, xmlname = xml.parse_apply, xml.convert, xml.copy, xml.name +local xmlconvert, xmlcopy, xmlname = xml.convert, xml.copy, xml.name local xmlinheritedconvert = xml.inheritedconvert +local xmlapplylpath = xml.applylpath local type = type local insert, remove = table.insert, table.remove @@ -77,10 +78,8 @@ function xml.withelement(e,n,handle) -- slow end end -xml.elements_only = xml.collected - -function xml.each_element(root,pattern,handle,reverse) - local collected = xmlparseapply({ root },pattern) +function xml.each(root,pattern,handle,reverse) + local collected = xmlapplylpath({ root },pattern) if collected then if reverse then for c=#collected,1,-1 do @@ -95,10 +94,8 @@ function xml.each_element(root,pattern,handle,reverse) end end -xml.process_elements = xml.each_element - -function xml.process_attributes(root,pattern,handle) - local collected = xmlparseapply({ root },pattern) +function xml.processattributes(root,pattern,handle) + local collected = xmlapplylpath({ root },pattern) if collected and handle then for c=1,#collected do handle(collected[c].at) @@ -113,12 +110,12 @@ end -- are these still needed -> lxml-cmp.lua -function xml.collect_elements(root, pattern) - return xmlparseapply({ root },pattern) +function xml.collect(root, pattern) + return xmlapplylpath({ root },pattern) end -function xml.collect_texts(root, pattern, flatten) -- todo: variant with handle - local collected = xmlparseapply({ root },pattern) +function xml.collecttexts(root, pattern, flatten) -- todo: variant with handle + local collected = xmlapplylpath({ root },pattern) if collected and flatten then local xmltostring = xml.tostring for c=1,#collected do @@ -129,7 +126,7 @@ function xml.collect_texts(root, pattern, flatten) -- todo: variant with handle end function xml.collect_tags(root, pattern, nonamespace) - local collected = xmlparseapply({ root },pattern) + local collected = xmlapplylpath({ root },pattern) if collected then local t = { } for c=1,#collected do @@ -153,7 +150,7 @@ end local no_root = { no_root = true } -function xml.redo_ni(d) +local function redo_ni(d) for k=1,#d do local dk = d[k] if type(dk) == "table" then @@ -199,8 +196,8 @@ local function copiedelement(element,newparent) end end -function xml.delete_element(root,pattern) - local collected = xmlparseapply({ root },pattern) +function xml.delete(root,pattern) + local collected = xmlapplylpath({ root },pattern) if collected then for c=1,#collected do local e = collected[c] @@ -211,15 +208,15 @@ function xml.delete_element(root,pattern) end local d = p.dt remove(d,e.ni) - xml.redo_ni(d) -- can be made faster and inlined + redo_ni(d) -- can be made faster and inlined end end end end -function xml.replace_element(root,pattern,whatever) +function xml.replace(root,pattern,whatever) local element = root and xmltoelement(whatever,root) - local collected = element and xmlparseapply({ root },pattern) + local collected = element and xmlapplylpath({ root },pattern) if collected then for c=1,#collected do local e = collected[c] @@ -230,7 +227,7 @@ function xml.replace_element(root,pattern,whatever) end local d = p.dt d[e.ni] = copiedelement(element,p) - xml.redo_ni(d) -- probably not needed + redo_ni(d) -- probably not needed end end end @@ -238,7 +235,7 @@ end local function inject_element(root,pattern,whatever,prepend) local element = root and xmltoelement(whatever,root) - local collected = element and xmlparseapply({ root },pattern) + local collected = element and xmlapplylpath({ root },pattern) if collected then for c=1,#collected do local e = collected[c] @@ -261,7 +258,7 @@ local function inject_element(root,pattern,whatever,prepend) else d[k].dt = be end - xml.redo_ni(d) + redo_ni(d) end end end @@ -269,7 +266,7 @@ end local function insert_element(root,pattern,whatever,before) -- todo: element als functie local element = root and xmltoelement(whatever,root) - local collected = element and xmlparseapply({ root },pattern) + local collected = element and xmlapplylpath({ root },pattern) if collected then for c=1,#collected do local e = collected[c] @@ -279,24 +276,23 @@ local function insert_element(root,pattern,whatever,before) -- todo: element als k = k + 1 end insert(d,k,copiedelement(element,r)) - xml.redo_ni(d) + redo_ni(d) end end end -xml.insert_element = insert_element -xml.insert_element_after = insert_element -xml.insert_element_before = function(r,p,e) insert_element(r,p,e,true) end -xml.inject_element = inject_element -xml.inject_element_after = inject_element -xml.inject_element_before = function(r,p,e) inject_element(r,p,e,true) end +xml.insert_element = insert_element +xml.insertafter = insert_element +xml.insertbefore = function(r,p,e) insert_element(r,p,e,true) end +xml.injectafter = inject_element +xml.injectbefore = function(r,p,e) inject_element(r,p,e,true) end local function include(xmldata,pattern,attribute,recursive,loaddata) -- parse="text" (default: xml), encoding="" (todo) -- attribute = attribute or 'href' pattern = pattern or 'include' loaddata = loaddata or io.loaddata - local collected = xmlparseapply({ xmldata },pattern) + local collected = xmlapplylpath({ xmldata },pattern) if collected then for c=1,#collected do local ek = collected[c] @@ -339,65 +335,8 @@ end xml.include = include ---~ local function manipulate(xmldata,pattern,manipulator) -- untested and might go away ---~ local collected = xmlparseapply({ xmldata },pattern) ---~ if collected then ---~ local xmltostring = xml.tostring ---~ for c=1,#collected do ---~ local e = collected[c] ---~ local data = manipulator(xmltostring(e)) ---~ if data == "" then ---~ epdt[e.ni] = "" ---~ else ---~ local xi = xmlinheritedconvert(data,xmldata) ---~ if not xi then ---~ epdt[e.ni] = "" ---~ else ---~ epdt[e.ni] = xml.body(xi) -- xml.assign(d,k,xi) ---~ end ---~ end ---~ end ---~ end ---~ end - ---~ xml.manipulate = manipulate - -function xml.strip_whitespace(root, pattern, nolines) -- strips all leading and trailing space ! - local collected = xmlparseapply({ root },pattern) - if collected then - for i=1,#collected do - local e = collected[i] - local edt = e.dt - if edt then - local t = { } - for i=1,#edt do - local str = edt[i] - if type(str) == "string" then - if str == "" then - -- stripped - else - if nolines then - str = gsub(str,"[ \n\r\t]+"," ") - end - if str == "" then - -- stripped - else - t[#t+1] = str - end - end - else - --~ str.ni = i - t[#t+1] = str - end - end - e.dt = t - end - end - end -end - -function xml.strip_whitespace(root, pattern, nolines, anywhere) -- strips all leading and trailing spacing - local collected = xmlparseapply({ root },pattern) -- beware, indices no longer are valid now +function xml.strip(root, pattern, nolines, anywhere) -- strips all leading and trailing spacing + local collected = xmlapplylpath({ root },pattern) -- beware, indices no longer are valid now if collected then for i=1,#collected do local e = collected[i] @@ -468,7 +407,7 @@ function xml.strip_whitespace(root, pattern, nolines, anywhere) -- strips all le end end -local function rename_space(root, oldspace, newspace) -- fast variant +local function renamespace(root, oldspace, newspace) -- fast variant local ndt = #root.dt for i=1,ndt or 0 do local e = root[i] @@ -481,16 +420,16 @@ local function rename_space(root, oldspace, newspace) -- fast variant end local edt = e.dt if edt then - rename_space(edt, oldspace, newspace) + renamespace(edt, oldspace, newspace) end end end end -xml.rename_space = rename_space +xml.renamespace = renamespace -function xml.remap_tag(root, pattern, newtg) - local collected = xmlparseapply({ root },pattern) +function xml.remaptag(root, pattern, newtg) + local collected = xmlapplylpath({ root },pattern) if collected then for c=1,#collected do collected[c].tg = newtg @@ -498,8 +437,8 @@ function xml.remap_tag(root, pattern, newtg) end end -function xml.remap_namespace(root, pattern, newns) - local collected = xmlparseapply({ root },pattern) +function xml.remapnamespace(root, pattern, newns) + local collected = xmlapplylpath({ root },pattern) if collected then for c=1,#collected do collected[c].ns = newns @@ -507,8 +446,8 @@ function xml.remap_namespace(root, pattern, newns) end end -function xml.check_namespace(root, pattern, newns) - local collected = xmlparseapply({ root },pattern) +function xml.checknamespace(root, pattern, newns) + local collected = xmlapplylpath({ root },pattern) if collected then for c=1,#collected do local e = collected[c] @@ -519,8 +458,8 @@ function xml.check_namespace(root, pattern, newns) end end -function xml.remap_name(root, pattern, newtg, newns, newrn) - local collected = xmlparseapply({ root },pattern) +function xml.remapname(root, pattern, newtg, newns, newrn) + local collected = xmlapplylpath({ root },pattern) if collected then for c=1,#collected do local e = collected[c] @@ -533,15 +472,31 @@ end <p>Here are a few synonyms.</p> --ldx]]-- -xml.each = xml.each_element -xml.process = xml.process_element -xml.strip = xml.strip_whitespace -xml.collect = xml.collect_elements -xml.all = xml.collect_elements - -xml.insert = xml.insert_element_after -xml.inject = xml.inject_element_after -xml.after = xml.insert_element_after -xml.before = xml.insert_element_before -xml.delete = xml.delete_element -xml.replace = xml.replace_element +xml.all = xml.each +xml.insert = xml.insertafter +xml.inject = xml.injectafter +xml.after = xml.insertafter +xml.before = xml.insertbefore +xml.process = xml.each + +-- obsolete + +xml.obsolete = xml.obsolete or { } +local obsolete = xml.obsolete + +xml.strip_whitespace = xml.strip obsolete.strip_whitespace = xml.strip +xml.collect_elements = xml.collect obsolete.collect_elements = xml.collect +xml.delete_element = xml.delete obsolete.delete_element = xml.delete +xml.replace_element = xml.replace obsolete.replace_element = xml.replacet +xml.each_element = xml.each obsolete.each_element = xml.each +xml.process_elements = xml.process obsolete.process_elements = xml.process +xml.insert_element_after = xml.insertafter obsolete.insert_element_after = xml.insertafter +xml.insert_element_before = xml.insertbefore obsolete.insert_element_before = xml.insertbefore +xml.inject_element_after = xml.injectafter obsolete.inject_element_after = xml.injectafter +xml.inject_element_before = xml.injectbefore obsolete.inject_element_before = xml.injectbefore +xml.process_attributes = xml.processattributes obsolete.process_attributes = xml.processattributes +xml.collect_texts = xml.collecttexts obsolete.collect_texts = xml.collecttexts +xml.inject_element = xml.inject obsolete.inject_element = xml.inject +xml.remap_tag = xml.remaptag obsolete.remap_tag = xml.remaptag +xml.remap_name = xml.remapname obsolete.remap_name = xml.remapname +xml.remap_namespace = xml.remapnamespace obsolete.remap_namespace = xml.remapnamespace diff --git a/tex/context/base/lxml-ctx.lua b/tex/context/base/lxml-ctx.lua index cbd3c6727..04f1c58e0 100644 --- a/tex/context/base/lxml-ctx.lua +++ b/tex/context/base/lxml-ctx.lua @@ -41,8 +41,8 @@ function xml.ctx.tshow(specification) if not string.find(xmlpattern,"^[%a]+://") then xmlpattern = "xml://" .. pattern end - parsed = xml.parse_pattern(xmlpattern) - titlecommand = specification.title or "type" + local parsed = xml.lpath(xmlpattern) + local titlecommand = specification.title or "type" if parsed.state then context[titlecommand]("pattern: " .. pattern .. " (".. parsed.state .. ")") else @@ -88,9 +88,9 @@ function xml.ctx.tshow(specification) context.stoptabulate() if xmlroot and xmlroot ~= "" then if not loaded[xmlroot] then - loaded[xmlroot] = { xml.convert(buffers.content(xmlroot) or "") } + loaded[xmlroot] = xml.convert(buffers.content(xmlroot) or "") end - local collected = xml.parse_apply(loaded[xmlroot],xmlpattern) + local collected = xml.filter(loaded[xmlroot],xmlpattern) if collected then local tc = type(collected) if not tc then diff --git a/tex/context/base/lxml-dir.lua b/tex/context/base/lxml-dir.lua index 0bc79877b..bcb846bba 100644 --- a/tex/context/base/lxml-dir.lua +++ b/tex/context/base/lxml-dir.lua @@ -7,9 +7,8 @@ if not modules then modules = { } end modules ['lxml-dir'] = { } local format, gsub = string.format, string.gsub -local get_id = lxml.id +local getid = lxml.getid local texsprint, ctxcatcodes = tex.sprint, tex.ctxcatcodes -local xmlparseapply = xml.parse_apply --~ <?xml version="1.0" standalone="yes"?> --~ <!-- demo.cdx --> @@ -42,7 +41,7 @@ local function load_setup(filename) if fullname ~= "" then filename = fullname end - local collection = xmlparseapply({ get_id(xml.load(filename)) },"directive") + local collection = xmlparseapply({ getid(xml.load(filename)) },"directive") if collection then local valid = 0 for i=1,#collection do @@ -66,7 +65,7 @@ local function load_setup(filename) end local function handle_setup(category,root,attribute,element) - root = get_id(root) + root = getid(root) if attribute then local value = root.at[attribute] if value then diff --git a/tex/context/base/lxml-ent.lua b/tex/context/base/lxml-ent.lua index d92e48365..487d13983 100644 --- a/tex/context/base/lxml-ent.lua +++ b/tex/context/base/lxml-ent.lua @@ -34,18 +34,18 @@ storage.register("xml/entities",xml.entities,"xml.entities") -- this will move t local entities = xml.entities -- this is a shared hash -xml.unknown_any_entity_format = nil -- has to be per xml +xml.placeholders.unknown_any_entity = nil -- has to be per xml local parsedentity = xml.parsedentitylpeg -function xml.register_entity(key,value) +function xml.registerentity(key,value) entities[key] = value if trace_entities then report_xml("registering entity '%s' as: %s",key,value) end end -function xml.resolved_entity(str) +function xml.resolvedentity(str) local e = entities[str] if e then local te = type(e) diff --git a/tex/context/base/lxml-inf.lua b/tex/context/base/lxml-inf.lua index 6862c476b..834d152fd 100644 --- a/tex/context/base/lxml-inf.lua +++ b/tex/context/base/lxml-inf.lua @@ -8,8 +8,8 @@ if not modules then modules = { } end modules ['lxml-inf'] = { -- This file will be loaded runtime by x-pending.tex. - local xmlwithelements = xml.withelements +local getid = lxml.getid local status, stack @@ -42,7 +42,7 @@ end local function get_command_status(id) status, stack = {}, {} if id then - xmlwithelements(get_id(id),get) + xmlwithelements(getid(id),get) return status else local t = { } diff --git a/tex/context/base/lxml-ini.mkiv b/tex/context/base/lxml-ini.mkiv index 99e9dd7ac..8bc154df4 100644 --- a/tex/context/base/lxml-ini.mkiv +++ b/tex/context/base/lxml-ini.mkiv @@ -69,8 +69,8 @@ \def\xmlelement #1#2{\ctxlua{lxml.element("#1",#2)}} \def\xmlregisterns #1#2{\ctxlua{xml.registerns("#1","#2")}} % document \def\xmlremapname #1#2#3#4{\ctxlua{xml.remapname(lxml.id("#1"),"#2","#3","#4")}} % element -\def\xmlremapnamespace #1#2#3{\ctxlua{xml.rename_space(lxml.id("#1"),"#2","#3")}} % document -\def\xmlchecknamespace #1#2#3{\ctxlua{xml.check_namespace(lxml.id("#1"),"#2","#3")}} % element +\def\xmlremapnamespace #1#2#3{\ctxlua{xml.renamespace(lxml.id("#1"),"#2","#3")}} % document +\def\xmlchecknamespace #1#2#3{\ctxlua{xml.checknamespace(lxml.id("#1"),"#2","#3")}} % element \def\xmlsetfunction #1#2#3{\ctxlua{lxml.setaction("#1","#2",#3)}} \def\xmlsetsetup #1#2#3{\ctxlua{lxml.setsetup("#1","#2","#3")}} \def\xmlstrip #1#2{\ctxlua{lxml.strip("#1","#2")}} @@ -263,9 +263,9 @@ \def\inlinemessage #1{\dontleavehmode{\tttf#1}} \def\displaymessage#1{\blank\inlinemessage{#1}\blank} -\def\xmltraceentities - {\ctxlua{xml.set_text_cleanup(lxml.trace_text_entities)}% - \appendtoks\ctxlua{lxml.show_text_entities()}\to\everygoodbye} +% \def\xmltraceentities % settextcleanup is not defined +% {\ctxlua{xml.settextcleanup(lxml.trace_text_entities)}% +% \appendtoks\ctxlua{lxml.showtextentities()}\to\everygoodbye} % processing instructions @@ -296,9 +296,9 @@ {\ifcase\xmlprocessingmode % unset \or - \ctxlua{lxml.set_command_to_text("#1")}% 1 + \ctxlua{lxml.setcommandtotext("#1")}% 1 \or - \ctxlua{lxml.set_command_to_none("#1")}% 2 + \ctxlua{lxml.setcommandtonone("#1")}% 2 \else % unset \fi} @@ -353,8 +353,8 @@ \let\isolatedentity\firstofoneargument -\def\xmlsetentity#1#2{\ctxlua{xml.register_entity('#1',\!!bs\detokenize{#2}\!!es)}} -\def\xmltexentity#1#2{\ctxlua{xml.register_entity('#1',\!!bs\detokenize{\isolatedentity{#2}}\!!es)}} +\def\xmlsetentity#1#2{\ctxlua{xml.registerentity('#1',\!!bs\detokenize{#2}\!!es)}} +\def\xmltexentity#1#2{\ctxlua{xml.registerentity('#1',\!!bs\detokenize{\isolatedentity{#2}}\!!es)}} % \xmlsetentity{tex}{\TEX{}} % {} needed @@ -405,7 +405,7 @@ % \stopextendcatcodetable % % \ctxlua { % entities are remembered in the format -% characters.remapentity("<",characters.active_offset + utf.byte("<")) -% characters.remapentity("&",characters.active_offset + utf.byte("&")) -% characters.remapentity(">",characters.active_offset + utf.byte(">")) +% characters.remapentity("<",characters.activeoffset + utf.byte("<")) +% characters.remapentity("&",characters.activeoffset + utf.byte("&")) +% characters.remapentity(">",characters.activeoffset + utf.byte(">")) % } diff --git a/tex/context/base/lxml-lpt.lua b/tex/context/base/lxml-lpt.lua index 2db7a4a23..954e72194 100644 --- a/tex/context/base/lxml-lpt.lua +++ b/tex/context/base/lxml-lpt.lua @@ -11,7 +11,7 @@ if not modules then modules = { } end modules ['lxml-pth'] = { local concat, remove, insert = table.concat, table.remove, table.insert local type, next, tonumber, tostring, setmetatable, loadstring = type, next, tonumber, tostring, setmetatable, loadstring local format, upper, lower, gmatch, gsub, find, rep = string.format, string.upper, string.lower, string.gmatch, string.gsub, string.find, string.rep -local lpegmatch = lpeg.match +local lpegmatch, lpegpatterns = lpeg.match, lpeg.patterns -- beware, this is not xpath ... e.g. position is different (currently) and -- we have reverse-sibling as reversed preceding sibling @@ -56,14 +56,20 @@ local xml = xml local lpathcalls = 0 function xml.lpathcalls () return lpathcalls end local lpathcached = 0 function xml.lpathcached() return lpathcached end -xml.functions = xml.functions or { } -- internal -xml.expressions = xml.expressions or { } -- in expressions -xml.finalizers = xml.finalizers or { } -- fast do-with ... (with return value other than collection) -xml.specialhandler = xml.specialhandler or { } +xml.functions = xml.functions or { } -- internal +local functions = xml.functions -local functions = xml.functions -local expressions = xml.expressions -local finalizers = xml.finalizers +xml.expressions = xml.expressions or { } -- in expressions +local expressions = xml.expressions + +xml.finalizers = xml.finalizers or { } -- fast do-with ... (with return value other than collection) +local finalizers = xml.finalizers + +xml.specialhandler = xml.specialhandler or { } +local specialhandler = xml.specialhandler + +lpegpatterns.xml = lpegpatterns.xml or { } +local xmlpatterns = lpegpatterns.xml finalizers.xml = finalizers.xml or { } finalizers.tex = finalizers.tex or { } @@ -676,7 +682,7 @@ local special_1 = P("*") * Cc(register_auto_descendant) * Cc(register_all_nodes local special_2 = P("/") * Cc(register_auto_self) local special_3 = P("") * Cc(register_auto_self) -local parser = Ct { "patterns", -- can be made a bit faster by moving pattern outside +local pathparser = Ct { "patterns", -- can be made a bit faster by moving pattern outside patterns = spaces * V("protocol") * spaces * ( ( V("special") * spaces * P(-1) ) + @@ -748,6 +754,8 @@ local parser = Ct { "patterns", -- can be made a bit faster by moving pattern ou } +xmlpatterns.pathparser = pathparser + local cache = { } local function nodesettostring(set,nodetest) @@ -784,11 +792,11 @@ end xml.nodesettostring = nodesettostring -local parse_pattern -- we have a harmless kind of circular reference +local lpath -- we have a harmless kind of circular reference local function lshow(parsed) if type(parsed) == "string" then - parsed = parse_pattern(parsed) + parsed = lpath(parsed) end local s = table.serialize_functions -- ugly table.serialize_functions = false -- ugly @@ -807,7 +815,7 @@ local function add_comment(p,str) end end -parse_pattern = function (pattern) -- the gain of caching is rather minimal +lpath = function (pattern) -- the gain of caching is rather minimal lpathcalls = lpathcalls + 1 if type(pattern) == "table" then return pattern @@ -816,7 +824,7 @@ parse_pattern = function (pattern) -- the gain of caching is rather minimal if parsed then lpathcached = lpathcached + 1 else - parsed = lpegmatch(parser,pattern) + parsed = lpegmatch(pathparser,pattern) if parsed then parsed.pattern = pattern local np = #parsed @@ -864,6 +872,8 @@ parse_pattern = function (pattern) -- the gain of caching is rather minimal end end +xml.lpath = lpath + -- we can move all calls inline and then merge the trace back -- technically we can combine axis and the next nodes which is -- what we did before but this a bit cleaner (but slower too) @@ -988,7 +998,7 @@ local function normal_apply(list,parsed,nofparsed,order) return collected end -local function parse_apply(list,pattern) +local function applylpath(list,pattern) -- we avoid an extra call local parsed = cache[pattern] if parsed then @@ -998,7 +1008,7 @@ local function parse_apply(list,pattern) lpathcalls = lpathcalls + 1 parsed = pattern else - parsed = parse_pattern(pattern) or pattern + parsed = lpath(pattern) or pattern end if not parsed then return @@ -1007,7 +1017,7 @@ local function parse_apply(list,pattern) if nofparsed == 0 then return -- something is wrong end - local one = list[1] + local one = list[1] -- we could have a third argument: isroot and list or list[1] or whatever we like ... todo if not one then return -- something is wrong elseif not trace_lpath then @@ -1019,13 +1029,15 @@ local function parse_apply(list,pattern) end end +xml.applylpath = applylpath -- takes a table as first argment, which is what xml.filter will do + -- internal (parsed) expressions.child = function(e,pattern) - return parse_apply({ e },pattern) -- todo: cache + return applylpath({ e },pattern) -- todo: cache end expressions.count = function(e,pattern) - local collected = parse_apply({ e },pattern) -- todo: cache + local collected = applylpath({ e },pattern) -- todo: cache return (collected and #collected) or 0 end @@ -1035,7 +1047,7 @@ expressions.oneof = function(s,...) -- slow local t = {...} for i=1,#t do if s == t[i] then return true end end return false end expressions.error = function(str) - xml.error_handler("unknown function in lpath expression",tostring(str or "?")) + xml.errorhandler("unknown function in lpath expression",tostring(str or "?")) return false end expressions.undefined = function(s) @@ -1065,7 +1077,7 @@ expressions.boolean = toboolean local function traverse(root,pattern,handle) report_lpath("use 'xml.selection' instead for '%s'",pattern) - local collected = parse_apply({ root },pattern) + local collected = applylpath({ root },pattern) if collected then for c=1,#collected do local e = collected[c] @@ -1076,7 +1088,7 @@ local function traverse(root,pattern,handle) end local function selection(root,pattern,handle) - local collected = parse_apply({ root },pattern) + local collected = applylpath({ root },pattern) if collected then if handle then for c=1,#collected do @@ -1088,19 +1100,12 @@ local function selection(root,pattern,handle) end end -xml.parse_parser = parser -xml.parse_pattern = parse_pattern -xml.parse_apply = parse_apply xml.traverse = traverse -- old method, r, d, k xml.selection = selection -- new method, simple handle -local lpath = parse_pattern - -xml.lpath = lpath - -function xml.cached_patterns() - return cache -end +--~ function xml.cachedpatterns() +--~ return cache +--~ end -- generic function finalizer (independant namespace) @@ -1117,8 +1122,8 @@ local function dofunction(collected,fnc) end end -xml.finalizers.xml["function"] = dofunction -xml.finalizers.tex["function"] = dofunction +finalizers.xml["function"] = dofunction +finalizers.tex["function"] = dofunction -- functions @@ -1215,7 +1220,7 @@ end --ldx]]-- function xml.filter(root,pattern) -- no longer funny attribute handling here - return parse_apply({ root },pattern) + return applylpath({ root },pattern) end --[[ldx-- @@ -1237,7 +1242,7 @@ end local wrap, yield = coroutine.wrap, coroutine.yield function xml.elements(root,pattern,reverse) -- r, d, k - local collected = parse_apply({ root },pattern) + local collected = applylpath({ root },pattern) if collected then if reverse then return wrap(function() for c=#collected,1,-1 do @@ -1253,7 +1258,7 @@ function xml.elements(root,pattern,reverse) -- r, d, k end function xml.collected(root,pattern,reverse) -- e - local collected = parse_apply({ root },pattern) + local collected = applylpath({ root },pattern) if collected then if reverse then return wrap(function() for c=#collected,1,-1 do yield(collected[c]) end end) diff --git a/tex/context/base/lxml-mis.lua b/tex/context/base/lxml-mis.lua index 78297b592..94a26b974 100644 --- a/tex/context/base/lxml-mis.lua +++ b/tex/context/base/lxml-mis.lua @@ -6,12 +6,16 @@ if not modules then modules = { } end modules ['lxml-mis'] = { license = "see context related readme files" } +local xml, lpeg, string = xml, lpeg, string + local concat = table.concat local type, next, tonumber, tostring, setmetatable, loadstring = type, next, tonumber, tostring, setmetatable, loadstring local format, gsub, match = string.format, string.gsub, string.match -local lpegmatch = lpeg.match +local lpegmatch, lpegpatterns = lpeg.match, lpeg.patterns +local P, S, R, C, V, Cc, Cs = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V, lpeg.Cc, lpeg.Cs -local xml = xml +lpegpatterns.xml = lpegpatterns.xml or { } +local xmlpatterns = lpegpatterns.xml --[[ldx-- <p>The following helper functions best belong to the <t>lxml-ini</t> @@ -37,7 +41,7 @@ end --~ xml.gsub = xmlgsub -function xml.strip_leading_spaces(dk,d,k) -- cosmetic, for manual +function xml.stripleadingspaces(dk,d,k) -- cosmetic, for manual if d and k then local dkm = d[k-1] if dkm and type(dkm) == "string" then @@ -54,8 +58,6 @@ end --~ function xml.unescaped(str) return (gsub(str,"(&.-;)", xml.unescapes)) end --~ function xml.cleansed (str) return (gsub(str,"<.->" , '' )) end -- "%b<>" -local P, S, R, C, V, Cc, Cs = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.V, lpeg.Cc, lpeg.Cs - -- 100 * 2500 * "oeps< oeps> oeps&" : gsub:lpeg|lpeg|lpeg -- -- 1021:0335:0287:0247 @@ -80,9 +82,9 @@ local unescaped = Cs(normal * (special * normal)^0) local cleansed = Cs(((P("<") * (1-P(">"))^0 * P(">"))/"" + 1)^0) -xml.escaped_pattern = escaped -xml.unescaped_pattern = unescaped -xml.cleansed_pattern = cleansed +xmlpatterns.escaped = escaped +xmlpatterns.unescaped = unescaped +xmlpatterns.cleansed = cleansed function xml.escaped (str) return lpegmatch(escaped,str) end function xml.unescaped(str) return lpegmatch(unescaped,str) end diff --git a/tex/context/base/lxml-tab.lua b/tex/context/base/lxml-tab.lua index e368764ad..270c83e5a 100644 --- a/tex/context/base/lxml-tab.lua +++ b/tex/context/base/lxml-tab.lua @@ -161,8 +161,8 @@ function xml.setproperty(root,k,v) getmetatable(root).__index[k] = v end -function xml.check_error(top,toclose) - return "" +function xml.checkerror(top,toclose) + return "" -- can be set end local function add_attribute(namespace,tag,value) @@ -218,9 +218,9 @@ local function add_end(spacing, namespace, tag) local toclose = remove(stack) top = stack[#stack] if #stack < 1 then - errorstr = format("nothing to close with %s %s", tag, xml.check_error(top,toclose) or "") + errorstr = format("nothing to close with %s %s", tag, xml.checkerror(top,toclose) or "") elseif toclose.tg ~= tag then -- no namespace check - errorstr = format("unable to close %s with %s %s", toclose.tg, tag, xml.check_error(top,toclose) or "") + errorstr = format("unable to close %s with %s %s", toclose.tg, tag, xml.checkerror(top,toclose) or "") end dt = top.dt dt[#dt+1] = toclose @@ -272,9 +272,13 @@ local function attribute_specification_error(str) return str end -function xml.unknown_dec_entity_format(str) return (str == "" and "&error;") or format("&%s;",str) end -function xml.unknown_hex_entity_format(str) return format("&#x%s;",str) end -function xml.unknown_any_entity_format(str) return format("&#x%s;",str) end +xml.placeholders = { + unknown_dec_entity = function(str) return (str == "" and "&error;") or format("&%s;",str) end, + unknown_hex_entity = function(str) return format("&#x%s;",str) end, + unknown_any_entity = function(str) return format("&#x%s;",str) end, +} + +local placeholders = xml.placeholders local function fromhex(s) local n = tonumber(s,16) @@ -331,7 +335,7 @@ local function handle_hex_entity(str) report_xml("utfize, converting hex entity &#x%s; into %s",str,h) end elseif utfize then - h = (n and utfchar(n)) or xml.unknown_hex_entity_format(str) or "" + h = (n and utfchar(n)) or xml.unknown_hex_entity(str) or "" if not n then report_xml("utfize, ignoring hex entity &#x%s;",str) elseif trace_entities then @@ -358,7 +362,7 @@ local function handle_dec_entity(str) report_xml("utfize, converting dec entity &#%s; into %s",str,d) end elseif utfize then - d = (n and utfchar(n)) or xml.unknown_dec_entity_format(str) or "" + d = (n and utfchar(n)) or placeholders.unknown_dec_entity(str) or "" if not n then report_xml("utfize, ignoring dec entity &#%s;",str) elseif trace_entities then @@ -395,8 +399,9 @@ local function handle_any_entity(str) end a = lpegmatch(parsedentity,a) or a else - if xml.unknown_any_entity_format then - a = xml.unknown_any_entity_format(str) or "" + local unknown_any_entity = placeholders.unknown_any_entity + if unknown_any_entity then + a = unknown_any_entity(str) or "" end if a then if trace_entities then @@ -611,13 +616,13 @@ local function xmlconvert(data, settings) if errorstr and errorstr ~= "" then result = { dt = { { ns = "", tg = "error", dt = { errorstr }, at={ }, er = true } } } setmetatable(stack, mt) - local error_handler = settings.error_handler - if error_handler == false then + local errorhandler = settings.error_handler + if errorhandler == false then -- no error message else - error_handler = error_handler or xml.error_handler - if error_handler then - xml.error_handler("load",errorstr) + errorhandler = errorhandler or xml.errorhandler + if errorhandler then + xml.errorhandler("load",errorstr) end end else @@ -677,7 +682,7 @@ function xml.is_valid(root) return root and not root.error end -xml.error_handler = (logs and logs.report) or (input and logs.report) or print +xml.errorhandler = (logs and logs.report) or (input and logs.report) or print --[[ldx-- <p>We cannot load an <l n='lpeg'/> from a filehandle so we need to load diff --git a/tex/context/base/lxml-tex.lua b/tex/context/base/lxml-tex.lua index 6aef2fc24..19614770e 100644 --- a/tex/context/base/lxml-tex.lua +++ b/tex/context/base/lxml-tex.lua @@ -36,8 +36,9 @@ local texsprint, texprint, texwrite = tex.sprint, tex.print, tex.write local texcatcodes, ctxcatcodes, vrbcatcodes, notcatcodes = tex.texcatcodes, tex.ctxcatcodes, tex.vrbcatcodes, tex.notcatcodes local xmlelements, xmlcollected, xmlsetproperty = xml.elements, xml.collected, xml.setproperty -local xmlparseapply, xmlwithelements = xml.parse_apply, xml.withelements +local xmlwithelements = xml.withelements local xmlserialize, xmlcollect, xmltext, xmltostring = xml.serialize, xml.collect, xml.text, xml.tostring +local xmlapplylpath = xml.applylpath local variables = (interfaces and interfaces.variables) or { } @@ -80,14 +81,14 @@ local xmltextcapture = ( space^0 * newline^2 * Cc("") / texprint + -- better ^-2 ? space^0 * newline * space^0 * Cc(" ") / texsprint + content / function(str) return texsprint(notcatcodes,str) end + -- was just texsprint, current catcodes regime is notcatcodes - entity / xml.resolved_entity + entity / xml.resolvedentity )^0 local ctxtextcapture = ( space^0 * newline^2 * Cc("") / texprint + -- better ^-2 ? space^0 * newline * space^0 * Cc(" ") / texsprint + content / function(str) return texsprint(ctxcatcodes,str) end + -- was just texsprint, current catcodes regime is notcatcodes - entity / xml.resolved_entity + entity / xml.resolvedentity )^0 local forceraw, rawroot = false, nil @@ -142,23 +143,23 @@ local function toverbatim(str) if aftercommand then texsprint(texcatcodes,aftercommand,"{}") end end -function lxml.set_verbatim(before,after,obeyedline,obeyedspace) +function lxml.setverbatim(before,after,obeyedline,obeyedspace) beforecommand, aftercommand, linecommand, spacecommand = before, after, obeyedline, obeyedspace end local obeycdata = true -function lxml.set_cdata() +function lxml.setcdata() obeycdata = true end -function lxml.reset_cdata() +function lxml.resetcdata() obeycdata = false end -- cdata and verbatim -lxml.set_verbatim("\\xmlcdatabefore", "\\xmlcdataafter", "\\xmlcdataobeyedline", "\\xmlcdataobeyedspace") +lxml.setverbatim("\\xmlcdatabefore", "\\xmlcdataafter", "\\xmlcdataobeyedline", "\\xmlcdataobeyedspace") -- local capture = (space^0*newline)^0 * capture * (space+newline)^0 * -1 @@ -194,7 +195,7 @@ function lxml.splitid(id) end end -local function get_id(id, qualified) +local function getid(id, qualified) if id then local lid = loaded[id] if lid then @@ -233,8 +234,8 @@ local function get_id(id, qualified) end end -lxml.id = get_id -lxml.get_id = get_id +lxml.id = getid -- we provide two names as locals can already use such +lxml.getid = getid -- names and we don't want clashes function lxml.root(id) return loaded[id] @@ -245,7 +246,7 @@ end local nofindices = 0 local function addindex(name,check_sum,force) - local root = get_id(name) + local root = getid(name) if root and (not root.index or force) then -- weird, only called once local n, index, maxindex, check = 0, root.index or { }, root.maxindex or 0, root.check or { } local function nest(root) @@ -284,27 +285,27 @@ lxml.addindex = addindex -- another cache -local function lxmlparseapply(id,pattern) -- better inline, saves call - return xmlparseapply({ get_id(id) }, pattern) +local function lxmlapplylpath(id,pattern) -- better inline, saves call + return xmlapplylpath({ getid(id) }, pattern) end -lxml.filter = lxmlparseapply +lxml.filter = lxmlapplylpath function lxml.filterlist(list,pattern) for s in gmatch(list,"[^, ]+") do -- we could cache a table - lxmlparseapply(s,pattern) + xmlapplylpath({ getid(s) }, pattern) end end lxml["function"] = function(id,name) local f = xml.functions[name] - return f and f(get_id(id)) + return f and f(getid(id)) end -- rather new, indexed storage (backward refs), maybe i will merge this function lxml.checkindex(name) - local root = get_id(name) + local root = getid(name) return (root and root.index) or 0 end @@ -381,7 +382,7 @@ end function lxml.include(id,pattern,attribute,recurse) starttiming(xml) - local root = get_id(id) + local root = getid(id) xml.include(root,pattern,attribute,recurse,function(filename) if filename then filename = commands.preparedfile(filename) @@ -553,7 +554,7 @@ function lxml.serialize(root) end function lxml.setaction(id,pattern,action) - local collected = lxmlparseapply(id,pattern) + local collected = xmlapplylpath({ getid(id) }, pattern) if collected then for c=1,#collected do collected[c].command = action @@ -619,7 +620,7 @@ xml.cprint = cprint local xmlcprint = cprint -- now we can flush function lxml.main(id) - xmlserialize(get_id(id),xmltexhandler) -- the real root (@rt@) + xmlserialize(getid(id),xmltexhandler) -- the real root (@rt@) end --~ -- lines (untested) @@ -675,12 +676,12 @@ end local setups = { } -function lxml.set_command_to_text(id) - xmlwithelements(get_id(id),to_text) +function lxml.setcommandtotext(id) + xmlwithelements(getid(id),to_text) end -function lxml.set_command_to_none(id) - xmlwithelements(get_id(id),to_none) +function lxml.setcommandtonone(id) + xmlwithelements(getid(id),to_none) end function lxml.installsetup(what,document,setup,where) @@ -704,12 +705,12 @@ function lxml.installsetup(what,document,setup,where) if trace_loading then commands.writestatus("lxml","inserting setup %s for %s before %s",setup,document,where) end - table.insert_before_value(sd,setup,where) + table.insertbeforevalue(sd,setup,where) elseif what == 4 then if trace_loading then commands.writestatus("lxml","inserting setup %s for %s after %s",setup,document,where) end - table.insert_after_value(sd,setup,where) + table.insertaftervalue(sd,setup,where) end end @@ -759,7 +760,7 @@ end function lxml.setsetup(id,pattern,setup) if not setup or setup == "" or setup == "*" or setup == "-" or setup == "+" then - local collected = lxmlparseapply(id,pattern) + local collected = xmlapplylpath({ getid(id) }, pattern) if collected then if trace_setups then for c=1, #collected do @@ -802,7 +803,7 @@ function lxml.setsetup(id,pattern,setup) else local a, b = match(setup,"^(.+:)([%*%-])$") if a and b then - local collected = lxmlparseapply(id,pattern) + local collected = xmlapplylpath({ getid(id) }, pattern) if collected then if trace_setups then for c=1, #collected do @@ -847,7 +848,7 @@ function lxml.setsetup(id,pattern,setup) report_lxml("no lpath matches for %s",pattern) end else - local collected = lxmlparseapply(id,pattern) + local collected = xmlapplylpath({ getid(id) }, pattern) if collected then if trace_setups then for c=1, #collected do @@ -1134,7 +1135,7 @@ end -- local function verbatim(id,before,after) - local root = get_id(id) + local root = getid(id) if root then if before then texsprint(ctxcatcodes,before,"[",root.tg or "?","]") end lxml.toverbatim(xmltostring(root.dt)) @@ -1153,21 +1154,21 @@ lxml.verbatim = verbatim -- helpers function lxml.first(id,pattern) - local collected = lxmlparseapply(id,pattern) + local collected = xmlapplylpath({ getid(id) }, pattern) if collected then first(collected) end end function lxml.last(id,pattern) - local collected = lxmlparseapply(id,pattern) + local collected = xmlapplylpath({ getid(id) }, pattern) if collected then last(collected) end end function lxml.all(id,pattern) - local collected = lxmlparseapply(id,pattern) + local collected = xmlapplylpath({ getid(id) }, pattern) if collected then all(collected) end @@ -1175,18 +1176,18 @@ end function lxml.count(id,pattern) -- always needs to produce a result so no test here - count(lxmlparseapply(id,pattern)) + count(xmlapplylpath({ getid(id) }, pattern)) end function lxml.attribute(id,pattern,a,default) - local collected = lxmlparseapply(id,pattern) + local collected = xmlapplylpath({ getid(id) }, pattern) if collected then attribute(collected,a,default) end end function lxml.raw(id,pattern) -- the content, untouched by commands - local collected = (pattern and lxmlparseapply(id,pattern)) or get_id(id) + local collected = (pattern and xmlapplylpath({ getid(id) }, pattern)) or getid(id) if collected then texsprint(xmltostring(collected[1].dt)) end @@ -1194,11 +1195,11 @@ end function lxml.context(id,pattern) -- the content, untouched by commands if not pattern then - local collected = get_id(id) + local collected = getid(id) -- texsprint(ctxcatcodes,collected.dt[1]) ctx_text(collected.dt[1]) else - local collected = lxmlparseapply(id,pattern) or get_id(id) + local collected = xmlapplylpath({ getid(id) }, pattern) or getid(id) if collected and #collected > 0 then texsprint(ctxcatcodes,collected[1].dt) end @@ -1206,7 +1207,7 @@ function lxml.context(id,pattern) -- the content, untouched by commands end function lxml.text(id,pattern) - local collected = (pattern and lxmlparseapply(id,pattern)) or get_id(id) + local collected = (pattern and xmlapplylpath({ getid(id) }, pattern)) or getid(id) if collected then text(collected) end @@ -1215,40 +1216,40 @@ end lxml.content = text function lxml.position(id,pattern,n) - local collected = lxmlparseapply(id,pattern) + local collected = xmlapplylpath({ getid(id) }, pattern) if collected then position(collected,n) end end function lxml.chainattribute(id,pattern,a,default) - local collected = lxmlparseapply(id,pattern) + local collected = xmlapplylpath({ getid(id) }, pattern) if collected then chainattribute(collected,a,default) end end function lxml.concatrange(id,pattern,start,stop,separator,lastseparator,textonly) -- test this on mml - concatrange(lxmlparseapply(id,pattern),start,stop,separator,lastseparator,textonly) + concatrange(xmlapplylpath({ getid(id) }, pattern),start,stop,separator,lastseparator,textonly) end function lxml.concat(id,pattern,separator,lastseparator,textonly) - concatrange(lxmlparseapply(id,pattern),false,false,separator,lastseparator,textonly) + concatrange(xmlapplylpath({ getid(id) }, pattern),false,false,separator,lastseparator,textonly) end function lxml.element(id,n) - position(lxmlparseapply(id,"/*"),n) + position(xmlapplylpath({ getid(id) },"/*"),n) end lxml.index = lxml.position function lxml.pos(id) - local root = get_id(id) + local root = getid(id) texwrite((root and root.ni) or 0) end function lxml.att(id,a,default) - local root = get_id(id) + local root = getid(id) if root then local at = root.at local str = (at and at[a]) or default @@ -1261,7 +1262,7 @@ function lxml.att(id,a,default) end function lxml.name(id) -- or remapped name? -> lxml.info, combine - local r = get_id(id) + local r = getid(id) local ns = r.rn or r.ns or "" if ns ~= "" then texsprint(ns,":",r.tg) @@ -1271,20 +1272,20 @@ function lxml.name(id) -- or remapped name? -> lxml.info, combine end function lxml.match(id) -- or remapped name? -> lxml.info, combine - texsprint(get_id(id).mi or 0) + texsprint(getid(id).mi or 0) end function lxml.tag(id) -- tag vs name -> also in l-xml tag->name - texsprint(get_id(id).tg or "") + texsprint(getid(id).tg or "") end function lxml.namespace(id) -- or remapped name? - local root = get_id(id) + local root = getid(id) texsprint(root.rn or root.ns or "") end function lxml.flush(id) - id = get_id(id) + id = getid(id) local dt = id and id.dt if dt then xmlsprint(dt) @@ -1292,7 +1293,7 @@ function lxml.flush(id) end function lxml.snippet(id,i) - local e = get_id(id) + local e = getid(id) if e then local edt = e.dt if edt then @@ -1302,12 +1303,12 @@ function lxml.snippet(id,i) end function lxml.direct(id) - xmlsprint(get_id(id)) + xmlsprint(getid(id)) end function lxml.command(id,pattern,cmd) - local i, p = get_id(id,true) - local collected = lxmlparseapply(i,pattern) + local i, p = getid(id,true) + local collected = xmlapplylpath({ getid(i) }, pattern) if collected then local rootname = p or i.name for c=1,#collected do @@ -1325,11 +1326,11 @@ end -- loops function lxml.collected(id,pattern,reverse) - return xmlcollected(get_id(id),pattern,reverse) + return xmlcollected(getid(id),pattern,reverse) end function lxml.elements(id,pattern,reverse) - return xmlelements(get_id(id),pattern,reverse) + return xmlelements(getid(id),pattern,reverse) end -- obscure ones @@ -1342,16 +1343,16 @@ local found, empty = xml.found, xml.empty local doif, doifnot, doifelse = commands.doif, commands.doifnot, commands.doifelse -function lxml.doif (id,pattern) doif (found(get_id(id),pattern)) end -function lxml.doifnot (id,pattern) doifnot (found(get_id(id),pattern)) end -function lxml.doifelse (id,pattern) doifelse(found(get_id(id),pattern)) end -function lxml.doiftext (id,pattern) doif (not empty(get_id(id),pattern)) end -function lxml.doifnottext (id,pattern) doifnot (not empty(get_id(id),pattern)) end -function lxml.doifelsetext (id,pattern) doifelse(not empty(get_id(id),pattern)) end +function lxml.doif (id,pattern) doif (found(getid(id),pattern)) end +function lxml.doifnot (id,pattern) doifnot (found(getid(id),pattern)) end +function lxml.doifelse (id,pattern) doifelse(found(getid(id),pattern)) end +function lxml.doiftext (id,pattern) doif (not empty(getid(id),pattern)) end +function lxml.doifnottext (id,pattern) doifnot (not empty(getid(id),pattern)) end +function lxml.doifelsetext (id,pattern) doifelse(not empty(getid(id),pattern)) end -- special case: "*" and "" -> self else lpath lookup ---~ function lxml.doifelseempty(id,pattern) doifelse(isempty(get_id(id),pattern ~= "" and pattern ~= nil)) end -- not yet done, pattern +--~ function lxml.doifelseempty(id,pattern) doifelse(isempty(getid(id),pattern ~= "" and pattern ~= nil)) end -- not yet done, pattern -- status info @@ -1397,15 +1398,15 @@ end) -- misc function lxml.nonspace(id,pattern) -- slow, todo loop - xmltprint(xmlcollect(get_id(id),pattern,true)) + xmltprint(xmlcollect(getid(id),pattern,true)) end function lxml.strip(id,pattern,nolines,anywhere) - xml.strip(get_id(id),pattern,nolines,anywhere) + xml.strip(getid(id),pattern,nolines,anywhere) end function lxml.stripped(id,pattern,nolines) - local str = xmltext(get_id(id),pattern) or "" + local str = xmltext(getid(id),pattern) or "" str = gsub(str,"^%s*(.-)%s*$","%1") if nolines then str = gsub(str,"%s+"," ") @@ -1414,5 +1415,9 @@ function lxml.stripped(id,pattern,nolines) end function lxml.delete(id,pattern) - xml.delete(get_id(id),pattern) + xml.delete(getid(id),pattern) end + +lxml.obsolete = { } + +lxml.get_id = getid lxml.obsolete.get_id = getid diff --git a/tex/context/base/m-punk.mkiv b/tex/context/base/m-punk.mkiv index 5b1486c81..7d8815c4b 100644 --- a/tex/context/base/m-punk.mkiv +++ b/tex/context/base/m-punk.mkiv @@ -97,7 +97,7 @@ function metapost.characters.process(mpxformat, name, instances, scalefactor) -- we can use a format per font local data = io.loaddata(resolvers.find_file(name)) metapost.reset(mpxformat) - metapost.set_outer_color(2) -- no outer color and no reset either + metapost.setoutercolor(2) -- no outer color and no reset either lists = { } for i=1,instances do characters, descriptions = { }, { } diff --git a/tex/context/base/m-timing.tex b/tex/context/base/m-timing.tex index 55185b0b2..e5c315c74 100644 --- a/tex/context/base/m-timing.tex +++ b/tex/context/base/m-timing.tex @@ -53,7 +53,7 @@ end \startnotmode[no-timing] \appendtoks\ctxlua{moduledata.progress.store()}\to\everystarttext \appendtoks\ctxlua{moduledata.progress.store()}\to\everyshipout - \ctxlua{luatex.register_stop_actions(function() moduledata.progress.save() end)} + \ctxlua{luatex.registerstopactions(function() moduledata.progress.save() end)} \stopnotmode \def\ShowNamedUsage#1#2#3% diff --git a/tex/context/base/math-def.mkiv b/tex/context/base/math-def.mkiv index af7166f80..ce6bdb23d 100644 --- a/tex/context/base/math-def.mkiv +++ b/tex/context/base/math-def.mkiv @@ -19,7 +19,7 @@ \startluacode mathematics.define() - mathematics.register_xml_entities() + mathematics.xml.registerentities() \stopluacode % special .. todo diff --git a/tex/context/base/math-ent.lua b/tex/context/base/math-ent.lua index d387f9ee5..53a68ab0f 100644 --- a/tex/context/base/math-ent.lua +++ b/tex/context/base/math-ent.lua @@ -7,7 +7,7 @@ if not modules then modules = { } end modules ['math-ent'] = { -- this might go into char-def -mathematics.entities={ +mathematics.xml.entities={ ["Aacute"]=0x000C1, ["aacute"]=0x000E1, ["Abreve"]=0x00102, @@ -2100,5 +2100,4 @@ mathematics.entities={ ["plusminus"]=0x000B1, ["minusplus"]=0x02213, ["cdots"]=0x2026, - } diff --git a/tex/context/base/math-ini.lua b/tex/context/base/math-ini.lua index 73a6725bb..9efc8ce64 100644 --- a/tex/context/base/math-ini.lua +++ b/tex/context/base/math-ini.lua @@ -273,11 +273,13 @@ function mathematics.utfmathfiller(chr, default) tex.sprint(cmd or default or "") end -mathematics.entities = mathematics.entities or { } +-- xml -function mathematics.register_xml_entities() +mathematics.xml = { entities = { } } + +function mathematics.xml.registerentities() local entities = xml.entities - for name, unicode in next, mathematics.entities do + for name, unicode in next, mathematics.xml.entities do if not entities[name] then entities[name] = utfchar(unicode) end diff --git a/tex/context/base/math-ini.mkiv b/tex/context/base/math-ini.mkiv index 729e10443..203d88156 100644 --- a/tex/context/base/math-ini.mkiv +++ b/tex/context/base/math-ini.mkiv @@ -73,9 +73,9 @@ \let\mathgreeknormal\mathgreekupright \let\mathgreeknone \mathgreekdefault -\def\setmathattribute#1#2{\ifmmode\ctxlua{mathematics.sync_a_both ("#1","#2")}\fi} -\def\setmathalphabet #1{\ifmmode\ctxlua{mathematics.sync_a_name ("#1")}\fi} -\def\setmathstyle #1{\ifmmode\ctxlua{mathematics.sync_a_style("#1")}\fi} +\def\setmathattribute#1#2{\ifmmode\ctxlua{mathematics.syncboth ("#1","#2")}\fi} +\def\setmathalphabet #1{\ifmmode\ctxlua{mathematics.syncname ("#1")}\fi} +\def\setmathstyle #1{\ifmmode\ctxlua{mathematics.syncstyle("#1")}\fi} \unexpanded\def\mr {\setmathattribute{regular}{tf}} diff --git a/tex/context/base/math-map.lua b/tex/context/base/math-map.lua index 9b1a925cd..0a3611cca 100644 --- a/tex/context/base/math-map.lua +++ b/tex/context/base/math-map.lua @@ -347,12 +347,12 @@ alphabets.serif = alphabets.regular alphabets.type = alphabets.monospaced alphabets.teletype = alphabets.monospaced -function mathematics.to_a_style(attribute) +function mathematics.tostyle(attribute) local r = mathremap[attribute] return r and r.style or "tf" end -function mathematics.to_a_name(attribute) +function mathematics.toname(attribute) local r = mathremap[attribute] return r and r.alphabet or "regular" end @@ -361,13 +361,13 @@ end local mathalphabet = attributes.private("mathalphabet") -function mathematics.sync_a_both(alphabet,style) +function mathematics.syncboth(alphabet,style) local data = alphabets[alphabet or "regular"] or alphabets.regular data = data[style or "tf"] or data.tf texattribute[mathalphabet] = data and data.attribute or texattribute[mathalphabet] end -function mathematics.sync_a_style(style) +function mathematics.syncstyle(style) --~ local r = mathremap[mathalphabet] local r = mathremap[texattribute[mathalphabet]] local alphabet = r and r.alphabet or "regular" @@ -375,7 +375,7 @@ function mathematics.sync_a_style(style) texattribute[mathalphabet] = data and data.attribute or texattribute[mathalphabet] end -function mathematics.sync_a_name(alphabet) +function mathematics.syncname(alphabet) --~ local r = mathremap[mathalphabet] local r = mathremap[texattribute[mathalphabet]] local style = r and r.style or "tf" @@ -393,7 +393,7 @@ local remapping = { [3] = { what = "italic", tf = "it", bf = "bi" }, -- italic } -function mathematics.remap_alphabets(char,mathalphabet,mathgreek) +function mathematics.remapalphabets(char,mathalphabet,mathgreek) if mathgreek > 0 then local lc, uc = floor(mathgreek/10), mathgreek % 10 -- 2 == upright 3 == italic if lc > 1 or uc > 1 then diff --git a/tex/context/base/math-noa.lua b/tex/context/base/math-noa.lua index cb0b7a1e6..50052c65c 100644 --- a/tex/context/base/math-noa.lua +++ b/tex/context/base/math-noa.lua @@ -130,7 +130,7 @@ local function report_remap(tag,id,old,new,extra) report_noads("remapping %s in font %s from U+%04X (%s) to U+%04X (%s)%s",tag,id,old,utfchar(old),new,utfchar(new),extra or "") end -local remap_alphabets = mathematics.remap_alphabets +local remapalphabets = mathematics.remapalphabets local fcs = fonts.color.set -- we can have a global famdata == fonts.famdata and chrdata == fonts.chrdata @@ -171,7 +171,7 @@ processors.relocate[math_char] = function(pointer) set_attribute(pointer,mathalphabet,0) end local char = pointer.char - local newchar = remap_alphabets(char,a,g) + local newchar = remapalphabets(char,a,g) if newchar then local fam = pointer.fam local id = font_of_family(fam) @@ -346,7 +346,7 @@ table.insert(fonts.triggers,"mathalternates") fonts.initializers.base.otf.mathalternates = fonts.initializers.common.mathalternates fonts.initializers.node.otf.mathalternates = fonts.initializers.common.mathalternates -local get_alternate = fonts.otf.get_alternate +local getalternate = fonts.otf.getalternate local mathalternate = attributes.private("mathalternate") @@ -370,7 +370,7 @@ alternate[math_char] = function(pointer) local mathalternatesattributes = tfmdata.shared.mathalternatesattributes if mathalternatesattributes then local what = mathalternatesattributes[a] - local alt = get_alternate(tfmdata,pointer.char,what.feature,what.value) + local alt = getalternate(tfmdata,pointer.char,what.feature,what.value) if alt then pointer.char = alt end diff --git a/tex/context/base/math-vfu.lua b/tex/context/base/math-vfu.lua index 71eb6c76e..9213ab6ee 100644 --- a/tex/context/base/math-vfu.lua +++ b/tex/context/base/math-vfu.lua @@ -690,7 +690,7 @@ function fonts.vf.math.define(specification,set) return main end -function mathematics.make_font(name, set) +function mathematics.makefont(name, set) fonts.define.methods[name] = function(specification) return fonts.vf.math.define(specification,set) end diff --git a/tex/context/base/meta-ini.mkii b/tex/context/base/meta-ini.mkii index e7c6d218e..c7bad9ebf 100644 --- a/tex/context/base/meta-ini.mkii +++ b/tex/context/base/meta-ini.mkii @@ -612,10 +612,10 @@ \def\initializeMPgraphics {\bgroup \initializeMPgraphicfile - \ifx\bufferprefix\empty\else - \let\bufferprefix\empty - \initializeMPgraphicfile - \fi +% \ifx\bufferprefix\empty\else +% \let\bufferprefix\empty +% \initializeMPgraphicfile +% \fi \egroup} %D Loading specific \METAPOST\ related definitions is diff --git a/tex/context/base/meta-ini.mkiv b/tex/context/base/meta-ini.mkiv index 3d1d87b1c..adc2e5aac 100644 --- a/tex/context/base/meta-ini.mkiv +++ b/tex/context/base/meta-ini.mkiv @@ -1234,7 +1234,7 @@ % can be faster, just \appendtoks - \ctxlua{metapost.set_outer_color(\number\MPcolormethod,\number\currentcolormodel,\number\dogetattribute{color},\number\dogetattribute{transparency})}% + \ctxlua{metapost.setoutercolor(\number\MPcolormethod,\number\currentcolormodel,\number\dogetattribute{color},\number\dogetattribute{transparency})}% \to \everyMPgraphic \startMPinitializations diff --git a/tex/context/base/metatex.tex b/tex/context/base/metatex.tex index d99f75ead..8f149d2e5 100644 --- a/tex/context/base/metatex.tex +++ b/tex/context/base/metatex.tex @@ -155,6 +155,12 @@ \pdfoutput\plusone +% too + +\appendtoks + \ctxlua{statistics.savefmtstatus("\jobname","\metatexversion","metatex.tex")}% can become automatic +\to \everydump + % done \errorstopmode \dump \endinput diff --git a/tex/context/base/mlib-pdf.lua b/tex/context/base/mlib-pdf.lua index 27e27eadb..a4f7f3137 100644 --- a/tex/context/base/mlib-pdf.lua +++ b/tex/context/base/mlib-pdf.lua @@ -69,7 +69,7 @@ local savedliterals = nil local mpsliteral = nodes.pool.register(node.new("whatsit",8)) -- pdfliteral -function metapost.flush_literal(d) -- \def\MPLIBtoPDF#1{\ctxlua{metapost.flush_literal(#1)}} +function metapost.flushliteral(d) -- \def\MPLIBtoPDF#1{\ctxlua{metapost.flush_literal(#1)}} if savedliterals then local literal = copy_node(mpsliteral) literal.data = savedliterals[d] @@ -79,7 +79,7 @@ function metapost.flush_literal(d) -- \def\MPLIBtoPDF#1{\ctxlua{metapost.flush_l end end -function metapost.flush_reset() +function metapost.flushreset() -- will become obsolete and internal savedliterals = nil end @@ -107,7 +107,7 @@ end function metapost.flushers.pdf.stopfigure(message) if message then metapost.flushers.pdf.comment(message) end texsprint(ctxcatcodes,"\\stopMPLIBtoPDF") - texsprint(ctxcatcodes,"\\ctxlua{metapost.flush_reset()}") -- maybe just at the beginning + texsprint(ctxcatcodes,"\\ctxlua{metapost.flushreset()}") -- maybe just at the beginning end function metapost.flushers.pdf.flushfigure(pdfliterals) -- table diff --git a/tex/context/base/mlib-pdf.mkiv b/tex/context/base/mlib-pdf.mkiv index 2e098730e..096c47cc6 100644 --- a/tex/context/base/mlib-pdf.mkiv +++ b/tex/context/base/mlib-pdf.mkiv @@ -15,7 +15,7 @@ \registerctxluafile{mlib-pdf}{1.001} -\def\MPLIBtoPDF#1{\ctxlua{metapost.flush_literal(#1)}} +\def\MPLIBtoPDF#1{\ctxlua{metapost.flushliteral(#1)}} \def\MPLIBboundingbox#1#2#3#4% {\xdef\MPllx{#1}% diff --git a/tex/context/base/mlib-pps.lua b/tex/context/base/mlib-pps.lua index 97b336a63..d930b8f9b 100644 --- a/tex/context/base/mlib-pps.lua +++ b/tex/context/base/mlib-pps.lua @@ -18,6 +18,8 @@ local lpegmatch = lpeg.match local texbox = tex.box local copy_list = node.copy_list +local P, S, V, Cs = lpeg.P, lpeg.S, lpeg.V, lpeg.Cs + local starttiming, stoptiming = statistics.starttiming, statistics.stoptiming local ctxcatcodes = tex.ctxcatcodes @@ -70,7 +72,7 @@ local registercolor, registerspotcolor = colors.register, colors.registerspotcol local transparencies = attributes.transparencies local registertransparency = transparencies.register -function metapost.set_outer_color(mode,colormodel,colorattribute,transparencyattribute) +function metapost.setoutercolor(mode,colormodel,colorattribute,transparencyattribute) -- has always to be called before conversion -- todo: transparency (not in the mood now) outercolormode = mode @@ -101,8 +103,6 @@ local function checked_color_pair(color) end end -metapost.checked_color_pair = checked_color_pair - function metapost.colorinitializer() innercolor = outercolor innertransparency = outertransparency @@ -391,15 +391,7 @@ metapost.multipass = false local textexts = { } -function metapost.free_boxes() -- todo: mp direct list ipv box - -- for i = metapost.first_box,metapost.last_box do - -- local b = texbox[i] - -- if b then - -- texbox[i] = nil -- no node.flush_list(b) needed, else double free error - -- else - -- break - -- end - -- end +local function free_boxes() -- todo: mp direct list ipv box for n, box in next, textexts do local tn = textexts[n] if tn then @@ -627,64 +619,58 @@ function metapost.colorconverter() return models[colors.model] or gray end -do +local btex = P("btex") +local etex = P(" etex") +local vtex = P("verbatimtex") +local ttex = P("textext") +local gtex = P("graphictext") +local multipass = P("forcemultipass") +local spacing = S(" \n\r\t\v")^0 +local dquote = P('"') - local P, S, V, Cs = lpeg.P, lpeg.S, lpeg.V, lpeg.Cs +local found, forced = false, false - local btex = P("btex") - local etex = P(" etex") - local vtex = P("verbatimtex") - local ttex = P("textext") - local gtex = P("graphictext") - local multipass = P("forcemultipass") - local spacing = S(" \n\r\t\v")^0 - local dquote = P('"') +local function convert(str) + found = true + return "rawtextext(\"" .. str .. "\")" -- centered +end +local function ditto(str) + return "\" & ditto & \"" +end +local function register() + found = true +end +local function force() + forced = true +end - local found, forced = false, false +local texmess = (dquote/ditto + (1 - etex))^0 - local function convert(str) - found = true - return "rawtextext(\"" .. str .. "\")" -- centered - end - local function ditto(str) - return "\" & ditto & \"" - end - local function register() - found = true - end - local function force() - forced = true - end +local function ignore(s) + report_mplib("ignoring verbatim tex: %s",s) + return "" +end - local texmess = (dquote/ditto + (1 - etex))^0 +local parser = P { + [1] = Cs((V(2)/register + V(4)/ignore + V(3)/convert + V(5)/force + 1)^0), + [2] = ttex + gtex, + [3] = btex * spacing * Cs(texmess) * etex, + [4] = vtex * spacing * Cs(texmess) * etex, + [5] = multipass, -- experimental, only for testing +} - local function ignore(s) - report_mplib("ignoring verbatim tex: %s",s) - return "" - end +-- currently a a one-liner produces less code - local parser = P { - [1] = Cs((V(2)/register + V(4)/ignore + V(3)/convert + V(5)/force + 1)^0), - [2] = ttex + gtex, - [3] = btex * spacing * Cs(texmess) * etex, - [4] = vtex * spacing * Cs(texmess) * etex, - [5] = multipass, -- experimental, only for testing - } - - -- currently a a one-liner produces less code - - local parser = Cs(( - (ttex + gtex)/register - + (btex * spacing * Cs(texmess) * etex)/convert - + (vtex * spacing * Cs(texmess) * etex)/ignore - + 1 - )^0) - - function metapost.check_texts(str) - found, forced = false, false - return lpegmatch(parser,str), found, forced - end +local parser = Cs(( + (ttex + gtex)/register + + (btex * spacing * Cs(texmess) * etex)/convert + + (vtex * spacing * Cs(texmess) * etex)/ignore + + 1 +)^0) +local function check_texts(str) + found, forced = false, false + return lpegmatch(parser,str), found, forced end local factor = 65536*(7227/7200) @@ -707,7 +693,7 @@ local do_begin_fig = "; beginfig(1); " local do_end_fig = "; endfig ;" local do_safeguard = ";" -function metapost.text_texts_data() +function metapost.texttextsdata() local t, n = { }, 0 --~ for i = metapost.first_box, metapost.last_box do --~ n = n + 1 @@ -735,11 +721,11 @@ metapost.method = 1 -- 1:dumb 2:clever function metapost.graphic_base_pass(mpsformat,str,initializations,preamble,askedfig) local nofig = (askedfig and "") or false local done_1, done_2, forced_1, forced_2 - str, done_1, forced_1 = metapost.check_texts(str) + str, done_1, forced_1 = check_texts(str) if not preamble or preamble == "" then preamble, done_2, forced_2 = "", false, false else - preamble, done_2, forced_2 = metapost.check_texts(preamble) + preamble, done_2, forced_2 = check_texts(preamble) end -- metapost.textext_current = metapost.first_box metapost.intermediate.needed = false @@ -779,7 +765,7 @@ function metapost.graphic_base_pass(mpsformat,str,initializations,preamble,asked }, false, nil, false, false, askedfig ) end -- here we could free the textext boxes - metapost.free_boxes() + free_boxes() end function metapost.graphic_extra_pass(askedfig) @@ -788,7 +774,7 @@ function metapost.graphic_extra_pass(askedfig) metapost.process(current_format, { nofig or do_begin_fig, no_trial_run, - concat(metapost.text_texts_data()," ;\n"), + concat(metapost.texttextsdata()," ;\n"), current_initializations, do_safeguard, current_graphic, diff --git a/tex/context/base/mult-aux.lua b/tex/context/base/mult-aux.lua index 997760a37..be2d282b6 100644 --- a/tex/context/base/mult-aux.lua +++ b/tex/context/base/mult-aux.lua @@ -22,6 +22,9 @@ local meaning = "@@@@" local data = { } function namespaces.define(namespace,settings) + if trace_namespaces then + report_namespaces("installing namespace '%s' with settings '%s'",namespace,settings) + end if data[namespace] then report_namespaces("namespace '%s' is already taken",namespace) end @@ -35,29 +38,29 @@ function namespaces.define(namespace,settings) if not name or name == "" then report_namespaces("provide a (command) name in namespace '%s'",namespace) end - local self = prefix .. namespace + local self = "\\" .. prefix .. namespace context.unprotect() -- context.installnamespace(namespace) - context("\\def\\%s%s{%s%s}",prefix,self,meaning,namespace) + context("\\def\\%s%s{%s%s}",prefix,namespace,meaning,namespace) if trace_namespaces then - report_namespaces("installing namespace '%s' for '%s'",namespace,name) + report_namespaces("using namespace '%s' for '%s'",namespace,name) end local parent = ns.parent or "" if parent ~= "" then if trace_namespaces then report_namespaces("namespace '%s' for '%s' uses parent '%s'",namespace,name,parent) end - parent = prefix .. parent + parent = "\\" .. prefix .. parent -- todo: check if defined end context.installparameterhandler(self,name) if trace_namespaces then report_namespaces("installing parameter handler for '%s'",name) - end + end context.installparameterhashhandler(self,name) if trace_namespaces then report_namespaces("installing parameterhash handler for '%s'",name) - end + end local style = ns.style if style == v_yes then context.installattributehandler(self,name) diff --git a/tex/context/base/mult-aux.mkiv b/tex/context/base/mult-aux.mkiv index 295b0a71c..54971d6a5 100644 --- a/tex/context/base/mult-aux.mkiv +++ b/tex/context/base/mult-aux.mkiv @@ -65,7 +65,8 @@ \def#7##1{\detokenize\expandafter\expandafter\expandafter{\csname#1##1\endcsname}}} % always root \def\installparameterhandler#1#2% - {\normalexpanded + {%\message{\detokenize{#1}/\detokenize{#2}}% + \normalexpanded {\doinstallparameterhandler {\noexpand#1}% \??aa \expandafter\noexpand\csname current#2\endcsname @@ -163,30 +164,40 @@ \def\installnamespace#1% {\setvalue{????#1}{@@@@#1}} -% \start -% -% \enabletrackers[interfaces.namespaces] +% \enabletrackers[interfaces.namespaces,context.flush] % % \definenamespace -% [ws] +% [xy] % [type=module, -% comment=letter module, +% comment=test module, % version=1, -% name=letter, +% name=test, % style=yes, % command=yes, % setup=list, -% parent=ws-common] +% parent=xy] +% +% \unprotect +% \getparameters +% [\????xy] +% [text=] +% \protect +% +% \definetest[one] +% +% \starttext +% +% “\testparameter{text}” % -% \ttx \listnamespaces +% \setuptest[text=foo] % -% \defineletter[mine][whatever=true] \setupletter[mine][whatever=true] +% “\testparameter{text}” % -% \namedletterparameter{mine}{whatever} +% \setuptest[one][text=bar] % -% \def\currentletter{mine} \letterparameter{whatever} +% “\testparameter{text}” % -% \stop +% \stoptext \def\definenamespace{\dodoubleargument\dodefinenamespace} diff --git a/tex/context/base/mult-cld.lua b/tex/context/base/mult-cld.lua index ac746b28b..7244b0d7e 100644 --- a/tex/context/base/mult-cld.lua +++ b/tex/context/base/mult-cld.lua @@ -16,11 +16,22 @@ if not modules then modules = { } end modules ['mult-cld'] = { -- Todo: optional checking against interface -- Todo: coroutine trickery -context = context or { } +context = context or { } +local context = context local format, concat = string.format, table.concat local next, type, tostring = next, type, tostring -local texsprint, texiowrite, texcount, ctxcatcodes = tex.sprint, texio.write, tex.count, tex.ctxcatcodes +local insert, remove = table.insert, table.remove + +local tex = tex + +local texsprint = tex.sprint +local texprint = tex.print +local texiowrite = texio.write +local texcount = tex.count +local ctxcatcodes = tex.ctxcatcodes +local prtcatcodes = tex.prtcatcodes +local vrbcatcodes = tex.vrbcatcodes local flush = texsprint or function(cct,...) print(concat{...}) end @@ -49,10 +60,43 @@ context._stack_ = _stack_ context._store_ = _store_ context._flush_ = _flush_ +-- Should we keep the catcodes with the function? + +local catcodestack = { } +local currentcatcodes = ctxcatcodes + +function context.pushcatcodes(c) + insert(catcodestack,currentcatcodes) + currentcatcodes = c +end + +function context.popcatcodes() + currentcatcodes = remove(catcodestack) or currentcatcodes +end + +function context.unprotect() + insert(catcodestack,currentcatcodes) + currentcatcodes = prtcatcodes +end + +function context.protect() + currentcatcodes = remove(catcodestack) or currentcatcodes +end + function tex.fprint(...) -- goodie - texsprint(ctxcatcodes,format(...)) + texsprint(currentcatcodes,format(...)) end +--~ function context.direct(...) +--~ context.flush(...) +--~ end + +--~ function context.verbose(...) +--~ context.flush(vrbcatcodes,...) +--~ end + +local trace_context = logs.new("context") -- here + function context.trace(intercept) local normalflush = flush flush = function(c,...) @@ -67,69 +111,11 @@ end trackers.register("context.flush", function(v) if v then context.trace() end end) trackers.register("context.intercept", function(v) if v then context.trace(true) end end) -local trace_context = logs.new("context") - -local function writer(k,...) -- we can optimize for 1 argument - if k then - flush(ctxcatcodes,k) - local t = { ... } - local nt = #t - if nt > 0 then - for i=1,nt do - local ti = t[i] - local typ = type(ti) - if ti == nil then - -- next - elseif typ == "string" or typ == "number" then - flush(ctxcatcodes,"{",ti,"}") - elseif typ == "table" then - local tn = #ti - if tn > 0 then - for j=1,tn do - local tj = ti[j] - if type(tj) == "function" then - ti[j] = "\\mkivflush{" .. _store_(tj) .. "}" - end - end - flush(ctxcatcodes,"[",concat(ti,","),"]") - else - flush(ctxcatcodes,"[") - local done = false - for k, v in next, ti do - if done then - flush(ctxcatcodes,",",k,'=',v) - else - flush(ctxcatcodes,k,'=',v) - done = true - end - end - flush(ctxcatcodes,"]") - end - elseif typ == "function" then - flush(ctxcatcodes,"{\\mkivflush{" .. _store_(ti) .. "}}") - -- elseif typ == "boolean" then - -- flush(ctxcatcodes,"\n") - elseif ti == true then - flush(ctxcatcodes,"\n") - elseif typ == false then - -- if force == "direct" then - flush(ctxcatcodes,tostring(ti)) - -- end - elseif typ == "thread" then - trace_context("coroutines not supported as we cannot yeild across boundaries") - else - trace_context("error: %s gets a weird argument %s",k,tostring(ti)) - end - end - end - end -end - -local function newwriter(command,first,...) -- 5% faster than just ... and separate flush of command +local function writer(command,first,...) -- 5% faster than just ... and separate flush of command if not command then -- error elseif not first then - flush(ctxcatcodes,command) + flush(currentcatcodes,command) else local t = { first, ... } for i=1,#t do @@ -139,28 +125,28 @@ local function newwriter(command,first,...) -- 5% faster than just ... and separ local ti = t[i] local typ = type(ti) if ti == nil then - flush(ctxcatcodes,command) + flush(currentcatcodes,command) elseif typ == "string" or typ == "number" then - flush(ctxcatcodes,command,"{",ti,"}") + flush(currentcatcodes,command,"{",ti,"}") elseif typ == "table" then local tn = #ti if tn == 0 then local done = false for k, v in next, ti do if done then - flush(ctxcatcodes,",",k,'=',v) + flush(currentcatcodes,",",k,'=',v) else - flush(ctxcatcodes,command,"[",k,'=',v) + flush(currentcatcodes,command,"[",k,'=',v) done = true end end - flush(ctxcatcodes,"]") + flush(currentcatcodes,"]") elseif tn == 1 then -- some 20% faster than the next loop local tj = ti[1] if type(tj) == "function" then - flush(ctxcatcodes,command,"[\\mkivflush{",_store_(tj),"}]") + flush(currentcatcodes,command,"[\\mkivflush{",_store_(tj),"}]") else - flush(ctxcatcodes,command,"[",tj,"]") + flush(currentcatcodes,command,"[",tj,"]") end else -- is concat really faster than flushes here? for j=1,tn do @@ -169,32 +155,32 @@ local function newwriter(command,first,...) -- 5% faster than just ... and separ ti[j] = "\\mkivflush{" .. _store_(tj) .. "}" end end - flush(ctxcatcodes,command,"[",concat(ti,","),"]") + flush(currentcatcodes,command,"[",concat(ti,","),"]") end elseif typ == "function" then - flush(ctxcatcodes,command,"{\\mkivflush{",_store_(ti),"}}") + flush(currentcatcodes,command,"{\\mkivflush{",_store_(ti),"}}") -- elseif typ == "boolean" then - -- flush(ctxcatcodes,"\n") + -- flush(currentcatcodes,"\n") elseif ti == true then - flush(ctxcatcodes,command,"\n") + flush(currentcatcodes,command,"\n") elseif typ == false then -- if force == "direct" then - flush(ctxcatcodes,command,tostring(ti)) + flush(currentcatcodes,command,tostring(ti)) -- end elseif typ == "thread" then - flush(ctxcatcodes,command) - trace_context("coroutines not supported as we cannot yeild across boundaries") + flush(currentcatcodes,command) + trace_context("coroutines not supported as we cannot yield across boundaries") else - flush(ctxcatcodes,command) + flush(currentcatcodes,command) trace_context("error: %s gets a weird argument %s",command,tostring(ti)) end end end end -experiments.register("context.writer",function() - writer = newwriter -end) +--~ experiments.register("context.writer",function() +--~ writer = newwriter +--~ end) -- -- -- @@ -209,13 +195,13 @@ local function caller(t,f,a,...) if not t then -- so we don't need to test in the calling (slower but often no issue) elseif a then - flush(ctxcatcodes,format(f,a,...)) + flush(currentcatcodes,format(f,a,...)) elseif type(f) == "function" then - flush(ctxcatcodes,"{\\mkivflush{" .. _store_(f) .. "}}") + flush(currentcatcodes,"{\\mkivflush{" .. _store_(f) .. "}}") elseif f then - flush(ctxcatcodes,f) + flush(currentcatcodes,f) else - flush(ctxcatcodes,"\n") + flush(currentcatcodes,"\n") end end diff --git a/tex/context/base/node-fin.lua b/tex/context/base/node-fin.lua index 84b60232c..943af3837 100644 --- a/tex/context/base/node-fin.lua +++ b/tex/context/base/node-fin.lua @@ -117,7 +117,7 @@ end -- nodes.process_attribute = process_attribute -function nodes.install_attribute_handler(plugin) -- we need to avoid this nested function +function nodes.installattributehandler(plugin) -- we need to avoid this nested function return function(head) return process_attribute(head,plugin) end @@ -165,7 +165,7 @@ end --~ end --~ ]] --~ ---~ function nodes.install_attribute_handler(plugin) -- we need to avoid this nested function +--~ function nodes.installattributehandler(plugin) -- we need to avoid this nested function --~ plugindata[plugin.name] = plugin --~ local str = format(template,plugin.name) --~ return loadstring(str)() diff --git a/tex/context/base/node-fnt.lua b/tex/context/base/node-fnt.lua index 3c98785e5..c35a42840 100644 --- a/tex/context/base/node-fnt.lua +++ b/tex/context/base/node-fnt.lua @@ -58,7 +58,7 @@ function handlers.characters(head) if shared then local dynamics = shared.dynamics if dynamics then - local d = shared.set_dynamics(font,dynamics,attr) -- still valid? + local d = shared.setdynamics(font,dynamics,attr) if d then used[attr] = d a = a + 1 diff --git a/tex/context/base/node-par.lua b/tex/context/base/node-par.lua index ef387cd55..b153ec6d6 100644 --- a/tex/context/base/node-par.lua +++ b/tex/context/base/node-par.lua @@ -14,32 +14,35 @@ local parbuilders = builders.paragraphs parbuilders.constructors = parbuilders.constructors or { } local constructors = parbuilders.constructors -parbuilders.names = parbuilders.names or { } -local names = parbuilders.names +constructors.names = constructors.names or { } +local names = constructors.names -parbuilders.numbers = parbuilders.numbers or { } -local numbers = parbuilders.numbers +constructors.numbers = constructors.numbers or { } +local numbers = constructors.numbers + +constructors.methods = constructors.methods or { } +local methods = constructors.methods local p_attribute = attributes.numbers['parbuilder'] or 999 -parbuilders.attribute = p_attribute +constructors.attribute = p_attribute local has_attribute = node.has_attribute local starttiming = statistics.starttiming local stoptiming = statistics.stoptiming -storage.register("builders/paragraphs/names", names, "builders.paragraphs.names") -storage.register("builders/paragraphs/numbers", numbers, "builders.paragraphs.numbers") +storage.register("builders/paragraphs/constructors/names", names, "builders.paragraphs.constructors.names") +storage.register("builders/paragraphs/constructors/numbers", numbers, "builders.paragraphs.constructors.numbers") local report_parbuilders = logs.new("parbuilders") local mainconstructor = nil -- not stored in format -function parbuilders.register(name,number) +function constructors.register(name,number) names[number] = name numbers[name] = number end -function parbuilders.setmain(name) +function constructors.set(name) mainconstructor = numbers[name] end @@ -49,19 +52,19 @@ end -- false : idem but dangerous -- head : list of valid vmode nodes with last being hlist -function parbuilders.constructor(head,followed_by_display) +function constructors.handler(head,followed_by_display) if type(head) == "boolean" then return head else local attribute = has_attribute(head,p_attribute) or mainconstructor if attribute then - local constructor = names[attribute] - if constructor then - local handler = constructor and constructors[constructor] + local method = names[attribute] + if method then + local handler = methods[method] if handler then return handler(head,followed_by_display) else - report_parbuilders("handler '%s' is not defined",tostring(constructor)) + report_parbuilders("contructor method '%s' is not defined",tostring(method)) return true -- let tex break end end @@ -72,13 +75,13 @@ end -- just for testing -function constructors.default(head,followed_by_display) +function constructors.methods.default(head,followed_by_display) return true -- let tex break end -- also for testing (no surrounding spacing done) -function constructors.oneline(head,followed_by_display) +function constructors.methods.oneline(head,followed_by_display) return node.hpack(head) end @@ -89,11 +92,11 @@ end -- todo: enable one as main -local actions = parbuilders.constructor +local actions = constructors.handler local enabled = false -function parbuilders.enable () enabled = true end -function parbuilders.disable() enabled = false end +function constructors.enable () enabled = true end +function constructors.disable() enabled = false end local function processor(head,followed_by_display) if enabled then diff --git a/tex/context/base/node-par.mkiv b/tex/context/base/node-par.mkiv index 4db097c92..28c8931d3 100644 --- a/tex/context/base/node-par.mkiv +++ b/tex/context/base/node-par.mkiv @@ -40,7 +40,7 @@ \unexpanded\def\defineparbuilder[#1]% {\global\advance\nofparbuilders\plusone - \ctxlua{builders.paragraphs.register("#1",\number\nofparbuilders)}% + \ctxlua{builders.paragraphs.constructors.register("#1",\number\nofparbuilders)}% \setxvalue{\??ng:#1}{\attribute\parbuilderattribute\nofparbuilders}} \unexpanded\def\startparbuilder[#1]% @@ -56,7 +56,7 @@ \checkparbuilders} \def\setmainparbuilder[#1]% - {\ctxlua{builders.paragraphs.setmain("#1")}} + {\ctxlua{builders.paragraphs.constructors.set("#1")}} % no high level interface, after all implementing a linebreaker is not something that % the average user will do @@ -65,8 +65,8 @@ \defineparbuilder[oneline] % just for testing \defineparbuilder[basic] % just for testing -\def\enableparbuilders {\ctxlua{builders.paragraphs.enable ()}} -\def\disableparbuilders{\ctxlua{builders.paragraphs.disable()}} +\def\enableparbuilders {\ctxlua{builders.paragraphs.constructors.enable ()}} +\def\disableparbuilders{\ctxlua{builders.paragraphs.constructors.disable()}} \def\checkparbuilders % can be more efficient as we don't want to do this to often {\ifcase\attribute\parbuilderattribute diff --git a/tex/context/base/node-ref.lua b/tex/context/base/node-ref.lua index 2f4575598..40dd82c4d 100644 --- a/tex/context/base/node-ref.lua +++ b/tex/context/base/node-ref.lua @@ -562,7 +562,7 @@ statistics.register("interactive elements", function() end end) -function references.enable_interaction() +function references.enableinteraction() tasks.enableaction("shipouts","nodes.references.handler") tasks.enableaction("shipouts","nodes.destinations.handler") end diff --git a/tex/context/base/node-rul.lua b/tex/context/base/node-rul.lua index eb388a6d9..a8f59c37e 100644 --- a/tex/context/base/node-rul.lua +++ b/tex/context/base/node-rul.lua @@ -121,7 +121,7 @@ local checkdir = true -- omkeren class en level -> scheelt functie call in analyse -local function process_words(attribute,data,flush,head,parent) -- we have hlistdir and local dir +local function processwords(attribute,data,flush,head,parent) -- we have hlistdir and local dir local n = head if n then local f, l, a, d, i, class @@ -167,7 +167,7 @@ local function process_words(attribute,data,flush,head,parent) -- we have hlistd end local list = n.list if list then - n.list = process_words(attribute,data,flush,list,n) + n.list = processwords(attribute,data,flush,list,n) end elseif checkdir and id == whatsit_code and n.subtype == dir_code then -- only changes in dir, we assume proper boundaries if f and a then @@ -206,7 +206,7 @@ local function process_words(attribute,data,flush,head,parent) -- we have hlistd end end -nodes.process_words = process_words +nodes.processwords = processwords -- @@ -297,7 +297,7 @@ local function flush_ruled(head,f,l,d,level,parent,strip) -- not that fast but a return head end -local process = nodes.process_words +local process = nodes.processwords nodes.rules.handler = function(head) return process(a_ruled,data,flush_ruled,head) end @@ -353,7 +353,7 @@ local function flush_shifted(head,first,last,data,level,parent,strip) -- not tha return head end -local process = nodes.process_words +local process = nodes.processwords nodes.shifts.handler = function(head) return process(a_shifted,data,flush_shifted,head) end diff --git a/tex/context/base/node-ser.lua b/tex/context/base/node-ser.lua index 0b8b2212e..0ef074397 100644 --- a/tex/context/base/node-ser.lua +++ b/tex/context/base/node-ser.lua @@ -265,7 +265,7 @@ function nodes.print(head,n) end end -function nodes.check_for_leaks(sparse) +function nodes.checkforleaks(sparse) local l = { } local q = node.usedlist() for p in traverse(q) do diff --git a/tex/context/base/node-spl.lua b/tex/context/base/node-spl.lua index db279b73f..bd641817c 100644 --- a/tex/context/base/node-spl.lua +++ b/tex/context/base/node-spl.lua @@ -74,7 +74,6 @@ local starttiming = statistics.starttiming local stoptiming = statistics.stoptiming local process_characters = nodes.handlers.characters local inject_kerns = nodes.handlers.injectkerns -local set_dynamics = fonts.otf.set_dynamics local fontdata = fonts.ids local parbuilders = builders.paragraphs @@ -239,7 +238,7 @@ function splitters.split(head) } if trace_split then report_splitter( "cached %4i: font: %s, attribute: %s, word: %s, direction: %s", n, - font, attribute, nodes.list_to_utf(list,true), rlmode) + font, attribute, nodes.listtoutf(list,true), rlmode) end cache[n] = c local solution = solutions[attribute] @@ -336,13 +335,14 @@ local function doit(word,list,best,width,badness,line,set,listdir) end local font = found.font local dynamics = found.dynamics + local shared = fontdata[font].shared if not dynamics then -- we cache this - dynamics = fontdata[font].shared.dynamics + dynamics = shared.dynamics found.dynamics = dynamics end local processors = found[featurenumber] if not processors then -- we cache this too - processors = set_dynamics(font,dynamics,featurenumber) + processors = shared.setdynamics(font,dynamics,featurenumber) found[featurenumber] = processors end for i=1,#processors do -- often more than 1 diff --git a/tex/context/base/node-tra.lua b/tex/context/base/node-tra.lua index 16829a1e5..dd6a49d4b 100644 --- a/tex/context/base/node-tra.lua +++ b/tex/context/base/node-tra.lua @@ -352,7 +352,7 @@ function nodes.show_list(head, message) end end -function nodes.check_glyphs(head,message) +function nodes.checkglyphs(head,message) local t = { } for g in traverse_id(glyph_code,head) do t[#t+1] = format("U+%04X:%s",g.char,g.subtype) @@ -428,7 +428,7 @@ function nodes.report(t,done) end end -function nodes.pack_list(head) +function nodes.packlist(head) local t = { } for n in traverse(head) do t[#t+1] = tostring(n) @@ -491,7 +491,7 @@ end nodes.show_simple_list = function(h,depth) show_simple_list(h,depth,0) end -function nodes.list_to_utf(h,joiner) +function nodes.listtoutf(h,joiner) local joiner = (joiner ==true and utfchar(0x200C)) or joiner -- zwnj local w = { } while h do diff --git a/tex/context/base/scrn-nav.mkiv b/tex/context/base/scrn-nav.mkiv index 207530b83..bc27cd973 100644 --- a/tex/context/base/scrn-nav.mkiv +++ b/tex/context/base/scrn-nav.mkiv @@ -197,7 +197,7 @@ \def\enableinteractivereferences {\ifproductionrun - \ctxlua{structures.references.enable_interaction()}% + \ctxlua{structures.references.enableinteraction()}% \globallet\enableinteractivereferences\relax \fi} diff --git a/tex/context/base/scrp-cjk.lua b/tex/context/base/scrp-cjk.lua index e17d4e967..7c1310528 100644 --- a/tex/context/base/scrp-cjk.lua +++ b/tex/context/base/scrp-cjk.lua @@ -28,13 +28,13 @@ local prestat = attributes.private('prestat') scripts.cjk = scripts.cjk or { } -local kind_to_number = scripts.kind_to_number -local number_to_kind = scripts.number_to_kind -local hash = scripts.hash -local cjk = scripts.cjk +local kindtonumber = scripts.kindtonumber +local numbertokind = scripts.numbertokind +local hash = scripts.hash +local cjk = scripts.cjk -local fontdata = fonts.identifiers -local quaddata = fonts.quads +local fontdata = fonts.identifiers +local quaddata = fonts.quads -- raggedleft is controlled by leftskip and we might end up with a situation where -- the intercharacter spacing interferes with this; the solution is to patch the @@ -326,7 +326,7 @@ local function process(head,first,last) local upcoming, id = first.next, first.id if id == glyph_code then local a = has_attribute(first,prestat) - local current = number_to_kind[a] + local current = numbertokind[a] local action = injectors[previous] if action then action = action[current] @@ -346,7 +346,7 @@ local function process(head,first,last) local pid, nid = p.id, n.id if pid == glyph_code and nid == glyph_code then local pa, na = has_attribute(p,prestat), has_attribute(n,prestat) - local pcjk, ncjk = pa and number_to_kind[pa], na and number_to_kind[na] + local pcjk, ncjk = pa and numbertokind[pa], na and numbertokind[na] if not pcjk or not ncjk or pcjk == "korean" or ncjk == "korean" or pcjk == "other" or ncjk == "other" @@ -529,7 +529,7 @@ local function process(head,first,last) local upcoming, id = first.next, first.id if id == glyph_code then local a = has_attribute(first,prestat) - local current = number_to_kind[a] + local current = numbertokind[a] local action = injectors[previous] if action then action = action[current] @@ -549,7 +549,7 @@ local function process(head,first,last) local pid, nid = p.id, n.id if pid == glyph_code and nid == glyph_code then local pa, na = has_attribute(p,prestat), has_attribute(n,prestat) - local pcjk, ncjk = pa and number_to_kind[pa], na and number_to_kind[na] + local pcjk, ncjk = pa and numbertokind[pa], na and numbertokind[na] if not pcjk or not ncjk or pcjk == "korean" or ncjk == "korean" or pcjk == "other" or ncjk == "other" diff --git a/tex/context/base/scrp-ini.lua b/tex/context/base/scrp-ini.lua index bff12def8..949bbe2a7 100644 --- a/tex/context/base/scrp-ini.lua +++ b/tex/context/base/scrp-ini.lua @@ -197,7 +197,7 @@ scripts.colors = { -- todo: just named colors local colors = scripts.colors -local number_to_kind = { +local numbertokind = { "korean", "chinese", "full_width_open", @@ -211,7 +211,7 @@ local number_to_kind = { "jamo_final", } -local kind_to_number = { +local kindtonumber = { korean = 1, chinese = 2, full_width_open = 3, @@ -225,8 +225,8 @@ local kind_to_number = { jamo_final = 11, } -scripts.kind_to_number = kind_to_number -scripts.number_to_kind = number_to_kind +scripts.kindtonumber = kindtonumber +scripts.numbertokind = numbertokind -- no, this time loading the lua always precedes the definitions -- @@ -254,7 +254,7 @@ end local function colorize(start,stop) for n in traverse_id(glyph_code,start) do - local kind = number_to_kind[has_attribute(n,prestat)] + local kind = numbertokind[has_attribute(n,prestat)] if kind then local ac = colors[kind] if ac then @@ -322,7 +322,7 @@ function scripts.preprocess(head) if originals then c = originals[c] or c end local h = hash[c] if h then - set_attribute(start,prestat,kind_to_number[h]) + set_attribute(start,prestat,kindtonumber[h]) if not first then first, last = start, start else diff --git a/tex/context/base/sort-ini.lua b/tex/context/base/sort-ini.lua index 38c28aaa6..2bafe8e5e 100644 --- a/tex/context/base/sort-ini.lua +++ b/tex/context/base/sort-ini.lua @@ -27,10 +27,10 @@ local splitters = { } local entries = { } local mappings = { } local replacements = { } -local ignored_offset = 0x10000 -local replacement_offset = 0x10000 -local digits_offset = 0x20000 -local digits_maximum = 0xFFFFF +local ignoredoffset = 0x10000 +local replacementoffset = 0x10000 +local digitsoffset = 0x20000 +local digitsmaximum = 0xFFFFF sorters = { comparers = comparers, @@ -38,10 +38,12 @@ sorters = { entries = entries, mappings = mappings, replacements = replacements, - ignored_offset = ignored_offset, - replacement_offset = replacement_offset, - digits_offset = digits_offset, - digits_maximum = digits_maximum, + constants = { + ignoredoffset = ignoredoffset, + replacementoffset = replacementoffset, + digitsoffset = digitsoffset, + digitsmaximum = digitsmaximum, + } } local ssorters = sorters @@ -146,9 +148,9 @@ local function numify(s) end local function numify(s) - s = digits_offset + tonumber(s) - if s > digits_maximum then - s = digits_maximum + s = digitsoffset + tonumber(s) + if s > digitsmaximum then + s = digitsmaximum end return utfchar(s) end @@ -240,7 +242,7 @@ local function pack(entry) local tt, li = { }, split[i].s for j=1,#li do local lij = li[j] - tt[j] = utfbyte(lij) > ignored_offset and "[]" or lij + tt[j] = utfbyte(lij) > ignoredoffset and "[]" or lij end t[i] = concat(tt) end @@ -249,7 +251,7 @@ local function pack(entry) local t, li = { }, split.s for j=1,#li do local lij = li[j] - t[j] = utfbyte(lij) > ignored_offset and "[]" or lij + t[j] = utfbyte(lij) > ignoredoffset and "[]" or lij end return concat(t) end @@ -283,7 +285,7 @@ end -- some day we can have a characters.upper and characters.lower -function sorters.add_uppercase_replacements(what) +function sorters.adduppercasereplacements(what) local rep, new = replacements[what], { } for i=1,#rep do local r = rep[i] @@ -297,7 +299,7 @@ function sorters.add_uppercase_replacements(what) end end -function sorters.add_uppercase_entries(what) +function sorters.adduppercaseentries(what) local ent, new = entries[what], { } for k, v in next, ent do local u = chardata[utfbyte(k)].uccode @@ -310,7 +312,7 @@ function sorters.add_uppercase_entries(what) end end -function sorters.add_uppercase_mappings(what,offset) +function sorters.adduppercasemappings(what,offset) local map, new, offset = mappings[what], { }, offset or 0 for k, v in next, map do local u = chardata[utfbyte(k)].uccode diff --git a/tex/context/base/sort-lan.lua b/tex/context/base/sort-lan.lua index 227b3ee7c..31824c964 100644 --- a/tex/context/base/sort-lan.lua +++ b/tex/context/base/sort-lan.lua @@ -17,15 +17,15 @@ local ub = utf.byte local sorters = sorters -local mappings = sorters.mappings -local entries = sorters.entries -local replacements = sorters.replacements +local mappings = sorters.mappings +local entries = sorters.entries +local replacements = sorters.replacements -local add_uppercase_replacements = sorters.add_uppercase_replacements -local add_uppercase_entries = sorters.add_uppercase_entries -local add_uppercase_mappings = sorters.add_uppercase_mappings +local adduppercasereplacements = sorters.adduppercasereplacements +local adduppercaseentries = sorters.adduppercaseentries +local adduppercasemappings = sorters.adduppercasemappings -local replacement_offset = sorters.replacement_offset +local replacementoffset = sorters.constants.replacementoffset -- english @@ -76,8 +76,8 @@ mappings ['nl'] = mappings['en'] -- czech -local cz_ch = uc(replacement_offset + 1) -local cz_CH = uc(replacement_offset + 2) +local cz_ch = uc(replacementoffset + 1) +local cz_CH = uc(replacementoffset + 2) replacements['cz'] = { [1] = { "ch", cz_ch } @@ -171,8 +171,8 @@ mappings['cz'] = { [uc(0x017E)] = 81, -- zcaron } -add_uppercase_entries ("cz") -add_uppercase_mappings("cz") -- 1 can be option (but then we need a runtime variant) +adduppercaseentries ("cz") +adduppercasemappings("cz") -- 1 can be option (but then we need a runtime variant) entries ['cz'][cz_CH] = entries ['cz'][cz_ch] mappings['cz'][cz_CH] = mappings['cz'][cz_ch] @@ -197,7 +197,7 @@ mappings ['DIN 5007-1'] = mappings['en'] -- DIN 5007-2 -replacements['DIN 5007-2'] = { -- todo: add_uppercase_replacements +replacements['DIN 5007-2'] = { -- todo: adduppercasereplacements { "ä", 'ae' }, { "ö", 'oe' }, { "ü", 'ue' }, @@ -206,7 +206,7 @@ replacements['DIN 5007-2'] = { -- todo: add_uppercase_replacements { "Ü", 'Ue' }, } ---~ add_uppercase_replacements('DIN 5007-2') +--~ adduppercasereplacements('DIN 5007-2') entries ['DIN 5007-2'] = entries ['en'] mappings ['DIN 5007-2'] = mappings['en'] @@ -269,8 +269,8 @@ mappings['de-AT'] = { -- ["W"] = 52, ["X"] = 54, ["Y"] = 56, ["Z"] = 58, } -add_uppercase_entries ('de-AT') -add_uppercase_mappings('de-AT',1) +adduppercaseentries ('de-AT') +adduppercasemappings('de-AT',1) -- finish (by Wolfgang Schuster) @@ -292,8 +292,8 @@ mappings['fi'] = { ["z"] = 51, ["å"] = 53, ["ä"] = 55, ["ö"] = 57, } -add_uppercase_entries ("fi") -add_uppercase_mappings("fi") +adduppercaseentries ("fi") +adduppercasemappings("fi") -- slovenian -- @@ -317,32 +317,32 @@ mappings['sl'] = { ["ž"] = 61, } -add_uppercase_entries ("sl") -add_uppercase_mappings("sl") -- cf. MM +adduppercaseentries ("sl") +adduppercasemappings("sl") -- cf. MM sorters.replacements["pl"] = { -- no replacements } sorters.entries["pl"] = { - ["a"] = "a", ["ą"] = "ą", ["b"] = "b", ["c"] = "c", ["ć"] = "ć", - ["d"] = "d", ["e"] = "e", ["ę"] = "ę", ["f"] = "f", ["g"] = "g", - ["h"] = "h", ["i"] = "i", ["j"] = "j", ["k"] = "k", ["l"] = "l", - ["ł"] = "ł", ["m"] = "m", ["n"] = "n", ["ń"] = "ń", ["o"] = "o", - ["ó"] = "ó", ["p"] = "p", ["q"] = "q", ["r"] = "r", ["s"] = "s", - ["ś"] = "ś", ["t"] = "t", ["u"] = "u", ["v"] = "v", ["w"] = "w", - ["x"] = "x", ["y"] = "y", ["z"] = "z", ["ź"] = "ź", ["ż"] = "ż", + ["a"] = "a", ["ą"] = "ą", ["b"] = "b", ["c"] = "c", ["ć"] = "ć", + ["d"] = "d", ["e"] = "e", ["ę"] = "ę", ["f"] = "f", ["g"] = "g", + ["h"] = "h", ["i"] = "i", ["j"] = "j", ["k"] = "k", ["l"] = "l", + ["ł"] = "ł", ["m"] = "m", ["n"] = "n", ["ń"] = "ń", ["o"] = "o", + ["ó"] = "ó", ["p"] = "p", ["q"] = "q", ["r"] = "r", ["s"] = "s", + ["ś"] = "ś", ["t"] = "t", ["u"] = "u", ["v"] = "v", ["w"] = "w", + ["x"] = "x", ["y"] = "y", ["z"] = "z", ["ź"] = "ź", ["ż"] = "ż", } sorters.mappings["pl"] = { - ["a"] = 1, ["ą"] = 2, ["b"] = 3, ["c"] = 4, ["ć"] = 5, - ["d"] = 6, ["e"] = 7, ["ę"] = 8, ["f"] = 9, ["g"] = 10, - ["h"] = 11, ["i"] = 12, ["j"] = 13, ["k"] = 14, ["l"] = 15, - ["ł"] = 16, ["m"] = 17, ["n"] = 18, ["ń"] = 19, ["o"] = 20, - ["ó"] = 21, ["p"] = 22, ["q"] = 23, ["r"] = 24, ["s"] = 25, - ["ś"] = 26, ["t"] = 27, ["u"] = 28, ["v"] = 29, ["w"] = 30, - ["x"] = 31, ["y"] = 32, ["z"] = 33, ["ź"] = 34, ["ż"] = 35, + ["a"] = 1, ["ą"] = 2, ["b"] = 3, ["c"] = 4, ["ć"] = 5, + ["d"] = 6, ["e"] = 7, ["ę"] = 8, ["f"] = 9, ["g"] = 10, + ["h"] = 11, ["i"] = 12, ["j"] = 13, ["k"] = 14, ["l"] = 15, + ["ł"] = 16, ["m"] = 17, ["n"] = 18, ["ń"] = 19, ["o"] = 20, + ["ó"] = 21, ["p"] = 22, ["q"] = 23, ["r"] = 24, ["s"] = 25, + ["ś"] = 26, ["t"] = 27, ["u"] = 28, ["v"] = 29, ["w"] = 30, + ["x"] = 31, ["y"] = 32, ["z"] = 33, ["ź"] = 34, ["ż"] = 35, } -add_uppercase_entries ('pl') -add_uppercase_mappings('pl',1) +adduppercaseentries ('pl') +adduppercasemappings('pl',1) diff --git a/tex/context/base/spac-ver.lua b/tex/context/base/spac-ver.lua index aa166a2f7..6ca229d2a 100644 --- a/tex/context/base/spac-ver.lua +++ b/tex/context/base/spac-ver.lua @@ -72,7 +72,7 @@ local node_ids_to_string = nodes.ids_to_string local hpack_node = node.hpack local vpack_node = node.vpack local writable_spec = nodes.writable_spec -local list_to_utf = nodes.list_to_utf +local listtoutf = nodes.listtoutf local nodepool = nodes.pool @@ -163,7 +163,7 @@ local function listtohash(str) end end -function vspacing.define_snap_method(name,method) +function vspacing.definesnapmethod(name,method) local n = #snapmethods + 1 local t = listtohash(method) snapmethods[n] = t @@ -732,7 +732,7 @@ local discard, largest, force, penalty, add, disable, nowhite, goback, together --~ local function free_glue_node(n) free_node(n.spec) free_node(n) end -function vspacing.snap_box(n,how) +function vspacing.snapbox(n,how) local sv = snapmethods[how] if sv then local box = texbox[n] @@ -749,14 +749,14 @@ function vspacing.snap_box(n,how) -- assume that the box is already snapped if trace_vsnapping then report_snapper("box list already snapped at (%s,%s): %s", - ht,dp,list_to_utf(list)) + ht,dp,listtoutf(list)) end else local h, d, ch, cd, lines = snap_hlist("box",box,sv,ht,dp) box.height, box.depth = ch, cd if trace_vsnapping then report_snapper("box list snapped from (%s,%s) to (%s,%s) using method '%s' (%s) for '%s' (%s lines): %s", - h,d,ch,cd,sv.name,sv.specification,"direct",lines,list_to_utf(list)) + h,d,ch,cd,sv.name,sv.specification,"direct",lines,listtoutf(list)) end set_attribute(box, snap_method,0) -- set_attribute(list,snap_method,0) -- yes or no @@ -837,7 +837,7 @@ local function collapser(head,where,what,trace,snap,snap_method) -- maybe also p -- end elseif s == 0 then if trace_vsnapping then - report_snapper("mvl %s not snapped, already done: %s",nodecodes[id],list_to_utf(list)) + report_snapper("mvl %s not snapped, already done: %s",nodecodes[id],listtoutf(list)) end else local sv = snapmethods[s] @@ -847,17 +847,17 @@ local function collapser(head,where,what,trace,snap,snap_method) -- maybe also p local ht, dp = current.height, current.depth -- assume that the box is already snapped if trace_vsnapping then - report_snapper("mvl list already snapped at (%s,%s): %s",ht,dp,list_to_utf(list)) + report_snapper("mvl list already snapped at (%s,%s): %s",ht,dp,listtoutf(list)) end else local h, d, ch, cd, lines = snap_hlist("mvl",current,sv) if trace_vsnapping then report_snapper("mvl %s snapped from (%s,%s) to (%s,%s) using method '%s' (%s) for '%s' (%s lines): %s", - nodecodes[id],h,d,ch,cd,sv.name,sv.specification,where,lines,list_to_utf(list)) + nodecodes[id],h,d,ch,cd,sv.name,sv.specification,where,lines,listtoutf(list)) end end elseif trace_vsnapping then - report_snapper("mvl %s not snapped due to unknown snap specification: %s",nodecodes[id],list_to_utf(list)) + report_snapper("mvl %s not snapped due to unknown snap specification: %s",nodecodes[id],listtoutf(list)) end set_attribute(current,snap_method,0) end @@ -1246,7 +1246,7 @@ function nodes.handlers.vboxspacing(head,where) return head end -function nodes.collapse_vbox(n) -- for boxes but using global snap_method +function nodes.collapsevbox(n) -- for boxes but using global snap_method local list = texbox[n].list if list then -- starttiming(vspacing) diff --git a/tex/context/base/spac-ver.mkiv b/tex/context/base/spac-ver.mkiv index e7d54975a..db80c6e36 100644 --- a/tex/context/base/spac-ver.mkiv +++ b/tex/context/base/spac-ver.mkiv @@ -1368,7 +1368,7 @@ \def\installsnapvalues#1#2% todo: a proper define {\edef\currentsnapper{#1:#2}% \ifcsname\currentsnapper\endcsname \else - \setevalue\currentsnapper{\ctxlua{builders.vspacing.define_snap_method("#1","#2")}}% + \setevalue\currentsnapper{\ctxlua{builders.vspacing.definesnapmethod("#1","#2")}}% \fi \setevalue{\??gr:#1}{\attribute\snapmethodattribute\csname\currentsnapper\endcsname\space}} @@ -1501,10 +1501,10 @@ \def\dododosnaptogrid#1% {\ifvbox\nextbox % this will go away - \ctxlua{nodes.collapse_vbox(\number\nextbox)}% isn't that already done? + \ctxlua{nodes.collapsevbox(\number\nextbox)}% isn't that already done? \fi \doifelsenothing{#1}{\setsnapvalue\v!normal}{\autosetsnapvalue{#1}}% - \ctxlua{builders.vspacing.snap_box(\number\nextbox,\number\attribute\snapmethodattribute)}% + \ctxlua{builders.vspacing.snapbox(\number\nextbox,\number\attribute\snapmethodattribute)}% \ifvbox\nextbox\vbox\else\hbox\fi attr \snapmethodattribute \zerocount {\box\nextbox}% \egroup} diff --git a/tex/context/base/strc-blk.lua b/tex/context/base/strc-blk.lua index dc2abf17e..5d6d90da9 100644 --- a/tex/context/base/strc-blk.lua +++ b/tex/context/base/strc-blk.lua @@ -84,7 +84,7 @@ function blocks.select(state,name,tag,criterium) local all = tag == "" local tags = not all and settings_to_set(tag) local hide = state == "process" - local n = sections.number_at_depth(criterium) + local n = sections.numberatdepth(criterium) local result = lists.filter_collected("all", criterium, n, collected, { }) for i=1,#result do local ri = result[i] diff --git a/tex/context/base/strc-doc.lua b/tex/context/base/strc-doc.lua index a40c69b99..660dd61f3 100644 --- a/tex/context/base/strc-doc.lua +++ b/tex/context/base/strc-doc.lua @@ -347,7 +347,7 @@ function sections.setnumber(depth,n) end end -function sections.number_at_depth(depth) +function sections.numberatdepth(depth) return data.numbers[tonumber(depth) or sections.getlevel(depth) or 0] or 0 end @@ -355,7 +355,7 @@ function sections.numbers() return data.numbers end -function sections.matching_till_depth(depth,numbers,parentnumbers) +function sections.matchingtilldepth(depth,numbers,parentnumbers) local dn = parentnumbers or data.numbers local ok = false for i=1,depth do diff --git a/tex/context/base/strc-ini.lua b/tex/context/base/strc-ini.lua index 85917375a..1810369a5 100644 --- a/tex/context/base/strc-ini.lua +++ b/tex/context/base/strc-ini.lua @@ -34,10 +34,10 @@ local report_processors = logs.new("processors") -- move this -commands = commands or { } +commands = commands or { } local commands = commands -function commands.first_in_list(str) +function commands.firstinlist(str) local first = match(str,"^([^,]+),") texsprint(ctxcatcodes,first or str) end diff --git a/tex/context/base/strc-lst.lua b/tex/context/base/strc-lst.lua index 4a46cc130..2cba90fe8 100644 --- a/tex/context/base/strc-lst.lua +++ b/tex/context/base/strc-lst.lua @@ -47,7 +47,7 @@ references.specials = references.specials or { } local cached, pushed = lists.cached, { } local variables = interfaces.variables -local matching_till_depth, number_at_depth = sections.matching_till_depth, sections.number_at_depth +local matchingtilldepth, numberatdepth = sections.matchingtilldepth, sections.numberatdepth local function initializer() -- create a cross reference between internal references @@ -308,7 +308,7 @@ local function filter_collected(names, criterium, number, collected, forced, nes else -- sectionname, number -- not the same as register local depth = sections.getlevel(criterium) - local number = tonumber(number) or number_at_depth(depth) or 0 + local number = tonumber(number) or numberatdepth(depth) or 0 if trace_lists then local t = sections.numbers() detail = format("depth: %s, number: %s, numbers: %s, startset: %s",depth,number,(#t>0 and concat(t,".",1,depth)) or "?",#collected) @@ -324,7 +324,7 @@ local function filter_collected(names, criterium, number, collected, forced, nes local metadata = v.metadata local cnumbers = sectionnumber.numbers if cnumbers then - if (all or names[metadata.name or false]) and #cnumbers >= depth and matching_till_depth(depth,cnumbers,parent) then + if (all or names[metadata.name or false]) and #cnumbers >= depth and matchingtilldepth(depth,cnumbers,parent) then result[#result+1] = v end end diff --git a/tex/context/base/strc-lst.mkiv b/tex/context/base/strc-lst.mkiv index a09d61c55..8578b7157 100644 --- a/tex/context/base/strc-lst.mkiv +++ b/tex/context/base/strc-lst.mkiv @@ -156,7 +156,7 @@ {\ctxlua{structures.lists.analyze("#1","#2","#3")}} \def\firststructureelementinlist#1% - {\ctxlua{commands.first_in_list("#1")}} + {\ctxlua{commands.firstinlist("#1")}} \def\structurelistsize {\ctxlua{structures.lists.size()}} diff --git a/tex/context/base/strc-not.mkii b/tex/context/base/strc-not.mkii index a47d796e0..ec38410d4 100644 --- a/tex/context/base/strc-not.mkii +++ b/tex/context/base/strc-not.mkii @@ -534,7 +534,7 @@ \unexpanded\def\setnotetext{\dotripleempty\dosetnote[0]} \def\dosetnote[#1][#2][#3]% - {\unskip + {\removeunwantedspaces \def\currentnote{#2}% \dochecknote % sometimes needed for local notes \ifcase#1\relax diff --git a/tex/context/base/strc-ref.lua b/tex/context/base/strc-ref.lua index 3e0fefc51..398afefba 100644 --- a/tex/context/base/strc-ref.lua +++ b/tex/context/base/strc-ref.lua @@ -963,26 +963,26 @@ end -- -function references.get_current_metadata(tag) +function references.getcurrentmetadata(tag) local data = currentreference and currentreference.i data = data and data.metadata and data.metadata[tag] if data then texsprint(ctxcatcodes,data) end end -local function current_metadata(tag) +local function currentmetadata(tag) local data = currentreference and currentreference.i return data and data.metadata and data.metadata[tag] end -references.current_metadata = current_metadata +references.currentmetadata = currentmetadata -function references.get_current_prefixspec(default) -- todo: message +function references.getcurrentprefixspec(default) -- todo: message texsprint(ctxcatcodes,"\\getreferencestructureprefix{", - current_metadata("kind") or "?", "}{", current_metadata("name") or "?", "}{", default or "?", "}") + currentmetadata("kind") or "?", "}{", currentmetadata("name") or "?", "}{", default or "?", "}") end ---~ function references.get_current_prefixspec(default) -- we can consider storing the data at the lua end ---~ context.getreferencestructureprefix(current_metadata("kind"),current_metadata("name"),default) +--~ function references.getcurrentprefixspec(default) -- we can consider storing the data at the lua end +--~ context.getreferencestructureprefix(currentmetadata("kind"),currentmetadata("name"),default) --~ end -- diff --git a/tex/context/base/strc-ref.mkiv b/tex/context/base/strc-ref.mkiv index 4a0231961..d5dadc63c 100644 --- a/tex/context/base/strc-ref.mkiv +++ b/tex/context/base/strc-ref.mkiv @@ -1946,8 +1946,8 @@ % \def\getreferencestructureprefixspec#1% we can save one call by moving this to the lua end % {\getreferencestructureprefix -% {\ctxlua{structures.references.get_current_metadata("kind")}} -% {\ctxlua{structures.references.get_current_metadata("name")}} +% {\ctxlua{structures.references.getcurrentmetadata("kind")}} +% {\ctxlua{structures.references.getcurrentmetadata("name")}} % {#1}} % \def\currentreferencedefault % {\ctxlua{structures.references.filter("default",\getreferencestructureprefixspec\v!default)}} @@ -1955,7 +1955,7 @@ % this is shortcut for: \def\currentreferencedefault - {\ctxlua{structures.references.filter("default",\ctxlua{structures.references.get_current_prefixspec("\v!default")})}} + {\ctxlua{structures.references.filter("default",\ctxlua{structures.references.getcurrentprefixspec("\v!default")})}} \protect \endinput diff --git a/tex/context/base/strc-reg.lua b/tex/context/base/strc-reg.lua index 1da64d6c1..2b6b6e30c 100644 --- a/tex/context/base/strc-reg.lua +++ b/tex/context/base/strc-reg.lua @@ -37,8 +37,7 @@ local processor_split = processors.split local variables = interfaces.variables -local matching_till_depth, number_at_depth = sections.matching_till_depth, sections.number_at_depth - +local matchingtilldepth, numberatdepth = sections.matchingtilldepth, sections.numberatdepth -- some day we will share registers and lists (although there are some conceptual -- differences in the application of keywords) @@ -140,7 +139,7 @@ local function filter_collected(names,criterium,number,collected,prevmode) else -- sectionname, number -- beware, this works ok for registers local depth = sections.getlevel(criterium) - local number = tonumber(number) or number_at_depth(depth) or 0 + local number = tonumber(number) or numberatdepth(depth) or 0 if trace_registers then detail = format("depth: %s, number: %s, numbers: %s, startset: %s",depth,number,concat(sections.numbers(),".",1,depth),#collected) end @@ -154,7 +153,7 @@ local function filter_collected(names,criterium,number,collected,prevmode) local metadata = v.metadata local cnumbers = sectionnumber.numbers if cnumbers then - if (all or hash[metadata.name or false]) and #cnumbers >= depth and matching_till_depth(depth,cnumbers) then + if (all or hash[metadata.name or false]) and #cnumbers >= depth and matchingtilldepth(depth,cnumbers) then result[#result+1] = v end end diff --git a/tex/context/base/strc-tag.lua b/tex/context/base/strc-tag.lua index 981a336b9..2df387e73 100644 --- a/tex/context/base/strc-tag.lua +++ b/tex/context/base/strc-tag.lua @@ -32,19 +32,18 @@ local tags = structures.tags tags.taglist = taglist -- can best be hidden function tags.start(tag,label,detail) ---~ labels[label or tag] = tag labels[tag] = label ~= "" and label or tag if detail and detail ~= "" then tag = tag .. ":" .. detail end if not enabled then - codeinjections.enabletags(tags,labels) + codeinjections.enabletags(taglist,labels) enabled = true end local n = (ids[tag] or 0) + 1 ids[tag] = n chain[#chain+1] = tag .. "-" .. n -- insert(chain,tag .. ":" .. n) - local t = #tags + 1 + local t = #taglist + 1 stack[#stack+1] = t -- insert(stack,t) taglist[t] = { unpack(chain) } -- we can add key values for alt and actualtext if needed texattribute[a_tagged] = t @@ -76,7 +75,7 @@ end statistics.register("structure elements", function() if enabled then - return format("%s element chains identified",#tags) + return format("%s element chains identified",#taglist) else return nil end @@ -84,7 +83,7 @@ end) directives.register("backend.addtags", function(v) if not enabled then - codeinjections.enabletags(tags,labels) + codeinjections.enabletags(taglist,labels) enabled = true end end) diff --git a/tex/context/base/syst-mes.mkiv b/tex/context/base/syst-mes.mkiv index 310f21040..586d8bb8c 100644 --- a/tex/context/base/syst-mes.mkiv +++ b/tex/context/base/syst-mes.mkiv @@ -27,7 +27,7 @@ % no xml logging in format generation \everyjob {% we can redefine at the lua end ! - \doif {\ctxlua{tex.sprint(logs.get_method())}} {xml} {% + \doif {\ctxlua{tex.sprint(logs.getmethod())}} {xml} {% \long\def\writebanner #1{\writestring {<m t='banner'>#1</m>}}% \long\def\writestatus#1#2{\writestring {<m t='#1'>#2</m>}}% \long\def\message #1{\normalmessage{<m t='message'>#1</m>}}% diff --git a/tex/context/base/trac-deb.lua b/tex/context/base/trac-deb.lua index b631450f8..7e8f089a0 100644 --- a/tex/context/base/trac-deb.lua +++ b/tex/context/base/trac-deb.lua @@ -8,7 +8,7 @@ if not modules then modules = { } end modules ['trac-deb'] = { local lpeg = lpeg local lpegmatch = lpeg.match -local format, concat = string.format, table.concat +local format, concat, match = string.format, table.concat, string.match local tonumber, tostring = tonumber, tostring local texdimen, textoks, texcount = tex.dimen, tex.toks, tex.count @@ -92,10 +92,29 @@ function tracers.knownlist(name) return l and #l > 0 end -function tracers.showlines(filename,linenumber,offset) +function tracers.showlines(filename,linenumber,offset,errorstr) local data = io.loaddata(filename) local lines = data and string.splitlines(data) if lines and #lines > 0 then + -- this does not work yet as we cannot access the last lua error + -- table.print(status.list()) + -- this will be a plugin sequence + local what, where = match(errorstr,"LuaTeX error <main (%a+) instance>:(%d+)") + if what and where then + -- lua error: linenumber points to last line + local start, stop = "\\start" .. what .. "code", "\\stop" .. what .. "code" + if lines[linenumber] == start then + local n = linenumber + for i=n,1,-1 do + if lines[i] == start then + local n = i + tonumber(where) + if n <= linenumber then + linenumber = n + end + end + end + end + end offset = tonumber(offset) or 10 linenumber = tonumber(linenumber) or 10 local start = math.max(linenumber - offset,1) @@ -124,8 +143,9 @@ function tracers.printerror(offset) -- currently we still get the error message printed to the log/console so we -- add a bit of spacing around our variant texio.write_nl("\n") - report_system("error on line %s in file %s: %s ...\n",linenumber,filename,status.lasterrorstring or "?") -- lua error? - texio.write_nl(tracers.showlines(filename,linenumber,offset),"\n") + local errorstr = status.lasterrorstring or "?" + report_system("error on line %s in file %s: %s ...\n",linenumber,filename,errorstr) -- lua error? + texio.write_nl(tracers.showlines(filename,linenumber,offset,errorstr),"\n") end end @@ -194,7 +214,7 @@ local debugger = utilities.debugger local function trace_calls(n) debugger.enable() - luatex.register_stop_actions(function() + luatex.registerstopactions(function() debugger.disable() debugger.savestats(tex.jobname .. "-luacalls.log",tonumber(n)) end) diff --git a/tex/context/base/trac-inf.lua b/tex/context/base/trac-inf.lua index ad50af4c8..7a4c336ae 100644 --- a/tex/context/base/trac-inf.lua +++ b/tex/context/base/trac-inf.lua @@ -135,10 +135,10 @@ function statistics.show(reporter) end end -function statistics.show_job_stat(tag,data,n) +function statistics.showjobstat(tag,data,n) if type(data) == "table" then for i=1,#data do - statistics.show_job_stat(tag,data[i],n) + statistics.showjobstat(tag,data[i],n) end else texio.write_nl(format("%-15s: %s - %s","mkiv lua stats",tag:rpadd(n," "),data)) diff --git a/tex/context/base/trac-log.lua b/tex/context/base/trac-log.lua index 3b75b390a..2c0ffb3db 100644 --- a/tex/context/base/trac-log.lua +++ b/tex/context/base/trac-log.lua @@ -51,13 +51,13 @@ local functions = { local method = "nop" -function logs.set_method(newmethod) +function logs.setmethod(newmethod) method = newmethod -- a direct copy might be faster but let's try this for a while setmetatable(logs, { __index = logs[method] }) end -function logs.get_method() +function logs.getmethod() return method end @@ -144,7 +144,7 @@ function texlog.stop_page_number() io.flush() end -texlog.report_job_stat = statistics and statistics.show_job_stat +texlog.report_job_stat = statistics and statistics.showjobstat -- xml logging @@ -237,12 +237,12 @@ end if tex and (tex.jobname or tex.formatname) then -- todo: this can be set in mtxrun ... or maybe we should just forget about this alternative format if (os.getenv("mtx.directives.logmethod") or os.getenv("mtx_directives_logmethod")) == "xml" then - logs.set_method('xml') + logs.setmethod('xml') else - logs.set_method('tex') + logs.setmethod('tex') end else - logs.set_method('nop') + logs.setmethod('nop') end -- logging in runners -> these are actually the nop loggers diff --git a/tex/context/base/trac-set.lua b/tex/context/base/trac-set.lua index 54ef22ee5..4cb1b65d1 100644 --- a/tex/context/base/trac-set.lua +++ b/tex/context/base/trac-set.lua @@ -8,7 +8,7 @@ if not modules then modules = { } end modules ['trac-set'] = { -- might become u local type, next, tostring = type, next, tostring local concat = table.concat -local format, find, lower, gsub, simpleesc = string.format, string.find, string.lower, string.gsub, string.simpleesc +local format, find, lower, gsub, partialescapedpattern = string.format, string.find, string.lower, string.gsub, string.partialescapedpattern local is_boolean = string.is_boolean local settings_to_hash = utilities.parsers.settings_to_hash @@ -84,7 +84,7 @@ local function set(t,what,newvalue) for name, functions in next, data do if done[name] then -- prevent recursion due to wildcards - elseif find(name,simpleesc(w)) then + elseif find(name,partialescapedpattern(w)) then done[name] = true for i=1,#functions do functions[i](value) diff --git a/tex/context/base/trac-tex.lua b/tex/context/base/trac-tex.lua index 8435efafd..dbd35b56e 100644 --- a/tex/context/base/trac-tex.lua +++ b/tex/context/base/trac-tex.lua @@ -18,7 +18,7 @@ function trackers.save_hash() saved = texhashtokens() end -function trackers.dump_hash(filename,delta) +function trackers.dumphashtofile(filename,delta) local list, hash, command_name = { }, texhashtokens(), token.command_name for name, token in next, hash do if not delta or not saved[name] then @@ -42,7 +42,7 @@ local delta = nil local function dump_hash(wanteddelta) if delta == nil then saved = saved or texhashtokens() -- no need for trackers.dump_hash - luatex.register_stop_actions(1,function() dump_hash(nil,wanteddelta) end) -- at front + luatex.registerstopactions(1,function() dump_hash(nil,wanteddelta) end) -- at front end delta = wanteddelta end diff --git a/tex/context/base/typo-brk.lua b/tex/context/base/typo-brk.lua index 7a193a6af..87645e05a 100644 --- a/tex/context/base/typo-brk.lua +++ b/tex/context/base/typo-brk.lua @@ -239,7 +239,7 @@ function breakpoints.set(n) breakpoints.set(n) end -breakpoints.handler = nodes.install_attribute_handler { +breakpoints.handler = nodes.installattributehandler { name = "breakpoint", namespace = breakpoints, processor = process, diff --git a/tex/context/base/typo-cap.lua b/tex/context/base/typo-cap.lua index bcb4fbd6e..6e244b9b9 100644 --- a/tex/context/base/typo-cap.lua +++ b/tex/context/base/typo-cap.lua @@ -267,7 +267,7 @@ function cases.set(n) texattribute[a_cases] = m * 100 + n end -cases.handler = nodes.install_attribute_handler { +cases.handler = nodes.installattributehandler { name = "case", namespace = cases, processor = process, diff --git a/tex/context/base/typo-dig.lua b/tex/context/base/typo-dig.lua index 4e94f7185..36954a233 100644 --- a/tex/context/base/typo-dig.lua +++ b/tex/context/base/typo-dig.lua @@ -138,7 +138,7 @@ function digits.set(n) texattribute[a_digits] = m * 100 + n end -digits.handler = nodes.install_attribute_handler { +digits.handler = nodes.installattributehandler { name = "digits", namespace = digits, processor = process, diff --git a/tex/context/base/typo-dir.lua b/tex/context/base/typo-dir.lua index 7fae75975..931e6c90c 100644 --- a/tex/context/base/typo-dir.lua +++ b/tex/context/base/typo-dir.lua @@ -446,7 +446,7 @@ function directions.set(n) directions.set(n) end -directions.handler = nodes.install_attribute_handler { +directions.handler = nodes.installattributehandler { name = "directions", namespace = directions, processor = directions.process, diff --git a/tex/context/base/typo-krn.lua b/tex/context/base/typo-krn.lua index effbd01f6..97a6f61a4 100644 --- a/tex/context/base/typo-krn.lua +++ b/tex/context/base/typo-krn.lua @@ -246,7 +246,7 @@ local function process(namespace,attribute,head) return do_process(namespace,attribute,head) -- no direct map, because else fourth argument is tail == true end -kerns.handler = nodes.install_attribute_handler { +kerns.handler = nodes.installattributehandler { name = "kern", namespace = kerns, processor = process, diff --git a/tex/context/base/typo-spa.lua b/tex/context/base/typo-spa.lua index 75cc64728..c375b9fb5 100644 --- a/tex/context/base/typo-spa.lua +++ b/tex/context/base/typo-spa.lua @@ -171,7 +171,7 @@ function spacings.set(id) texattribute[a_spacings] = id end -spacings.handler = nodes.install_attribute_handler { +spacings.handler = nodes.installattributehandler { name = "spacing", namespace = spacings, processor = process, diff --git a/tex/context/base/util-seq.lua b/tex/context/base/util-seq.lua index 3f27221fe..415918a44 100644 --- a/tex/context/base/util-seq.lua +++ b/tex/context/base/util-seq.lua @@ -45,23 +45,23 @@ end function sequencers.prependgroup(t,group,where) local list, order = t.list, t.order - table.remove_value(order,group) - table.insert_before_value(order,where,group) + table.removevalue(order,group) + table.insertbeforevalue(order,where,group) list[group] = { } end function sequencers.appendgroup(t,group,where) local list, order = t.list, t.order - table.remove_value(order,group) - table.insert_after_value(order,where,group) + table.removevalue(order,group) + table.insertaftervalue(order,where,group) list[group] = { } end function sequencers.prependaction(t,group,action,where,kind,force) local g = t.list[group] if g and (force or validaction(action)) then - table.remove_value(g,action) - table.insert_before_value(g,where,action) + table.removevalue(g,action) + table.insertbeforevalue(g,where,action) t.kind[action] = kind end end @@ -69,8 +69,8 @@ end function sequencers.appendaction(t,group,action,where,kind,force) local g = t.list[group] if g and (force or validaction(action)) then - table.remove_value(g,action) - table.insert_after_value(g,where,action) + table.removevalue(g,action) + table.insertaftervalue(g,where,action) t.kind[action] = kind end end @@ -87,7 +87,7 @@ end function sequencers.removeaction(t,group,action,force) local g = t.list[group] if g and (force or validaction(action)) then - table.remove_value(g,action) + table.removevalue(g,action) end end diff --git a/tex/context/base/util-tab.lua b/tex/context/base/util-tab.lua index c9a0923a5..323f3e2c7 100644 --- a/tex/context/base/util-tab.lua +++ b/tex/context/base/util-tab.lua @@ -10,7 +10,8 @@ utilities = utilities or {} utilities.tables = utilities.tables or { } local tables = utilities.tables -local concat, format, gmatch = table.concat, string.format, string.gmatch +local format, gmatch = string.format, string.gmatch +local concat, insert, remove = table.concat, table.insert, table.remove function tables.definetable(target) -- defines undefined tables local composed, t = nil, { } @@ -32,3 +33,50 @@ function tables.accesstable(target) end return t end + +function table.removevalue(t,value) -- todo: n + if value then + for i=1,#t do + if t[i] == value then + remove(t,i) + -- remove all, so no: return + end + end + end +end + +function table.insertbeforevalue(t,value,extra) + for i=1,#t do + if t[i] == extra then + remove(t,i) + end + end + for i=1,#t do + if t[i] == value then + insert(t,i,extra) + return + end + end + insert(t,1,extra) +end + +function table.insertaftervalue(t,value,extra) + for i=1,#t do + if t[i] == extra then + remove(t,i) + end + end + for i=1,#t do + if t[i] == value then + insert(t,i+1,extra) + return + end + end + insert(t,#t+1,extra) +end + +local _empty_table_ = { __index = function(t,k) return "" end } + +function table.setemptymetatable(t) + setmetatable(t,_empty_table_) +end diff --git a/tex/context/base/x-mathml.lua b/tex/context/base/x-mathml.lua index 2ee3cd090..9ea128ef3 100644 --- a/tex/context/base/x-mathml.lua +++ b/tex/context/base/x-mathml.lua @@ -12,7 +12,7 @@ local texsprint, ctxcatcodes = tex.sprint, tex.ctxcatcodes local format, lower, find, gsub = string.format, string.lower, string.find, string.gsub local utfchar, utffind, utfgmatch, utfgsub = utf.char, utf.find, utf.gmatch, utf.gsub local xmlsprint, xmlcprint, xmltext, xmlcontent = xml.sprint, xml.cprint, xml.text, xml.content -local lxmltext, get_id = lxml.text, lxml.get_id +local lxmltext, getid = lxml.text, lxml.getid local utfcharacters, utfvalues = string.utfcharacters, string.utfvalues local lpegmatch = lpeg.match @@ -468,18 +468,18 @@ end function lxml.mml.mn(id,pattern) -- maybe at some point we need to interpret the number, but -- currently we assume an upright font - local str = xmlcontent(get_id(id)) or "" + local str = xmlcontent(getid(id)) or "" str = gsub(str,"(%s+)",utfchar(0x205F)) -- medspace e.g.: twenty one (nbsp is not seen) texsprint(ctxcatcodes,(gsub(str,".",n_replacements))) end function lxml.mml.mo(id) - local str = xmlcontent(get_id(id)) or "" + local str = xmlcontent(getid(id)) or "" texsprint(ctxcatcodes,(utfgsub(str,".",o_replacements))) end function lxml.mml.mi(id) - local str = xmlcontent(get_id(id)) or "" + local str = xmlcontent(getid(id)) or "" -- str = gsub(str,"^%s*(.-)%s*$","%1") local rep = i_replacements[str] if rep then @@ -490,7 +490,7 @@ function lxml.mml.mi(id) end function lxml.mml.mfenced(id) -- multiple separators - id = get_id(id) + id = getid(id) local left, right, separators = id.at.open or "(", id.at.close or ")", id.at.separators or "," local l, r = l_replacements[left], r_replacements[right] texsprint(ctxcatcodes,"\\enabledelimiter") @@ -610,7 +610,7 @@ local frametypes = { -- crazy element ... should be a proper structure instead of such a mess function lxml.mml.mcolumn(root) - root = get_id(root) + root = getid(root) local matrix, numbers = { }, 0 local function collect(m,e) local tag = e.tg @@ -707,7 +707,7 @@ local spacesplitter = lpeg.Ct(lpeg.splitat(" ")) function lxml.mml.mtable(root) -- todo: align, rowspacing, columnspacing, rowlines, columnlines - root = get_id(root) + root = getid(root) local at = root.at local rowalign = at.rowalign local columnalign = at.columnalign @@ -764,7 +764,7 @@ function lxml.mml.mtable(root) end function lxml.mml.csymbol(root) - root = get_id(root) + root = getid(root) local at = root.at local encoding = at.encoding or "" local hash = url.hashed(lower(at.definitionUrl or "")) @@ -776,7 +776,7 @@ function lxml.mml.csymbol(root) end function lxml.mml.menclosepattern(root) - root = get_id(root) + root = getid(root) local a = root.at.notation if a and a ~= "" then texsprint("mml:enclose:",gsub(a," +",",mml:enclose:")) diff --git a/tex/generic/context/luatex-fonts-merged.lua b/tex/generic/context/luatex-fonts-merged.lua index f2a22d983..e37ed7638 100644 --- a/tex/generic/context/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : luatex-fonts-merged.lua -- parent file : luatex-fonts.lua --- merge date : 08/19/10 01:08:29 +-- merge date : 08/20/10 00:00:51 do -- begin closure to overcome local limits and interference @@ -36,7 +36,9 @@ if not string.split then end -local chr_to_esc = { +string.patterns = { } + +local escapes = { ["%"] = "%%", ["."] = "%.", ["+"] = "%+", ["-"] = "%-", ["*"] = "%*", @@ -46,10 +48,10 @@ local chr_to_esc = { ["{"] = "%{", ["}"] = "%}" } -string.chr_to_esc = chr_to_esc +string.patterns.escapes = escapes function string:esc() -- variant 2 - return (gsub(self,"(.)",chr_to_esc)) + return (gsub(self,"(.)",escapes)) end function string:unquote() @@ -116,21 +118,6 @@ function string:enhance(pattern,action) return self, n end -local chr_to_hex, hex_to_chr = { }, { } - -for i=0,255 do - local c, h = char(i), format("%02X",i) - chr_to_hex[c], hex_to_chr[h] = h, c -end - -function string:to_hex() - return (gsub(self or "","(.)",chr_to_hex)) -end - -function string:from_hex() - return (gsub(self or "","(..)",hex_to_chr)) -end - if not string.characters then local function nextchar(str, index) @@ -150,8 +137,6 @@ if not string.characters then end --- we can use format for this (neg n) - function string:rpadd(n,chr) local m = n-#self if m > 0 then @@ -172,18 +157,6 @@ end string.padd = string.rpadd -function string:split_settings() -- no {} handling, see l-aux for lpeg variant - if find(self,"=") then - local t = { } - for k,v in gmatch(self,"(%a+)=([^%,]*)") do - t[k] = v - end - return t - else - return nil - end -end - local patterns_escapes = { ["-"] = "%-", ["."] = "%.", @@ -196,7 +169,7 @@ local patterns_escapes = { ["]"] = "%]", } -function string:pattesc() +function string:escapedpattern() return (gsub(self,".",patterns_escapes)) end @@ -207,7 +180,7 @@ local simple_escapes = { ["*"] = ".*", } -function string:simpleesc() +function string:partialescapedpattern() return (gsub(self,".",simple_escapes)) end @@ -922,15 +895,11 @@ function table.is_empty(t) -- obolete, use inline code instead return not t or not next(t) end -function table.one_entry(t) -- obolete, use inline code instead +function table.has_one_entry(t) local n = next(t) return n and not next(t,n) end ---~ function table.starts_at(t) -- obsolete, not nice anyway ---~ return ipairs(t,1)(t,0) ---~ end - function table.tohash(t,value) local h = { } if t then @@ -1352,7 +1321,7 @@ function table.unnest(t) -- bad name return f end -table.flatten_one_level = table.unnest +table.flattenonelevel = table.unnest -- a better one: @@ -1372,51 +1341,6 @@ end table.flattened = flattened --- the next three may disappear - -function table.remove_value(t,value) -- todo: n - if value then - for i=1,#t do - if t[i] == value then - remove(t,i) - -- remove all, so no: return - end - end - end -end - -function table.insert_before_value(t,value,str) - if str then - if value then - for i=1,#t do - if t[i] == value then - insert(t,i,str) - return - end - end - end - insert(t,1,str) - elseif value then - insert(t,1,value) - end -end - -function table.insert_after_value(t,value,str) - if str then - if value then - for i=1,#t do - if t[i] == value then - insert(t,i+1,str) - return - end - end - end - t[#t+1] = str - elseif value then - t[#t+1] = value - end -end - local function are_equal(a,b,n,m) -- indexed if a and b and #a == #b then n = n or 1 @@ -1531,7 +1455,7 @@ function table.hexed(t,seperator) return concat(tt,seperator or " ") end -function table.reverse_hash(h) -- needs another name +function table.swaphash(h) -- needs another name local r = { } for k,v in next, h do r[v] = lower(gsub(k," ","")) @@ -1549,36 +1473,6 @@ function table.reverse(t) return tt end -function table.insert_before_value(t,value,extra) - for i=1,#t do - if t[i] == extra then - remove(t,i) - end - end - for i=1,#t do - if t[i] == value then - insert(t,i,extra) - return - end - end - insert(t,1,extra) -end - -function table.insert_after_value(t,value,extra) - for i=1,#t do - if t[i] == extra then - remove(t,i) - end - end - for i=1,#t do - if t[i] == value then - insert(t,i+1,extra) - return - end - end - insert(t,#t+1,extra) -end - function table.sequenced(t,sep,simple) -- hash only local s = { } for k, v in sortedhash(t) do @@ -1613,13 +1507,13 @@ if not modules then modules = { } end modules ['l-file'] = { -- needs a cleanup -file = file or { } +file = file or { } local file = file local insert, concat = table.insert, table.concat local find, gmatch, match, gsub, sub, char = string.find, string.gmatch, string.match, string.gsub, string.sub, string.char local lpegmatch = lpeg.match -local getcurrentdir = lfs.currentdir +local getcurrentdir, attributes = lfs.currentdir, lfs.attributes local P, R, S, C, Cs, Cp, Cc = lpeg.P, lpeg.R, lpeg.S, lpeg.C, lpeg.Cs, lpeg.Cp, lpeg.Cc @@ -1751,18 +1645,18 @@ end --~ print(file.join("http:///a","/y")) --~ print(file.join("//nas-1","/y")) -function file.iswritable(name) - local a = lfs.attributes(name) or lfs.attributes(dirname(name,".")) +function file.is_writable(name) + local a = attributes(name) or attributes(dirname(name,".")) return a and sub(a.permissions,2,2) == "w" end -function file.isreadable(name) - local a = lfs.attributes(name) +function file.is_readable(name) + local a = attributes(name) return a and sub(a.permissions,1,1) == "r" end -file.is_readable = file.isreadable -file.is_writable = file.iswritable +file.isreadable = file.is_readable -- depricated +file.iswritable = file.is_writable -- depricated -- todo: lpeg @@ -1794,7 +1688,7 @@ end --~ function file.old_collapse_path(str) -- fails on b.c/.. --~ str = gsub(str,"\\","/") --~ if find(str,"/") then ---~ str = gsub(str,"^%./",(gsub(lfs.currentdir(),"\\","/")) .. "/") -- ./xx in qualified +--~ str = gsub(str,"^%./",(gsub(getcurrentdir(),"\\","/")) .. "/") -- ./xx in qualified --~ str = gsub(str,"/%./","/") --~ local n, m = 1, 1 --~ while n > 0 or m > 0 do @@ -2023,8 +1917,8 @@ end --~ -- todo: --~ --~ if os.type == "windows" then ---~ local currentdir = lfs.currentdir ---~ function lfs.currentdir() +--~ local currentdir = getcurrentdir +--~ function getcurrentdir() --~ return (gsub(currentdir(),"\\","/")) --~ end --~ end @@ -2364,7 +2258,7 @@ do cachepaths = string.split(cachepaths,os.type == "windows" and ";" or ":") for i=1,#cachepaths do - if file.iswritable(cachepaths[i]) then + if file.is_writable(cachepaths[i]) then writable = file.join(cachepaths[i],"luatex-cache") lfs.mkdir(writable) writable = file.join(writable,caches.namespace) @@ -2374,7 +2268,7 @@ do end for i=1,#cachepaths do - if file.isreadable(cachepaths[i]) then + if file.is_readable(cachepaths[i]) then readables[#readables+1] = file.join(cachepaths[i],"luatex-cache",caches.namespace) end end @@ -2417,9 +2311,9 @@ local function makefullname(path,name) end end -function caches.iswritable(path,name) +function caches.is_writable(path,name) local fullname = makefullname(path,name) - return fullname and file.iswritable(fullname) + return fullname and file.is_writable(fullname) end function caches.loaddata(paths,name) @@ -2527,7 +2421,7 @@ function containers.define(category, subcategory, version, enabled) end function containers.is_usable(container, name) - return container.enabled and caches and caches.iswritable(container.writable, name) + return container.enabled and caches and caches.is_writable(container.writable, name) end function containers.is_valid(container, name) @@ -4825,9 +4719,9 @@ local baselines = { ['romn'] = 'Roman baseline' } -local to_scripts = table.reverse_hash(scripts ) -local to_languages = table.reverse_hash(languages) -local to_features = table.reverse_hash(features ) +local to_scripts = table.swaphash(scripts ) +local to_languages = table.swaphash(languages) +local to_features = table.swaphash(features ) tables.scripts = scripts tables.languages = languages @@ -6916,7 +6810,7 @@ local lists = { -- why local fonts.manipulators, } -function otf.set_features(tfmdata,features) +function otf.setfeatures(tfmdata,features) local processes = { } if features and next(features) then local mode = tfmdata.mode or features.mode or "base" @@ -6978,52 +6872,6 @@ tfmdata.mode = mode return processes, features end -function otf.otf_to_tfm(specification) - local name = specification.name - local sub = specification.sub - local filename = specification.filename - local format = specification.format - local features = specification.features.normal - local cache_id = specification.hash - local tfmdata = containers.read(tfm.cache,cache_id) ---~ print(cache_id) - if not tfmdata then - local otfdata = otf.load(filename,format,sub,features and features.featurefile) - if otfdata and next(otfdata) then - otfdata.shared = otfdata.shared or { - featuredata = { }, - anchorhash = { }, - initialized = false, - } - tfmdata = otf.copy_to_tfm(otfdata,cache_id) - if tfmdata and next(tfmdata) then - tfmdata.unique = tfmdata.unique or { } - tfmdata.shared = tfmdata.shared or { } -- combine - local shared = tfmdata.shared - shared.otfdata = otfdata - shared.features = features -- default - shared.dynamics = { } - shared.processes = { } - shared.set_dynamics = otf.set_dynamics -- fast access and makes other modules independent - -- this will be done later anyway, but it's convenient to have - -- them already for fast access - tfmdata.luatex = otfdata.luatex - tfmdata.indices = otfdata.luatex.indices - tfmdata.unicodes = otfdata.luatex.unicodes - tfmdata.marks = otfdata.luatex.marks - tfmdata.originals = otfdata.luatex.originals - tfmdata.changed = { } - tfmdata.has_italic = otfdata.metadata.has_italic - if not tfmdata.language then tfmdata.language = 'dflt' end - if not tfmdata.script then tfmdata.script = 'dflt' end - shared.processes, shared.features = otf.set_features(tfmdata,fonts.define.check(features,otf.features.default)) - end - end - containers.write(tfm.cache,cache_id,tfmdata) - end - return tfmdata -end - --~ { --~ ['boundingbox']={ 95, -458, 733, 1449 }, --~ ['class']="base", @@ -7054,7 +6902,7 @@ fonts.formats.ttc = "truetype" fonts.formats.ttf = "truetype" fonts.formats.otf = "opentype" -function otf.copy_to_tfm(data,cache_id) -- we can save a copy when we reorder the tma to unicode (nasty due to one->many) +local function copytotfm(data,cache_id) -- we can save a copy when we reorder the tma to unicode (nasty due to one->many) if data then local glyphs, pfminfo, metadata = data.glyphs or { }, data.pfminfo or { }, data.metadata or { } local luatex = data.luatex @@ -7221,10 +7069,56 @@ function otf.copy_to_tfm(data,cache_id) -- we can save a copy when we reorder th end end +local function otftotfm(specification) + local name = specification.name + local sub = specification.sub + local filename = specification.filename + local format = specification.format + local features = specification.features.normal + local cache_id = specification.hash + local tfmdata = containers.read(tfm.cache,cache_id) +--~ print(cache_id) + if not tfmdata then + local otfdata = otf.load(filename,format,sub,features and features.featurefile) + if otfdata and next(otfdata) then + otfdata.shared = otfdata.shared or { + featuredata = { }, + anchorhash = { }, + initialized = false, + } + tfmdata = copytotfm(otfdata,cache_id) + if tfmdata and next(tfmdata) then + tfmdata.unique = tfmdata.unique or { } + tfmdata.shared = tfmdata.shared or { } -- combine + local shared = tfmdata.shared + shared.otfdata = otfdata + shared.features = features -- default + shared.dynamics = { } + shared.processes = { } + shared.setdynamics = otf.setdynamics -- fast access and makes other modules independent + -- this will be done later anyway, but it's convenient to have + -- them already for fast access + tfmdata.luatex = otfdata.luatex + tfmdata.indices = otfdata.luatex.indices + tfmdata.unicodes = otfdata.luatex.unicodes + tfmdata.marks = otfdata.luatex.marks + tfmdata.originals = otfdata.luatex.originals + tfmdata.changed = { } + tfmdata.has_italic = otfdata.metadata.has_italic + if not tfmdata.language then tfmdata.language = 'dflt' end + if not tfmdata.script then tfmdata.script = 'dflt' end + shared.processes, shared.features = otf.setfeatures(tfmdata,fonts.define.check(features,otf.features.default)) + end + end + containers.write(tfm.cache,cache_id,tfmdata) + end + return tfmdata +end + otf.features.register('mathsize') -function tfm.read_from_open_type(specification) - local tfmtable = otf.otf_to_tfm(specification) +function tfm.read_from_open_type(specification) -- wrong namespace + local tfmtable = otftotfm(specification) if tfmtable then local otfdata = tfmtable.shared.otfdata tfmtable.name = specification.name @@ -7336,10 +7230,12 @@ otf.features.default = otf.features.default or { } local context_setups = fonts.define.specify.context_setups local context_numbers = fonts.define.specify.context_numbers +-- todo: dynamics namespace + local a_to_script = { } otf.a_to_script = a_to_script local a_to_language = { } otf.a_to_language = a_to_language -function otf.set_dynamics(font,dynamics,attribute) +function otf.setdynamics(font,dynamics,attribute) local features = context_setups[context_numbers[attribute]] -- can be moved to caller if features then local script = features.script or 'dflt' @@ -7378,7 +7274,7 @@ function otf.set_dynamics(font,dynamics,attribute) tfmdata.shared.features = { } -- end of save local set = fonts.define.check(features,otf.features.default) - dsla = otf.set_features(tfmdata,set) + dsla = otf.setfeatures(tfmdata,set) if trace_dynamics then report_otf("setting dynamics %s: attribute %s, script %s, language %s, set: %s",context_numbers[attribute],attribute,script,language,table.sequenced(set)) end @@ -7730,7 +7626,7 @@ local function prepare_base_substitutions(tfmdata,kind,value) -- we can share so end end -local function prepare_base_kerns(tfmdata,kind,value) -- todo what kind of kerns, currently all +local function preparebasekerns(tfmdata,kind,value) -- todo what kind of kerns, currently all if value then local otfdata = tfmdata.shared.otfdata local validlookups, lookuplist = otf.collect_lookups(otfdata,kind,tfmdata.script,tfmdata.language) @@ -7800,10 +7696,10 @@ local supported_gpos = { 'kern' } -function otf.features.register_base_substitution(tag) +function otf.features.registerbasesubstitution(tag) supported_gsub[#supported_gsub+1] = tag end -function otf.features.register_base_kern(tag) +function otf.features.registerbasekern(tag) supported_gsub[#supported_gpos+1] = tag end @@ -7827,7 +7723,7 @@ function fonts.initializers.base.otf.features(tfmdata,value) for f=1,#supported_gpos do local feature = supported_gpos[f] local value = features[feature] - prepare_base_kerns(tfmdata,feature,features[feature]) + preparebasekerns(tfmdata,feature,features[feature]) if value then h[#h+1] = feature .. "=" .. tostring(value) end @@ -11062,11 +10958,11 @@ features['tlig'] = 'TeX Ligatures' features['trep'] = 'TeX Replacements' features['anum'] = 'Arabic Digits' -local register_base_substitution = otf.features.register_base_substitution +local registerbasesubstitution = otf.features.registerbasesubstitution -register_base_substitution('tlig') -register_base_substitution('trep') -register_base_substitution('anum') +registerbasesubstitution('tlig') +registerbasesubstitution('trep') +registerbasesubstitution('anum') -- the functionality is defined elsewhere @@ -12134,7 +12030,7 @@ end -- bonus -function fonts.otf.name_to_slot(name) +function fonts.otf.nametoslot(name) local tfmdata = fonts.ids[font.current()] if tfmdata and tfmdata.shared then local otfdata = tfmdata.shared.otfdata @@ -12145,7 +12041,7 @@ end function fonts.otf.char(n) if type(n) == "string" then - n = fonts.otf.name_to_slot(n) + n = fonts.otf.nametoslot(n) end if type(n) == "number" then tex.sprint("\\char" .. n) |