From 55575b7cad42dac55b4a5f699c33363489cb502d Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Fri, 25 Jan 2019 20:34:48 +0100 Subject: 2019-01-25 20:15:00 --- tex/context/base/mkii/cont-new.mkii | 2 +- tex/context/base/mkii/context.mkii | 2 +- tex/context/base/mkiv/cont-new.mkiv | 2 +- tex/context/base/mkiv/context.mkiv | 5 +- tex/context/base/mkiv/core-con.lua | 336 ++++++++++++--------- tex/context/base/mkiv/core-con.mkiv | 43 ++- tex/context/base/mkiv/font-ctx.lua | 13 +- tex/context/base/mkiv/l-lua.lua | 2 - tex/context/base/mkiv/lpdf-ini.lua | 2 +- tex/context/base/mkiv/math-noa.lua | 2 +- tex/context/base/mkiv/meta-blb.lua | 48 +-- tex/context/base/mkiv/meta-tex.lua | 6 +- tex/context/base/mkiv/node-nut.lua | 12 +- tex/context/base/mkiv/node-pro.lua | 16 +- tex/context/base/mkiv/node-shp.lua | 1 - tex/context/base/mkiv/page-str.lua | 73 +++-- tex/context/base/mkiv/status-files.pdf | Bin 26052 -> 26375 bytes tex/context/base/mkiv/status-lua.pdf | Bin 268471 -> 235485 bytes tex/context/base/mkiv/supp-box.lua | 62 ++-- tex/context/base/mkiv/symb-emj.lua | 27 +- tex/context/base/mkiv/task-ini.lua | 2 +- tex/context/base/mkiv/trac-inf.lua | 10 +- tex/context/base/mkiv/typo-itc.lua | 22 +- tex/context/base/mkiv/util-jsn.lua | 95 +++--- tex/context/base/mkiv/util-str.lua | 255 +++++++--------- tex/context/interface/mkiv/i-context.pdf | Bin 864657 -> 913818 bytes tex/context/interface/mkiv/i-readme.pdf | Bin 60773 -> 25093 bytes tex/generic/context/luatex/luatex-fonts-merged.lua | 185 +++++------- 28 files changed, 637 insertions(+), 586 deletions(-) (limited to 'tex') diff --git a/tex/context/base/mkii/cont-new.mkii b/tex/context/base/mkii/cont-new.mkii index d46a2dc0d..d3e4c17e9 100644 --- a/tex/context/base/mkii/cont-new.mkii +++ b/tex/context/base/mkii/cont-new.mkii @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2019.01.19 12:06} +\newcontextversion{2019.01.25 20:06} %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/mkii/context.mkii b/tex/context/base/mkii/context.mkii index b3946bb4f..df4b07429 100644 --- a/tex/context/base/mkii/context.mkii +++ b/tex/context/base/mkii/context.mkii @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2019.01.19 12:06} +\edef\contextversion{2019.01.25 20:06} %D For those who want to use this: diff --git a/tex/context/base/mkiv/cont-new.mkiv b/tex/context/base/mkiv/cont-new.mkiv index 2de482d5b..2aa91bfcd 100644 --- a/tex/context/base/mkiv/cont-new.mkiv +++ b/tex/context/base/mkiv/cont-new.mkiv @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2019.01.19 12:06} +\newcontextversion{2019.01.25 20:06} %D This file is loaded at runtime, thereby providing an excellent place for %D hacks, patches, extensions and new features. diff --git a/tex/context/base/mkiv/context.mkiv b/tex/context/base/mkiv/context.mkiv index 1ab97d706..824690bd1 100644 --- a/tex/context/base/mkiv/context.mkiv +++ b/tex/context/base/mkiv/context.mkiv @@ -42,7 +42,7 @@ %D has to match \type {YYYY.MM.DD HH:MM} format. \edef\contextformat {\jobname} -\edef\contextversion{2019.01.19 12:06} +\edef\contextversion{2019.01.25 20:06} \edef\contextkind {beta} %D For those who want to use this: @@ -213,6 +213,7 @@ \loadmkvifile{file-syn} \loadmkvifile{file-mod} +\loadmarkfile{core-sys} \loadmarkfile{core-con} \loadmarkfile{cont-fil} @@ -306,7 +307,7 @@ \loadmarkfile{strc-lab} \loadmarkfile{strc-syn} -\loadmarkfile{core-sys} +% \loadmarkfile{core-sys} \loadmarkfile{page-var} \loadmkvifile{page-otr} diff --git a/tex/context/base/mkiv/core-con.lua b/tex/context/base/mkiv/core-con.lua index 87b4c063e..a17c57208 100644 --- a/tex/context/base/mkiv/core-con.lua +++ b/tex/context/base/mkiv/core-con.lua @@ -33,6 +33,7 @@ local setmetatableindex = table.setmetatableindex local formatters = string.formatters local variables = interfaces.variables local constants = interfaces.constants +local addformatter = utilities.strings.formatters.add local texset = tex.set @@ -42,6 +43,9 @@ local converters = converters languages = languages or { } local languages = languages +local helpers = converters.helpers or { } +converters.helpers = helpers + local ctx_labeltext = context.labeltext local ctx_LABELTEXT = context.LABELTEXT local ctx_space = context.space @@ -1222,45 +1226,75 @@ setmetatableindex(months, function(t,k) return "unknown" end) setmetatableindex(days, function(t,k) return "unknown" end) setmetatableindex(monthmnems, function(t,k) return months[k] .. ":mnem" end) -local function dayname(n) - return days[n] -end +do -local function weekdayname(day,month,year) - return days[weekday(day,month,year)] -end + local function dayname(n) + ctx_labeltext(days[n]) + end -local function monthname(n) - return months[n] -end + local function weekdayname(day,month,year) + ctx_labeltext(days[weekday(day,month,year)]) + end -local function monthmnem(n) - return monthmnems[n] -end + local function monthname(n) + ctx_labeltext(months[n]) + end -implement { - name = "dayname", - actions = { dayname, ctx_labeltext }, - arguments = "integer", -} + local function monthmnem(n) + ctx_labeltext(monthmnems[n]) + end -implement { - name = "weekdayname", - actions = { weekdayname, ctx_labeltext }, - arguments = { "integer", "integer", "integer" } -} + implement { + name = "dayname", + actions = dayname, + arguments = "integer", + } -implement { - name = "monthname", - actions = { monthname, ctx_labeltext }, - arguments = { "integer" } -} + implement { + name = "weekdayname", + actions = weekdayname, + arguments = { "integer", "integer", "integer" } + } -implement { - name = "monthmnem", - actions = { monthmnem, ctx_labeltext }, - arguments = { "integer" } -} + implement { + name = "monthname", + actions = monthname, + arguments = { "integer" } + } + + implement { + name = "monthmnem", + actions = monthmnem, + arguments = { "integer" } + } + + local f_month = formatters["\\month{%s}"] + local f_monthshort = formatters["\\monthshort{%s}"] + local f_weekday = formatters["\\weekday{%s}"] + local f_dayoftheweek = formatters["\\dayoftheweek{%s}{%s}{%s}"] + + local function tomonth(m) + return f_month(tonumber(m) or 1) + end + + local function tomonthshort(m) + return f_monthshort(tonumber(m) or 1) + end + + local function toweekday(d) + return f_weekday(tonumber(d) or 1) + end + + local function todayoftheweek(d,m,y) + return f_dayoftheweek(tonumber(d) or 1,tonumber(m) or 1,tonumber(y) or 2000) + end + + addformatter(formatters,"month", [[tomonth(%s)]], { tomonth = tomonth }) + addformatter(formatters,"monthshort", [[tomonthshort(%s)]], { tomonthshort = tomonthshort }) + addformatter(formatters,"weekday", [[toweekday(%s)]], { toweekday = toweekday }) + addformatter(formatters,"dayoftheweek",[[todayoftheweek(%s,%s,%s)]],{ todayoftheweek = todayoftheweek }) + +end -- a prelude to a function that we can use at the lua end @@ -1287,125 +1321,146 @@ local variants = { jalali = setmetatableindex(function(t,k) return months[k] .. ":jalali" end), } -local function currentdate(str,currentlanguage) -- second argument false : no label - local list = utilities.parsers.settings_to_array(str) - local splitlabel = languages.labels.split or string.itself -- we need to get the loading order right - local year = tex.year - local month = tex.month - local day = tex.day - local auto = true - if currentlanguage == "" then - currentlanguage = false - end - for i=1,#list do - local entry = list[i] - local convert = dateconverters[entry] - if convert then - year, month, day = convert(year,month,day) - else - local tag, plus = splitlabel(entry) - local ordinal, mnemonic, whatordinal, highordinal = false, false, nil, false - if not tag then - tag = entry - elseif plus == "+" or plus == "ord" then - ordinal = true - elseif plus == "++" or plus == "highord" then - ordinal = true - highordinal = true - -- elseif plus == "mnem" then - -- mnemonic = true - elseif plus then -- elseif plus == "mnem" then - mnemonic = variants[plus] - end - if not auto and spaced[tag] then - ctx_space() - end - auto = false - if tag == v_year or tag == "y" or tag == "Y" then - context(year) - elseif tag == "yy" or tag == "YY" then - context("%02i",year % 100) - elseif tag == v_month or tag == "m" then - if currentlanguage == false then - context(Word(months[month])) - elseif mnemonic then - ctx_labeltext(variables[mnemonic[month]]) - else - ctx_labeltext(variables[months[month]]) +do + + local function currentdate(str,currentlanguage,year,month,day) -- second argument false : no label + local list = utilities.parsers.settings_to_array(str) + local splitlabel = languages.labels.split or string.itself -- we need to get the loading order right + -- local year = tex.year + -- local month = tex.month + -- local day = tex.day + local auto = true + if currentlanguage == "" then + currentlanguage = false + end + for i=1,#list do + local entry = list[i] + local convert = dateconverters[entry] + if convert then + year, month, day = convert(year,month,day) + else + local tag, plus = splitlabel(entry) + local ordinal, mnemonic, whatordinal, highordinal = false, false, nil, false + if not tag then + tag = entry + elseif plus == "+" or plus == "ord" then + ordinal = true + elseif plus == "++" or plus == "highord" then + ordinal = true + highordinal = true + -- elseif plus == "mnem" then + -- mnemonic = true + elseif plus then -- elseif plus == "mnem" then + mnemonic = variants[plus] end - elseif tag == v_MONTH then - if currentlanguage == false then - context(Word(variables[months[month]])) - elseif mnemonic then - ctx_LABELTEXT(variables[mnemonic[month]]) - else - ctx_LABELTEXT(variables[months[month]]) + if not auto and spaced[tag] then + ctx_space() end - elseif tag == "mm" then - context("%02i",month) - elseif tag == "M" then - context(month) - elseif tag == v_day or tag == "d" then - if currentlanguage == false then + auto = false + if tag == v_year or tag == "y" or tag == "Y" then + context(year) + elseif tag == "yy" or tag == "YY" then + context("%02i",year % 100) + elseif tag == v_month or tag == "m" then + if currentlanguage == false then + context(Word(months[month])) + elseif mnemonic then + ctx_labeltext(variables[mnemonic[month]]) + else + ctx_labeltext(variables[months[month]]) + end + elseif tag == v_MONTH then + if currentlanguage == false then + context(Word(variables[months[month]])) + elseif mnemonic then + ctx_LABELTEXT(variables[mnemonic[month]]) + else + ctx_LABELTEXT(variables[months[month]]) + end + elseif tag == "mm" then + context("%02i",month) + elseif tag == "M" then + context(month) + elseif tag == v_day or tag == "d" then + if currentlanguage == false then + context(day) + else + ctx_convertnumber(v_day,day) -- why not direct + end + whatordinal = day + elseif tag == "dd" then + context("%02i",day) + whatordinal = day + elseif tag == "D" then context(day) - else - ctx_convertnumber(v_day,day) -- why not direct - end - whatordinal = day - elseif tag == "dd" then - context("%02i",day) - whatordinal = day - elseif tag == "D" then - context(day) - whatordinal = day - elseif tag == v_weekday or tag == "w" then - local wd = weekday(day,month,year) - if currentlanguage == false then - context(Word(days[wd])) - else - ctx_labeltext(variables[days[wd]]) - end - elseif tag == v_WEEKDAY then - local wd = weekday(day,month,year) - if currentlanguage == false then - context(Word(days[wd])) - else - ctx_LABELTEXT(variables[days[wd]]) + whatordinal = day + elseif tag == v_weekday or tag == "w" then + local wd = weekday(day,month,year) + if currentlanguage == false then + context(Word(days[wd])) + else + ctx_labeltext(variables[days[wd]]) + end + elseif tag == v_WEEKDAY then + local wd = weekday(day,month,year) + if currentlanguage == false then + context(Word(days[wd])) + else + ctx_LABELTEXT(variables[days[wd]]) + end + elseif tag == "W" then + context(weekday(day,month,year)) + elseif tag == v_referral then + context("%04i%02i%02i",year,month,day) + elseif tag == v_space or tag == "\\ " then + ctx_space() + auto = true + elseif tag ~= "" then + context(tag) + auto = true end - elseif tag == "W" then - context(weekday(day,month,year)) - elseif tag == v_referral then - context("%04i%02i%02i",year,month,day) - elseif tag == v_space or tag == "\\ " then - ctx_space() - auto = true - elseif tag ~= "" then - context(tag) - auto = true - end - if ordinal and whatordinal then - if currentlanguage == false then - -- ignore - else - context[highordinal and "highordinalstr" or "ordinalstr"](converters.ordinal(whatordinal,currentlanguage)) + if ordinal and whatordinal then + if currentlanguage == false then + -- ignore + else + context[highordinal and "highordinalstr" or "ordinalstr"](converters.ordinal(whatordinal,currentlanguage)) + end end end end end -end + implement { + name = "currentdate", + arguments = { "string", "string", "string", "integer", "integer", "integer" }, + actions = function(pattern,default,language,year,month,day) + currentdate( + pattern == "" and default or pattern, + language == "" and false or language, + year, month, day + ) + end, + } + local function todate(s,y,m,d) + if y or m or d then + return formatters["\\date[y=%s,m=%s,d=%s][%s]\\relax"](y or "",m or "",d or "",s or "") + else + return formatters["\\currentdate[%s]\\relax"](s) + end + end -implement { - name = "currentdate", - arguments = "3 strings", - actions = function(pattern,default,language) - currentdate( - pattern == "" and default or pattern, - language == "" and false or language - ) - end, -} + addformatter(formatters,"date", [[todate(...)]], { todate = todate }) + + -- context("one: %4!date!","MONTH",2020,12,11) context.par() + -- context("one: %4!date!","month",2020,12,11) context.par() + -- context("one: %4!date!","year,-,mm,-,dd",2020,12,11) context.par() + + -- context("two: %3!date!","MONTH",false,12) context.par() + -- context("two: %3!date!","month",false,12) context.par() + -- context("two: %3!date!","year,-,mm,-,dd",false,12) context.par() + +end implement { name = "unihex", @@ -1586,3 +1641,4 @@ implement { } } } + diff --git a/tex/context/base/mkiv/core-con.mkiv b/tex/context/base/mkiv/core-con.mkiv index cc42e9b46..85b988c88 100644 --- a/tex/context/base/mkiv/core-con.mkiv +++ b/tex/context/base/mkiv/core-con.mkiv @@ -408,15 +408,33 @@ %D %D \typebuffer \getbuffer +\setupsystem + [\c!y=\normalyear, + \c!m=\normalmonth, + \c!d=\normalday] + \newtoks \everycurrentdate +\def\syst_converters_check_date + {\edef\temp{\systemparameter\c!y}\scratchcounterone \ifx\temp\empty\normalyear \else\temp\fi + \edef\temp{\systemparameter\c!m}\scratchcountertwo \ifx\temp\empty\normalmonth\else\temp\fi + \edef\temp{\systemparameter\c!d}\scratchcounterthree\ifx\temp\empty\normalday \else\temp\fi} + \unexpanded\def\currentdate {\dosingleempty\syst_converters_current_date} \def\syst_converters_current_date[#1]% - {\begingroup + {\dontleavehmode + \begingroup \the\everycurrentdate - \clf_currentdate{#1}{\currentdatespecification}{\labellanguage}% + \syst_converters_check_date + \clf_currentdate + {#1}% + {\currentdatespecification}% + {\labellanguage}% + \scratchcounterone + \scratchcountertwo + \scratchcounterthree \endgroup} \unexpanded\def\date @@ -425,19 +443,24 @@ \def\syst_converters_date[#1][#2]% {\begingroup \iffirstargument - \letdummyparameter\c!d\normalday - \letdummyparameter\c!m\normalmonth - \letdummyparameter\c!y\normalyear - \getdummyparameters[#1]% - \normalday \directdummyparameter\c!d\relax - \normalmonth\directdummyparameter\c!m\relax - \normalyear \directdummyparameter\c!y\relax + \setupsystem[#1]% \fi + \syst_converters_check_date \syst_converters_current_date[#2]% \endgroup} \def\rawdate[#1]% expandable and no labels - {\clf_currentdate{#1}{\currentdatespecification}{}} + {\begingroup + \syst_converters_check_date + \clf_currentdate + {#1}% + {\currentdatespecification}% + {}% + \scratchcounterone + \scratchcountertwo + \scratchcounterthree + \relax + \endgroup} %D \macros %D {currenttime} diff --git a/tex/context/base/mkiv/font-ctx.lua b/tex/context/base/mkiv/font-ctx.lua index 7b8cf0d7c..98825c3b6 100644 --- a/tex/context/base/mkiv/font-ctx.lua +++ b/tex/context/base/mkiv/font-ctx.lua @@ -163,17 +163,8 @@ helpers.name = getfontname local addformatter = utilities.strings.formatters.add -if LUAVERSION < 5.2 then - - addformatter(formatters,"font:name", [["'"..fontname(%s).."'"]], "local fontname = fonts.helpers.name") - addformatter(formatters,"font:features",[["'"..sequenced(%s," ",true).."'"]],"local sequenced = table.sequenced") - -else - - addformatter(formatters,"font:name", [["'"..fontname(%s).."'"]], { fontname = helpers.name }) - addformatter(formatters,"font:features",[["'"..sequenced(%s," ",true).."'"]],{ sequenced = table.sequenced }) - -end +addformatter(formatters,"font:name", [["'"..fontname(%s).."'"]], { fontname = helpers.name }) +addformatter(formatters,"font:features",[["'"..sequenced(%s," ",true).."'"]],{ sequenced = table.sequenced }) -- ... like font-sfm or so diff --git a/tex/context/base/mkiv/l-lua.lua b/tex/context/base/mkiv/l-lua.lua index c0a787a5c..ddd499022 100644 --- a/tex/context/base/mkiv/l-lua.lua +++ b/tex/context/base/mkiv/l-lua.lua @@ -35,8 +35,6 @@ if LUAVERSION < 5.2 and jit then LUAVERSION = 5.2 end -_LUAVERSION = LUAVERSION -- for old times sake, will go away - -- lpeg if not lpeg then diff --git a/tex/context/base/mkiv/lpdf-ini.lua b/tex/context/base/mkiv/lpdf-ini.lua index ddbfd6edb..37427cde0 100644 --- a/tex/context/base/mkiv/lpdf-ini.lua +++ b/tex/context/base/mkiv/lpdf-ini.lua @@ -1538,7 +1538,7 @@ do local f_actual_text = formatters["/Span <> BDC"] local context = context - local pdfdirect = nodes.pool.pdfdirectliteral + local pdfdirect = nodes.pool.pdfdirectliteral -- we can use nuts.write deep down -- todo: use tounicode from the font mapper diff --git a/tex/context/base/mkiv/math-noa.lua b/tex/context/base/mkiv/math-noa.lua index 51fc211dd..11baaf413 100644 --- a/tex/context/base/mkiv/math-noa.lua +++ b/tex/context/base/mkiv/math-noa.lua @@ -134,7 +134,7 @@ local copy_node = nuts.copy local slide_nodes = nuts.slide local set_visual = nuts.setvisual -local mlist_to_hlist = nodes.mlist_to_hlist +local mlist_to_hlist = nuts.mlist_to_hlist local font_of_family = node.family_font diff --git a/tex/context/base/mkiv/meta-blb.lua b/tex/context/base/mkiv/meta-blb.lua index ca3e55e42..e1c0de74f 100644 --- a/tex/context/base/mkiv/meta-blb.lua +++ b/tex/context/base/mkiv/meta-blb.lua @@ -22,9 +22,12 @@ local mppoints = mp.points local mptriplet = mp.triplet local mptripletpoints = mp.tripletpoints -local texsetbox = tex.setbox -local toutf = nodes.toutf -local hpack_nodes = nodes.hpack +local nuts = nodes.nuts +local hpack = nuts.hpack +local setbox = nuts.setbox +local getwhd = nuts.getwhd +local getwidth = nuts.getwidth +local toutf = nuts.toutf local trace = false local report = logs.reporter("metapost","blobs") @@ -66,7 +69,7 @@ end local function blob_raw_dimensions(i) local blob = allblobs[i] if blob then - return blob.width, blob.height, blob.depth + return getwhd(blob) else return 0, 0, 0 end @@ -100,7 +103,7 @@ end function mp.mf_blob_add(category,blob) local tb = texblobs[category].blobs local tn = #allblobs + 1 - blob = hpack_nodes(blob) + blob = hpack(blob) allblobs[tn] = blob tb[#tb+1] = tn if trace then @@ -112,7 +115,7 @@ function mp.mf_blob_width(category,i) local index = texblobs[category].blobs[i] local blob = allblobs[index] if blob then - mppoints(blob.width or 0) + mppoints(getwidth(blob) or 0) else mpinteger(0) end @@ -130,7 +133,7 @@ function mp.mf_blob_dimensions(category,i) local index = texblobs[category].blobs[i] local blob = allblobs[index] if blob then - mptripletpoints(blob.width,blob.height,blob.depth) + mptripletpoints(getwhd(blob)) else mptriplet(0,0,0) end @@ -168,7 +171,7 @@ end -- mp.mf_blob_inject = injectblob local function getblob(box,blob) - texsetbox(box,blob_raw_content(blob)) + setbox(box,blob_raw_content(blob)) blob_raw_wipe(blob) end @@ -214,10 +217,17 @@ local italickern_code = kerncodes.italickern local a_fontkern = attributes.private("fontkern") -local takebox = tex.takebox -local flatten_list = node.flatten_discretionaries -local remove_node = nodes.remove -local flush_node = nodes.flush +local nuts = nodes.nuts +local takebox = nuts.takebox +local getlist = nuts.getlist +local getid = nuts.getid +local getsubtype = nuts.getsubtype +local setlink = nuts.setlink +local setlist = nuts.setlist +local getnext = nuts.getnext +local flatten_list = nuts.flatten_discretionaries +local remove_node = nuts.remove +local flush_node = nuts.flush local addblob = mp.mf_blob_add local newblob = mp.mf_blob_new @@ -233,7 +243,7 @@ local visible_codes = { local function initialize(category,box) local wrap = takebox(box) if wrap then - local head = wrap.list + local head = getlist(wrap) local tail = nil local temp = nil if head then @@ -242,18 +252,16 @@ local function initialize(category,box) head = flatten_list(head) local current = head while current do - local id = current.id + local id = getid(current) if visible_codes[id] then head, current, tail = remove_node(head,current) s = s + 1 n[s] = tail elseif id == kern_code then - local subtype = current.subtype + local subtype = getsubtype(current) if subtype == fontkern_code or subtype == italickern_code then -- or current[a_fontkern] head, current, temp = remove_node(head,current) - tail.next = temp - temp.prev = tail - tail = temp + setlink(tail,temp) else head, current, temp = remove_node(head,current) s = s + 1 @@ -264,13 +272,13 @@ local function initialize(category,box) s = s + 1 n[s] = temp else - current = current.next + current = getnext(current) end end for i=1,s do n[i] = addblob(category,n[i]) end - wrap.list = head + setlist(wrap,head) end flush_node(wrap) end diff --git a/tex/context/base/mkiv/meta-tex.lua b/tex/context/base/mkiv/meta-tex.lua index fdf118424..c2f72bcf3 100644 --- a/tex/context/base/mkiv/meta-tex.lua +++ b/tex/context/base/mkiv/meta-tex.lua @@ -126,11 +126,7 @@ do arguments = "2 strings", } - if LUAVERSION < 5.2 then - utilities.strings.formatters.add(formatters,"texexp", [[texexp(...)]], "local texexp = metapost.texexp") - else - utilities.strings.formatters.add(formatters,"texexp", [[texexp(...)]], { texexp = metapost.texexp }) - end + utilities.strings.formatters.add(formatters,"texexp", [[texexp(...)]], { texexp = metapost.texexp }) local f_textext = formatters[ [[textext("%s")]] ] local f_mthtext = formatters[ [[textext("\mathematics{%s}")]] ] diff --git a/tex/context/base/mkiv/node-nut.lua b/tex/context/base/mkiv/node-nut.lua index d65645f8c..f23a0cfc5 100644 --- a/tex/context/base/mkiv/node-nut.lua +++ b/tex/context/base/mkiv/node-nut.lua @@ -202,13 +202,19 @@ nuts.uses_font = direct.uses_font nuts.vpack = direct.vpack nuts.writable_spec = direct.writable_spec nuts.write = direct.write +nuts.mlist_to_hlist = direct.mlist_to_hlist -if not direct.mlist_to_hlist then -- needed +if not nuts.mlist_to_hlist then local n_mlist_to_hlist = node.mlist_to_hlist - function nuts.mlist_to_hlist(head) - return n_mlist_to_hlist(tonut(head)) + function nuts.mlist_to_hlist(head,...) + if head then + local head = n_mlist_to_hlist(tonode(head),...) + if head then + return tonut(head) + end + end end end diff --git a/tex/context/base/mkiv/node-pro.lua b/tex/context/base/mkiv/node-pro.lua index 6804d810f..5bb396d86 100644 --- a/tex/context/base/mkiv/node-pro.lua +++ b/tex/context/base/mkiv/node-pro.lua @@ -124,28 +124,20 @@ do do - local setboth = nodes.setboth - local hpack = nodes.hpack + local hpack = nodes.hpack function nodes.fullhpack(head,...) - head = hpack_filter(head) - local hp, b = hpack(head,...) - setboth(hp) - return hp, b + return hpack((hpack_filter(head)),...) end end do - local setboth = nuts.setboth - local hpack = nuts.hpack + local hpack = nuts.hpack function nuts.fullhpack(head,...) - local head = tonut(hpack_filter(tonode(head))) - local hp, b = hpack(head,...) - setboth(hp) - return hp, b + return hpack(tonut(hpack_filter(tonode(head))),...) end end diff --git a/tex/context/base/mkiv/node-shp.lua b/tex/context/base/mkiv/node-shp.lua index 55fe0843a..306e38f6a 100644 --- a/tex/context/base/mkiv/node-shp.lua +++ b/tex/context/base/mkiv/node-shp.lua @@ -50,7 +50,6 @@ local getsubtype = nuts.getsubtype local setlist = nuts.setlist local getbox = nuts.getbox -local getboxnode = nodes.getbox local removables = { [whatsitcodes.open] = true, diff --git a/tex/context/base/mkiv/page-str.lua b/tex/context/base/mkiv/page-str.lua index 4aeffffd8..ebb49a918 100644 --- a/tex/context/base/mkiv/page-str.lua +++ b/tex/context/base/mkiv/page-str.lua @@ -20,18 +20,27 @@ local implement = interfaces.implement local nodecodes = nodes.nodecodes -local slide_node_list = nodes.slide -local write_node = nodes.write -local flush_node = nodes.flush -local copy_node_list = nodes.copy_list -local vpack_node_list = nodes.vpack +local nuts = nodes.nuts +local tonut = nodes.tonut +local slide_node_list = nuts.slide +local write_node = nuts.write +local flush_node = nuts.flush +local copy_node_list = nuts.copy_list +local vpack_node_list = nuts.vpack + +local getbox = nuts.getbox +local setlink = nuts.setlink +local getlist = nuts.getlist +local setlist = nuts.setlist +local getwhd = nuts.getwhd +local setwhd = nuts.setwhd local settings_to_array = utilities.parsers.settings_to_array local enableaction = nodes.tasks.enableaction local texgetdimen = tex.getdimen -local texgetbox = tex.getbox +----- texgetbox = tex.getbox local trace_collecting = false trackers.register("streams.collecting", function(v) trace_collecting = v end) local trace_flushing = false trackers.register("streams.flushing", function(v) trace_flushing = v end) @@ -41,7 +50,11 @@ local report_streams = logs.reporter("streams") streams = streams or { } -- might move to the builders namespace local streams = streams -local data, name, stack = { }, nil, { } +-- maybe store head and tail ... first we need usage + +local data = { } +local name = nil +local stack = { } function streams.enable(newname) if newname == "default" then @@ -66,7 +79,7 @@ end function streams.collect(head,where) if name and head and name ~= "default" then - local tail = node.slide(head) + local head = tonut(head) local dana = data[name] if not dana then dana = { } @@ -75,7 +88,7 @@ function streams.collect(head,where) local last = dana[#dana] if last then local tail = slide_node_list(last) - tail.next, head.prev = head, tail + setlink(tail,head) elseif last == false then dana[#dana] = head else @@ -84,9 +97,9 @@ function streams.collect(head,where) if trace_collecting then report_streams("appending snippet %a to slot %s",name,#dana) end - return nil, true + return nil else - return head, false + return head end end @@ -118,7 +131,7 @@ function streams.flush(name,copy) -- problem: we need to migrate afterwards for i=1,dn do local di = dana[i] if di then - write_node(copy_node_list(di.list)) -- list, will be option + write_node(copy_node_list(getlist(di))) -- list, will be option end end if copy then @@ -131,8 +144,8 @@ function streams.flush(name,copy) -- problem: we need to migrate afterwards for i=1,dn do local di = dana[i] if di then - write_node(di.list) -- list, will be option - di.list = nil + write_node(getlist(di)) -- list, will be option + setlist(di) flush_node(di) end end @@ -167,7 +180,7 @@ function streams.synchronize(list) -- this is an experiment ! local slot = dana[m] if slot then local vbox = vpack_node_list(slot) - local ht, dp = vbox.height, vbox.depth + local wd, ht, dp = getwhd(vbox) if ht > height then height = ht end @@ -191,32 +204,36 @@ function streams.synchronize(list) -- this is an experiment ! local dana = data[name] local vbox = dana[m] if vbox then - local delta_height = height - vbox.height - local delta_depth = depth - vbox.depth + local wd, ht, dp = getwhd(vbox) + local delta_height = height - ht + local delta_depth = depth - dp if delta_height > 0 or delta_depth > 0 then if false then -- actually we need to add glue and repack - vbox.height, vbox.depth = height, depth + setwhd(vbox,false,height,depth) if trace_flushing then report_streams("slot %s of %a with delta (%p,%p) is compensated",m,i,delta_height,delta_depth) end else -- this is not yet ok as we also need to keep an eye on vertical spacing -- so we might need to do some splitting or whatever - local tail = vbox.list and slide_node_list(vbox.list) - local n, delta = 0, delta_height -- for tracing + local list = getlist(vbox) + local tail = list and slide_node_list(list) + local n = 0 + local delta = delta_height -- for tracing while delta > 0 do -- we need to add some interline penalties - local line = copy_node_list(texgetbox("strutbox")) - line.height, line.depth = strutht, strutdp + local line = copy_node_list(getbox("strutbox")) + setwhd(line,false,strutht,strutdp) if tail then - tail.next, line.prev = line, tail + setlink(tail,line) end - tail = line - n, delta = n +1, delta - struthtdp + tail = line + n = n + 1 + delta = delta - struthtdp end - dana[m] = vpack_node_list(vbox.list) - vbox.list = nil + dana[m] = vpack_node_list(getlist(vbox)) + setlist(vbox) flush_node(vbox) if trace_flushing then report_streams("slot %s:%s with delta (%p,%p) is compensated by %s lines",m,i,delta_height,delta_depth,n) @@ -230,6 +247,8 @@ function streams.synchronize(list) -- this is an experiment ! end end +-- hm, nut or node + tasks.appendaction("mvlbuilders", "normalizers", "streams.collect") tasks.disableaction("mvlbuilders", "streams.collect") diff --git a/tex/context/base/mkiv/status-files.pdf b/tex/context/base/mkiv/status-files.pdf index d02146c5a..591118f62 100644 Binary files a/tex/context/base/mkiv/status-files.pdf and b/tex/context/base/mkiv/status-files.pdf differ diff --git a/tex/context/base/mkiv/status-lua.pdf b/tex/context/base/mkiv/status-lua.pdf index 85c6b3477..e4ab24ae0 100644 Binary files a/tex/context/base/mkiv/status-lua.pdf and b/tex/context/base/mkiv/status-lua.pdf differ diff --git a/tex/context/base/mkiv/supp-box.lua b/tex/context/base/mkiv/supp-box.lua index e57eaba54..a22eb8f69 100644 --- a/tex/context/base/mkiv/supp-box.lua +++ b/tex/context/base/mkiv/supp-box.lua @@ -460,18 +460,20 @@ end do - local flush_list = nodes.flush_list - local copy_list = nodes.copy_list - local takebox = nodes.takebox - local texsetbox = tex.setbox - - local new_hlist = nodes.pool.hlist - - local boxes = { } - nodes.boxes = boxes - local cache = table.setmetatableindex("table") - local report = logs.reporter("boxes","cache") - local trace = false + local nuts = nodes.nuts + local tonode = nuts.tonode + local takebox = nuts.takebox + local flush_list = nuts.flush_list + local copy_list = nuts.copy_list + local getwhd = nuts.getwhd + local setbox = nuts.setbox + local new_hlist = nuts.pool.hlist + + local boxes = { } + nodes.boxes = boxes + local cache = table.setmetatableindex("table") + local report = logs.reporter("boxes","cache") + local trace = false trackers.register("nodes.boxes",function(v) trace = v end) @@ -503,7 +505,9 @@ do if trace then report("category %a, name %a, %s (%s)",category,name,"direct",b and "content" or "empty") end - return b or nil + if b then + return tonode(b) + end end function boxes.restore(category,name,box,copy) @@ -524,11 +528,9 @@ do if trace then report("category %a, name %a, %s (%s)",category,name,"restore",b and "content" or "empty") end - texsetbox(box,b or nil) + setbox(box,b or nil) end - local getwhd = nodes.getwhd - function boxes.dimensions(category,name) name = tonumber(name) or name local b = cache[category][name] @@ -608,19 +610,19 @@ do actions = boxes.reset, } - implement { - name = "lastlinewidth", - actions = function() - local head = tex.lists.page_head - -- list dimensions returns 3 value but we take the first - context(head and getdimensions(getlist(find_tail(tonut(tex.lists.page_head)))) or 0) - end - } +end - interfaces.implement { - name = "shiftbox", - arguments = { "integer", "dimension" }, - actions = function(n,d) setshift(getbox(n),d) end, - } +implement { + name = "lastlinewidth", + actions = function() + local head = tex.lists.page_head + -- list dimensions returns 3 value but we take the first + context(head and getdimensions(getlist(find_tail(tonut(tex.lists.page_head)))) or 0) + end +} -end +interfaces.implement { + name = "shiftbox", + arguments = { "integer", "dimension" }, + actions = function(n,d) setshift(getbox(n),d) end, +} diff --git a/tex/context/base/mkiv/symb-emj.lua b/tex/context/base/mkiv/symb-emj.lua index 3075e0985..d6e2aebea 100644 --- a/tex/context/base/mkiv/symb-emj.lua +++ b/tex/context/base/mkiv/symb-emj.lua @@ -19,32 +19,27 @@ local protectglyphs = nodes.handlers.protectglyphs local tonodes = nodes.tonodes local currentfont = font.current --- fast enough, no need to memoize - -local glyph_code = nodes.nodecodes.glyph -local remove_node = nodes.remove -local getid = nodes.getid -local getnext = nodes.getnext -local getchar = nodes.getchar +local nuts = nodes.nuts +local tonode = nuts.tonode +local tonut = nuts.tonut +local remove_node = nuts.remove +local isglyph = nuts.isglyph local function removemodifiers(head) + local head = tonut(head) local current = head while current do - if getid(current) == glyph_code then - local char = getchar(current) -- using categories is too much - if char == 0x200D or (char >= 0x1F3FB and char <= 0x1F3FF) then - head, current = remove_node(head,current,true) - else - current = getnext(current) - end + local char, id = isglyph(current) + if char and char == 0x200D or (char >= 0x1F3FB and char <= 0x1F3FF) then + head, current = remove_node(head,current,true) else current = getnext(current) end end - return head + return tonode(head) end --- attributes +-- fast enough, no need to memoize, maybe use attributes local function checkedemoji(name,id) local str = resolvedemoji(name) diff --git a/tex/context/base/mkiv/task-ini.lua b/tex/context/base/mkiv/task-ini.lua index cfff3625a..d9ce5dcd5 100644 --- a/tex/context/base/mkiv/task-ini.lua +++ b/tex/context/base/mkiv/task-ini.lua @@ -113,7 +113,7 @@ appendaction("math", "normalizers", "noads.handlers.italics", appendaction("math", "normalizers", "noads.handlers.kernpairs", nil, "nonut", "disabled" ) appendaction("math", "normalizers", "noads.handlers.classes", nil, "nonut", "disabled" ) -appendaction("math", "builders", "builders.kernel.mlist_to_hlist", nil, "node", "enabled" ) -- mandate +appendaction("math", "builders", "builders.kernel.mlist_to_hlist", nil, "nut", "enabled" ) -- mandate appendaction("math", "builders", "typesetters.directions.processmath", nil, "nut", "disabled" ) appendaction("math", "builders", "noads.handlers.makeup", nil, "nonut", "disabled" ) appendaction("math", "builders", "noads.handlers.align", nil, "nonut", "enabled" ) diff --git a/tex/context/base/mkiv/trac-inf.lua b/tex/context/base/mkiv/trac-inf.lua index 2c1dbbfe7..7a5c35fd5 100644 --- a/tex/context/base/mkiv/trac-inf.lua +++ b/tex/context/base/mkiv/trac-inf.lua @@ -265,11 +265,13 @@ function statistics.timed(action,all) stoptiming("run") local runtime = tonumber(elapsedtime("run")) if all then - local alltime = lua.getruntime and lua.getruntime() or elapsedtime(statistics) - report("total runtime: %0.3f seconds of %0.3f seconds",runtime,alltime) - else - report("total runtime: %0.3f seconds",runtime) + local alltime = tonumber(lua.getruntime and lua.getruntime() or elapsedtime(statistics)) + if alltime and alltime > 0 then + report("total runtime: %0.3f seconds of %0.3f seconds",runtime,alltime) + return + end end + report("total runtime: %0.3f seconds",runtime) end -- goodie diff --git a/tex/context/base/mkiv/typo-itc.lua b/tex/context/base/mkiv/typo-itc.lua index 6cd3caf88..2683eecc3 100644 --- a/tex/context/base/mkiv/typo-itc.lua +++ b/tex/context/base/mkiv/typo-itc.lua @@ -124,14 +124,22 @@ local function okay(data,current,font,prevchar,previtalic,char,what) return false end if threshold then - local ht = getheight(current) - local ex = exheights[font] - local th = threshold * ex - if ht <= th then - if trace_italics then - report_italics("ignoring correction between %s italic %C and regular %C, height %p less than threshold %p",prevchar,what,char,ht,th) + -- if getid(current) == glyph_code then + while current and getid(current) ~= glyph_code do + current = getprev(current) + end + if current then + local ht = getheight(current) + local ex = exheights[font] + local th = threshold * ex + if ht <= th then + if trace_italics then + report_italics("ignoring correction between %s italic %C and regular %C, height %p less than threshold %p",prevchar,what,char,ht,th) + end + return false end - return false + else + -- maybe backtrack to glyph end end if trace_italics then diff --git a/tex/context/base/mkiv/util-jsn.lua b/tex/context/base/mkiv/util-jsn.lua index e5f83e06c..acbf16090 100644 --- a/tex/context/base/mkiv/util-jsn.lua +++ b/tex/context/base/mkiv/util-jsn.lua @@ -14,10 +14,12 @@ if not modules then modules = { } end modules ['util-jsn'] = { -- -- Reminder for me: check usage in framework and extend when needed. Also document -- it in the cld lib documentation. +-- +-- Upgraded for handling the somewhat more fax server templates. local P, V, R, S, C, Cc, Cs, Ct, Cf, Cg = lpeg.P, lpeg.V, lpeg.R, lpeg.S, lpeg.C, lpeg.Cc, lpeg.Cs, lpeg.Ct, lpeg.Cf, lpeg.Cg local lpegmatch = lpeg.match -local format = string.format +local format, gsub = string.format, string.gsub local utfchar = utf.char local concat = table.concat @@ -26,9 +28,6 @@ local tonumber, tostring, rawset, type, next = tonumber, tostring, rawset, type, local json = utilities.json or { } utilities.json = json --- moduledata = moduledata or { } --- moduledata.json = json - -- \\ \/ \b \f \n \r \t \uHHHH local lbrace = P("{") @@ -43,16 +42,19 @@ local whitespace = lpeg.patterns.whitespace local optionalws = whitespace^0 local escapes = { - -- ["\\"] = "\\", -- lua will escape these - -- ["/"] = "/", -- no need to escape this one - ["b"] = "\010", - ["f"] = "\014", - ["n"] = "\n", - ["r"] = "\r", - ["t"] = "\t", + ["b"] = "\010", + ["f"] = "\014", + ["n"] = "\n", + ["r"] = "\r", + ["t"] = "\t", } -local escape_un = C(P("\\u") / "0x" * S("09","AF","af")) / function(s) return utfchar(tonumber(s)) end +-- todo: also handle larger utf16 + +local escape_un = P("\\u")/"" * (C(R("09","AF","af")^-4) / function(s) + return utfchar(tonumber(s,16)) +end) + local escape_bs = P([[\]]) / "" * (P(1) / escapes) -- if not found then P(1) is returned i.e. the to be escaped char local jstring = dquote * Cs((escape_un + escape_bs + (1-dquote))^0) * dquote @@ -85,7 +87,9 @@ function json.tolua(str) return lpegmatch(jsonconverter,str) end -local function tojson(value,t) -- we could optimize #t +local escaper + +local function tojson(value,t,n) -- we could optimize #t local kind = type(value) if kind == "table" then local done = false @@ -93,60 +97,75 @@ local function tojson(value,t) -- we could optimize #t if size == 0 then for k, v in next, value do if done then - t[#t+1] = "," + n = n + 1 ; t[n] = "," else - t[#t+1] = "{" + n = n + 1 ; t[n] = "{" done = true end - t[#t+1] = format("%q:",k) - tojson(v,t) + n = n + 1 ; t[n] = format("%q:",k) + t, n = tojson(v,t,n) end if done then - t[#t+1] = "}" + n = n + 1 ; t[n] = "}" else - t[#t+1] = "{}" + n = n + 1 ; t[n] = "{}" end elseif size == 1 then -- we can optimize for non tables - t[#t+1] = "[" - tojson(value[1],t) - t[#t+1] = "]" + n = n + 1 ; t[n] = "[" + t, n = tojson(value[1],t,n) + n = n + 1 ; t[n] = "]" else for i=1,size do if done then - t[#t+1] = "," + n = n + 1 ; t[n] = "," else - t[#t+1] = "[" + n = n + 1 ; t[n] = "[" done = true end - tojson(value[i],t) + t, n = tojson(value[i],t,n) end - t[#t+1] = "]" + n = n + 1 ; t[n] = "]" end elseif kind == "string" then - t[#t+1] = format("%q",value) + n = n + 1 ; t[n] = '"' + n = n + 1 ; t[n] = lpegmatch(escaper,value) or value + n = n + 1 ; t[n] = '"' elseif kind == "number" then - t[#t+1] = value + n = n + 1 ; t[n] = value elseif kind == "boolean" then - t[#t+1] = tostring(value) + n = n + 1 ; t[n] = tostring(value) end - return t + return t, n end function json.tostring(value) -- todo optimize for non table local kind = type(value) if kind == "table" then - return concat(tojson(value,{}),"") + if not escaper then + local escapes = { + ["\\"] = "\\u005C", + ["\""] = "\\u0022", + } + for i=0,0x20 do + escapes[utfchar(i)] = format("\\u%04X",i) + end + escaper = Cs( ( + (R('\0\x20') + S('\"\\')) / escapes + + P(1) + )^1 ) + + end + return concat((tojson(value,{},0))) elseif kind == "string" or kind == "number" then - return value + return lpegmatch(escaper,value) or value else return tostring(value) end end --- local tmp = [[ { "a" : true, "b" : [ 123 , 456E-10, { "a" : true, "b" : [ 123 , 456 ] } ] } ]] - +-- local tmp = [[ { "t" : "foobar", "a" : true, "b" : [ 123 , 456E-10, { "a" : true, "b" : [ 123 , 456 ] } ] } ]] -- tmp = json.tolua(tmp) -- inspect(tmp) -- tmp = json.tostring(tmp) @@ -155,7 +174,6 @@ end -- inspect(tmp) -- tmp = json.tostring(tmp) -- inspect(tmp) - -- inspect(json.tostring(true)) function json.load(filename) @@ -165,4 +183,11 @@ function json.load(filename) end end +-- local s = [[\foo"bar"]] +-- local j = json.tostring { s = s } +-- local l = json.tolua(j) +-- inspect(j) +-- inspect(l) +-- print(s==l.s) + return json diff --git a/tex/context/base/mkiv/util-str.lua b/tex/context/base/mkiv/util-str.lua index 508d32d71..410a4a547 100644 --- a/tex/context/base/mkiv/util-str.lua +++ b/tex/context/base/mkiv/util-str.lua @@ -22,25 +22,12 @@ local utfchar, utfbyte, utflen = utf.char, utf.byte, utf.len ----- loadstripped = utilities.lua.loadstripped ----- setmetatableindex = table.setmetatableindex -local loadstripped = nil -local oldfashioned = LUAVERSION < 5.2 - -if oldfashioned then - - loadstripped = function(str,shortcuts) - return load(str) - end - -else - - loadstripped = function(str,shortcuts) - if shortcuts then - return load(dump(load(str),true),nil,nil,shortcuts) - else - return load(dump(load(str),true)) - end +local loadstripped = function(str,shortcuts) + if shortcuts then + return load(dump(load(str),true),nil,nil,shortcuts) + else + return load(dump(load(str),true)) end - end -- todo: make a special namespace for the formatter @@ -598,66 +585,34 @@ local template = [[ return function(%s) return %s end ]] -local preamble, environment = "", { } - -if oldfashioned then - - preamble = [[ -local lpeg=lpeg -local type=type -local tostring=tostring -local tonumber=tonumber -local format=string.format -local concat=table.concat -local signed=number.signed -local points=number.points -local basepoints= number.basepoints -local utfchar=utf.char -local utfbyte=utf.byte -local lpegmatch=lpeg.match -local nspaces=string.nspaces -local utfpadding=string.utfpadding -local tracedchar=string.tracedchar -local autosingle=string.autosingle -local autodouble=string.autodouble -local sequenced=table.sequenced -local formattednumber=number.formatted -local sparseexponent=number.sparseexponent -local formattedfloat=number.formattedfloat -local stripzero=lpeg.patterns.stripzero -local stripzeros=lpeg.patterns.stripzeros - ]] - -else - - environment = { - global = global or _G, - lpeg = lpeg, - type = type, - tostring = tostring, - tonumber = tonumber, - format = string.format, - concat = table.concat, - signed = number.signed, - points = number.points, - basepoints = number.basepoints, - utfchar = utf.char, - utfbyte = utf.byte, - lpegmatch = lpeg.match, - nspaces = string.nspaces, - utfpadding = string.utfpadding, - tracedchar = string.tracedchar, - autosingle = string.autosingle, - autodouble = string.autodouble, - sequenced = table.sequenced, - formattednumber = number.formatted, - sparseexponent = number.sparseexponent, - formattedfloat = number.formattedfloat, - stripzero = lpeg.patterns.stripzero, - stripzeros = lpeg.patterns.stripzeros, - } - -end +local preamble = "" + +local environment = { + global = global or _G, + lpeg = lpeg, + type = type, + tostring = tostring, + tonumber = tonumber, + format = string.format, + concat = table.concat, + signed = number.signed, + points = number.points, + basepoints = number.basepoints, + utfchar = utf.char, + utfbyte = utf.byte, + lpegmatch = lpeg.match, + nspaces = string.nspaces, + utfpadding = string.utfpadding, + tracedchar = string.tracedchar, + autosingle = string.autosingle, + autodouble = string.autodouble, + sequenced = table.sequenced, + formattednumber = number.formatted, + sparseexponent = number.sparseexponent, + formattedfloat = number.formattedfloat, + stripzero = lpeg.patterns.stripzero, + stripzeros = lpeg.patterns.stripzeros, +} -- -- -- @@ -1036,44 +991,86 @@ end -- strip = true -- end +-- add(formatters,"texexp", [[texexp(...)]], "local texexp = metapost.texexp") -- +-- add(formatters,"foo:bar",[[foo(...)]], { foo = function(...) print(...) return "!" end }) +-- print(string.formatters["foo %3!foo:bar! bar"](1,2,3)) + local format_rest = function(s) return format("%q",s) -- catches " and \n and such end +-- local format_extension = function(extensions,f,name) +-- local extension = extensions[name] or "tostring(%s)" +-- local f = tonumber(f) or 1 +-- local w = find(extension,"%.%.%.") +-- if f == 0 then +-- if w then +-- extension = gsub(extension,"%.%.%.","") +-- end +-- return extension +-- elseif f == 1 then +-- if w then +-- extension = gsub(extension,"%.%.%.","%%s") +-- end +-- n = n + 1 +-- local a = "a" .. n +-- return format(extension,a,a) -- maybe more times? +-- elseif f < 0 then +-- local a = "a" .. (n + f + 1) +-- return format(extension,a,a) +-- else +-- if w then +-- extension = gsub(extension,"%.%.%.",rep("%%s,",f-1).."%%s") +-- end +-- -- we could fill an array and then n = n + 1 unpack(t,n,n+f) but as we +-- -- cache we don't save much and there are hardly any extensions anyway +-- local t = { } +-- for i=1,f do +-- n = n + 1 +-- -- t[#t+1] = "a" .. n +-- t[i] = "a" .. n +-- end +-- return format(extension,unpack(t)) +-- end +-- end + local format_extension = function(extensions,f,name) local extension = extensions[name] or "tostring(%s)" local f = tonumber(f) or 1 local w = find(extension,"%.%.%.") - if f == 0 then - if w then + if w then + -- we have a wildcard + if f == 0 then extension = gsub(extension,"%.%.%.","") - end - return extension - elseif f == 1 then - if w then + return extension + elseif f == 1 then extension = gsub(extension,"%.%.%.","%%s") - end - n = n + 1 - local a = "a" .. n - return format(extension,a,a) -- maybe more times? - elseif f < 0 then - local a = "a" .. (n + f + 1) - return format(extension,a,a) - else - if w then + n = n + 1 + local a = "a" .. n + return format(extension,a,a) -- maybe more times? + elseif f < 0 then + local a = "a" .. (n + f + 1) + return format(extension,a,a) + else extension = gsub(extension,"%.%.%.",rep("%%s,",f-1).."%%s") + -- we could fill an array and then n = n + 1 unpack(t,n,n+f) but as we + -- cache we don't save much and there are hardly any extensions anyway + local t = { } + for i=1,f do + n = n + 1 + -- t[#t+1] = "a" .. n + t[i] = "a" .. n + end + return format(extension,unpack(t)) end - -- we could fill an array and then n = n + 1 unpack(t,n,n+f) but as we - -- cache we don't save much and there are hardly any extensions anyway - local t = { } - for i=1,f do + else + extension = gsub(extension,"%%s",function() n = n + 1 - -- t[#t+1] = "a" .. n - t[i] = "a" .. n - end - return format(extension,unpack(t)) + return "a" .. n + end) + return extension end end @@ -1273,36 +1270,22 @@ strings.formatters = { } -- _connector_ is an experiment -if oldfashioned then - - function strings.formatters.new(noconcat) - local t = { _type_ = "formatter", _connector_ = noconcat and "," or "..", _extensions_ = { }, _preamble_ = preamble, _environment_ = { } } - setmetatable(t, { __index = make, __call = use }) - return t - end - -else - - function strings.formatters.new(noconcat) - local e = { } -- better make a copy as we can overload - for k, v in next, environment do - e[k] = v - end - local t = { _type_ = "formatter", _connector_ = noconcat and "," or "..", _extensions_ = { }, _preamble_ = "", _environment_ = e } - setmetatable(t, { __index = make, __call = use }) - return t +function strings.formatters.new(noconcat) + local e = { } -- better make a copy as we can overload + for k, v in next, environment do + e[k] = v end - + local t = { + _type_ = "formatter", + _connector_ = noconcat and "," or "..", + _extensions_ = { }, + _preamble_ = "", + _environment_ = e, + } + setmetatable(t, { __index = make, __call = use }) + return t end --- function strings.formatters.new() --- local t = { _extensions_ = { }, _preamble_ = "", _type_ = "formatter", _n_ = 0 } --- local m = { _t_ = t } --- setmetatable(t, { __index = m, __call = use }) --- setmetatable(m, { __index = make }) --- return t --- end - local formatters = strings.formatters.new() -- the default instance string.formatters = formatters -- in the main string namespace @@ -1333,19 +1316,9 @@ patterns.luaquoted = Cs(Cc('"') * ((1-S('"\n'))^1 + P('"')/'\\"' + P('\n')/'\\n" -- escaping by lpeg is faster for strings without quotes, slower on a string with quotes, but -- faster again when other q-escapables are found (the ones we don't need to escape) -if oldfashioned then - - add(formatters,"xml",[[lpegmatch(xmlescape,%s)]],"local xmlescape = lpeg.patterns.xmlescape") - add(formatters,"tex",[[lpegmatch(texescape,%s)]],"local texescape = lpeg.patterns.texescape") - add(formatters,"lua",[[lpegmatch(luaescape,%s)]],"local luaescape = lpeg.patterns.luaescape") - -else - - add(formatters,"xml",[[lpegmatch(xmlescape,%s)]],{ xmlescape = lpeg.patterns.xmlescape }) - add(formatters,"tex",[[lpegmatch(texescape,%s)]],{ texescape = lpeg.patterns.texescape }) - add(formatters,"lua",[[lpegmatch(luaescape,%s)]],{ luaescape = lpeg.patterns.luaescape }) - -end +add(formatters,"xml",[[lpegmatch(xmlescape,%s)]],{ xmlescape = lpeg.patterns.xmlescape }) +add(formatters,"tex",[[lpegmatch(texescape,%s)]],{ texescape = lpeg.patterns.texescape }) +add(formatters,"lua",[[lpegmatch(luaescape,%s)]],{ luaescape = lpeg.patterns.luaescape }) -- -- yes or no: -- diff --git a/tex/context/interface/mkiv/i-context.pdf b/tex/context/interface/mkiv/i-context.pdf index cb329ec26..6f7618b57 100644 Binary files a/tex/context/interface/mkiv/i-context.pdf and b/tex/context/interface/mkiv/i-context.pdf differ diff --git a/tex/context/interface/mkiv/i-readme.pdf b/tex/context/interface/mkiv/i-readme.pdf index 46c87adc2..859484617 100644 Binary files a/tex/context/interface/mkiv/i-readme.pdf and b/tex/context/interface/mkiv/i-readme.pdf differ diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index 127074771..02f50d6e7 100644 --- a/tex/generic/context/luatex/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : c:/data/develop/context/sources/luatex-fonts-merged.lua -- parent file : c:/data/develop/context/sources/luatex-fonts.lua --- merge date : 01/19/19 12:06:39 +-- merge date : 01/25/19 20:06:50 do -- begin closure to overcome local limits and interference @@ -20,7 +20,6 @@ if LUAVERSION<5.2 and jit then MINORVERSION=2 LUAVERSION=5.2 end -_LUAVERSION=LUAVERSION if not lpeg then lpeg=require("lpeg") end @@ -3050,19 +3049,11 @@ local unpack,concat=table.unpack,table.concat local P,V,C,S,R,Ct,Cs,Cp,Carg,Cc=lpeg.P,lpeg.V,lpeg.C,lpeg.S,lpeg.R,lpeg.Ct,lpeg.Cs,lpeg.Cp,lpeg.Carg,lpeg.Cc local patterns,lpegmatch=lpeg.patterns,lpeg.match local utfchar,utfbyte,utflen=utf.char,utf.byte,utf.len -local loadstripped=nil -local oldfashioned=LUAVERSION<5.2 -if oldfashioned then - loadstripped=function(str,shortcuts) - return load(str) - end -else - loadstripped=function(str,shortcuts) - if shortcuts then - return load(dump(load(str),true),nil,nil,shortcuts) - else - return load(dump(load(str),true)) - end +local loadstripped=function(str,shortcuts) + if shortcuts then + return load(dump(load(str),true),nil,nil,shortcuts) + else + return load(dump(load(str),true)) end end if not number then number={} end @@ -3369,61 +3360,33 @@ local template=[[ %s return function(%s) return %s end ]] -local preamble,environment="",{} -if oldfashioned then - preamble=[[ -local lpeg=lpeg -local type=type -local tostring=tostring -local tonumber=tonumber -local format=string.format -local concat=table.concat -local signed=number.signed -local points=number.points -local basepoints= number.basepoints -local utfchar=utf.char -local utfbyte=utf.byte -local lpegmatch=lpeg.match -local nspaces=string.nspaces -local utfpadding=string.utfpadding -local tracedchar=string.tracedchar -local autosingle=string.autosingle -local autodouble=string.autodouble -local sequenced=table.sequenced -local formattednumber=number.formatted -local sparseexponent=number.sparseexponent -local formattedfloat=number.formattedfloat -local stripzero=lpeg.patterns.stripzero -local stripzeros=lpeg.patterns.stripzeros - ]] -else - environment={ - global=global or _G, - lpeg=lpeg, - type=type, - tostring=tostring, - tonumber=tonumber, - format=string.format, - concat=table.concat, - signed=number.signed, - points=number.points, - basepoints=number.basepoints, - utfchar=utf.char, - utfbyte=utf.byte, - lpegmatch=lpeg.match, - nspaces=string.nspaces, - utfpadding=string.utfpadding, - tracedchar=string.tracedchar, - autosingle=string.autosingle, - autodouble=string.autodouble, - sequenced=table.sequenced, - formattednumber=number.formatted, - sparseexponent=number.sparseexponent, - formattedfloat=number.formattedfloat, - stripzero=lpeg.patterns.stripzero, - stripzeros=lpeg.patterns.stripzeros, - } -end +local preamble="" +local environment={ + global=global or _G, + lpeg=lpeg, + type=type, + tostring=tostring, + tonumber=tonumber, + format=string.format, + concat=table.concat, + signed=number.signed, + points=number.points, + basepoints=number.basepoints, + utfchar=utf.char, + utfbyte=utf.byte, + lpegmatch=lpeg.match, + nspaces=string.nspaces, + utfpadding=string.utfpadding, + tracedchar=string.tracedchar, + autosingle=string.autosingle, + autodouble=string.autodouble, + sequenced=table.sequenced, + formattednumber=number.formatted, + sparseexponent=number.sparseexponent, + formattedfloat=number.formattedfloat, + stripzero=lpeg.patterns.stripzero, + stripzeros=lpeg.patterns.stripzeros, +} local arguments={ "a1" } setmetatable(arguments,{ __index=function(t,k) local v=t[k-1]..",a"..k @@ -3698,31 +3661,33 @@ local format_extension=function(extensions,f,name) local extension=extensions[name] or "tostring(%s)" local f=tonumber(f) or 1 local w=find(extension,"%.%.%.") - if f==0 then - if w then + if w then + if f==0 then extension=gsub(extension,"%.%.%.","") - end - return extension - elseif f==1 then - if w then + return extension + elseif f==1 then extension=gsub(extension,"%.%.%.","%%s") - end - n=n+1 - local a="a"..n - return format(extension,a,a) - elseif f<0 then - local a="a"..(n+f+1) - return format(extension,a,a) - else - if w then + n=n+1 + local a="a"..n + return format(extension,a,a) + elseif f<0 then + local a="a"..(n+f+1) + return format(extension,a,a) + else extension=gsub(extension,"%.%.%.",rep("%%s,",f-1).."%%s") + local t={} + for i=1,f do + n=n+1 + t[i]="a"..n + end + return format(extension,unpack(t)) end - local t={} - for i=1,f do + else + extension=gsub(extension,"%%s",function() n=n+1 - t[i]="a"..n - end - return format(extension,unpack(t)) + return "a"..n + end) + return extension end end local builder=Cs { "start", @@ -3827,22 +3792,20 @@ local function use(t,fmt,...) return t[fmt](...) end strings.formatters={} -if oldfashioned then - function strings.formatters.new(noconcat) - local t={ _type_="formatter",_connector_=noconcat and "," or "..",_extensions_={},_preamble_=preamble,_environment_={} } - setmetatable(t,{ __index=make,__call=use }) - return t - end -else - function strings.formatters.new(noconcat) - local e={} - for k,v in next,environment do - e[k]=v - end - local t={ _type_="formatter",_connector_=noconcat and "," or "..",_extensions_={},_preamble_="",_environment_=e } - setmetatable(t,{ __index=make,__call=use }) - return t +function strings.formatters.new(noconcat) + local e={} + for k,v in next,environment do + e[k]=v end + local t={ + _type_="formatter", + _connector_=noconcat and "," or "..", + _extensions_={}, + _preamble_="", + _environment_=e, + } + setmetatable(t,{ __index=make,__call=use }) + return t end local formatters=strings.formatters.new() string.formatters=formatters @@ -3864,15 +3827,9 @@ patterns.xmlescape=Cs((P("<")/"<"+P(">")/">"+P("&")/"&"+P('"')/"" patterns.texescape=Cs((C(S("#$%\\{}"))/"\\%1"+anything)^0) patterns.luaescape=Cs(((1-S('"\n'))^1+P('"')/'\\"'+P('\n')/'\\n"')^0) patterns.luaquoted=Cs(Cc('"')*((1-S('"\n'))^1+P('"')/'\\"'+P('\n')/'\\n"')^0*Cc('"')) -if oldfashioned then - add(formatters,"xml",[[lpegmatch(xmlescape,%s)]],"local xmlescape = lpeg.patterns.xmlescape") - add(formatters,"tex",[[lpegmatch(texescape,%s)]],"local texescape = lpeg.patterns.texescape") - add(formatters,"lua",[[lpegmatch(luaescape,%s)]],"local luaescape = lpeg.patterns.luaescape") -else - add(formatters,"xml",[[lpegmatch(xmlescape,%s)]],{ xmlescape=lpeg.patterns.xmlescape }) - add(formatters,"tex",[[lpegmatch(texescape,%s)]],{ texescape=lpeg.patterns.texescape }) - add(formatters,"lua",[[lpegmatch(luaescape,%s)]],{ luaescape=lpeg.patterns.luaescape }) -end +add(formatters,"xml",[[lpegmatch(xmlescape,%s)]],{ xmlescape=lpeg.patterns.xmlescape }) +add(formatters,"tex",[[lpegmatch(texescape,%s)]],{ texescape=lpeg.patterns.texescape }) +add(formatters,"lua",[[lpegmatch(luaescape,%s)]],{ luaescape=lpeg.patterns.luaescape }) local dquote=patterns.dquote local equote=patterns.escaped+dquote/'\\"'+1 local cquote=Cc('"') -- cgit v1.2.3