From 397508ee8dca010aec5a9c6951b68434e5657f14 Mon Sep 17 00:00:00 2001
From: Context Git Mirror Bot .. a paragraph of text
foo | +bar | + |
first
+second
+third
+fourth
+We've now arrived at an interesting part: accessing the tree using a subset @@ -659,6 +672,7 @@ local template_f_n = [[ -- +local register_last_match = { kind = "axis", axis = "last-match" } -- , apply = apply_axis["self"] } local register_self = { kind = "axis", axis = "self" } -- , apply = apply_axis["self"] } local register_parent = { kind = "axis", axis = "parent" } -- , apply = apply_axis["parent"] } local register_descendant = { kind = "axis", axis = "descendant" } -- , apply = apply_axis["descendant"] } @@ -759,21 +773,41 @@ local pathparser = Ct { "patterns", -- can be made a bit faster by moving some p protocol = Cg(V("letters"),"protocol") * P("://") + Cg(Cc(nil),"protocol"), -- the / is needed for // as descendant or self is somewhat special + -- -- step = (V("shortcuts") + V("axis") * spaces * V("nodes")^0 + V("error")) * spaces * V("expressions")^0 * spaces * V("finalizer")^0, step = ((V("shortcuts") + P("/") + V("axis")) * spaces * V("nodes")^0 + V("error")) * spaces * V("expressions")^0 * spaces * V("finalizer")^0, - axis = V("descendant") + V("child") + V("parent") + V("self") + V("root") + V("ancestor") + - V("descendant_or_self") + V("following_sibling") + V("following") + - V("reverse_sibling") + V("preceding_sibling") + V("preceding") + V("ancestor_or_self") + - #(1-P(-1)) * Cc(register_auto_child), - - special = special_1 + special_2 + special_3, + axis = V("last_match") + + V("descendant") + + V("child") + + V("parent") + + V("self") + + V("root") + + V("ancestor") + + V("descendant_or_self") + + V("following_sibling") + + V("following") + + V("reverse_sibling") + + V("preceding_sibling") + + V("preceding") + + V("ancestor_or_self") + + #(1-P(-1)) * Cc(register_auto_child), + + special = special_1 + + special_2 + + special_3, initial = (P("/") * spaces * Cc(register_initial_child))^-1, error = (P(1)^1) / register_error, - shortcuts_a = V("s_descendant_or_self") + V("s_descendant") + V("s_child") + V("s_parent") + V("s_self") + V("s_root") + V("s_ancestor"), + shortcuts_a = V("s_descendant_or_self") + + V("s_descendant") + + V("s_child") + + V("s_parent") + + V("s_self") + + V("s_root") + + V("s_ancestor"), shortcuts = V("shortcuts_a") * (spaces * "/" * spaces * V("shortcuts_a"))^0, @@ -785,6 +819,8 @@ local pathparser = Ct { "patterns", -- can be made a bit faster by moving some p s_root = P("^^") * Cc(register_root ), s_ancestor = P("^") * Cc(register_ancestor ), + -- we can speed this up when needed but we cache anyway so ... + descendant = P("descendant::") * Cc(register_descendant ), child = P("child::") * Cc(register_child ), parent = P("parent::") * Cc(register_parent ), @@ -800,6 +836,7 @@ local pathparser = Ct { "patterns", -- can be made a bit faster by moving some p preceding = P('preceding::') * Cc(register_preceding ), preceding_sibling = P('preceding-sibling::') * Cc(register_preceding_sibling ), reverse_sibling = P('reverse-sibling::') * Cc(register_reverse_sibling ), + last_match = P('last-match::') * Cc(register_last_match ), nodes = (V("nodefunction") * spaces * P("(") * V("nodeset") * P(")") + V("nodetest") * V("nodeset")) / register_nodes, @@ -953,146 +990,194 @@ xml.lpath = lpath -- can be cases that a finalizer returns (or does) something in case -- there is no match; an example of this is count() -local profiled = { } xml.profiled = profiled +do -local function profiled_apply(list,parsed,nofparsed,order) - local p = profiled[parsed.pattern] - if p then - p.tested = p.tested + 1 - else - p = { tested = 1, matched = 0, finalized = 0 } - profiled[parsed.pattern] = p + local profiled = { } + xml.profiled = profiled + local lastmatch = nil -- we remember the last one .. drawback: no collection till new collect + local keepmatch = nil -- we remember the last one .. drawback: no collection till new collect + + if directives then + directives.register("xml.path.keeplastmatch",function(v) + keepmatch = v + lastmatch = nil + end) end - local collected = list - for i=1,nofparsed do - local pi = parsed[i] - local kind = pi.kind - if kind == "axis" then - collected = apply_axis[pi.axis](collected) - elseif kind == "nodes" then - collected = apply_nodes(collected,pi.nodetest,pi.nodes) - elseif kind == "expression" then - collected = apply_expression(collected,pi.evaluator,order) - elseif kind == "finalizer" then - collected = pi.finalizer(collected) -- no check on # here - p.matched = p.matched + 1 - p.finalized = p.finalized + 1 - return collected + + apply_axis["last-match"] = function() + return lastmatch or { } + end + + local function profiled_apply(list,parsed,nofparsed,order) + local p = profiled[parsed.pattern] + if p then + p.tested = p.tested + 1 + else + p = { tested = 1, matched = 0, finalized = 0 } + profiled[parsed.pattern] = p end - if not collected or #collected == 0 then - local pn = i < nofparsed and parsed[nofparsed] - if pn and pn.kind == "finalizer" then - collected = pn.finalizer(collected) + local collected = list + for i=1,nofparsed do + local pi = parsed[i] + local kind = pi.kind + if kind == "axis" then + collected = apply_axis[pi.axis](collected) + elseif kind == "nodes" then + collected = apply_nodes(collected,pi.nodetest,pi.nodes) + elseif kind == "expression" then + collected = apply_expression(collected,pi.evaluator,order) + elseif kind == "finalizer" then + collected = pi.finalizer(collected) -- no check on # here + p.matched = p.matched + 1 p.finalized = p.finalized + 1 return collected end - return nil + if not collected or #collected == 0 then + local pn = i < nofparsed and parsed[nofparsed] + if pn and pn.kind == "finalizer" then + collected = pn.finalizer(collected) -- collected can be nil + p.finalized = p.finalized + 1 + return collected + end + return nil + end end + if collected then + p.matched = p.matched + 1 + end + return collected end - if collected then - p.matched = p.matched + 1 - end - return collected -end -local function traced_apply(list,parsed,nofparsed,order) - if trace_lparse then - lshow(parsed) - end - report_lpath("collecting: %s",parsed.pattern) - report_lpath("root tags : %s",tagstostring(list)) - report_lpath("order : %s",order or "unset") - local collected = list - for i=1,nofparsed do - local pi = parsed[i] - local kind = pi.kind - if kind == "axis" then - collected = apply_axis[pi.axis](collected) - report_lpath("% 10i : ax : %s",(collected and #collected) or 0,pi.axis) - elseif kind == "nodes" then - collected = apply_nodes(collected,pi.nodetest,pi.nodes) - report_lpath("% 10i : ns : %s",(collected and #collected) or 0,nodesettostring(pi.nodes,pi.nodetest)) - elseif kind == "expression" then - collected = apply_expression(collected,pi.evaluator,order) - report_lpath("% 10i : ex : %s -> %s",(collected and #collected) or 0,pi.expression,pi.converted) - elseif kind == "finalizer" then - collected = pi.finalizer(collected) - report_lpath("% 10i : fi : %s : %s(%s)",(type(collected) == "table" and #collected) or 0,parsed.protocol or xml.defaultprotocol,pi.name,pi.arguments or "") - return collected + local function traced_apply(list,parsed,nofparsed,order) + if trace_lparse then + lshow(parsed) end - if not collected or #collected == 0 then - local pn = i < nofparsed and parsed[nofparsed] - if pn and pn.kind == "finalizer" then - collected = pn.finalizer(collected) - report_lpath("% 10i : fi : %s : %s(%s)",(type(collected) == "table" and #collected) or 0,parsed.protocol or xml.defaultprotocol,pn.name,pn.arguments or "") + report_lpath("collecting: %s",parsed.pattern) + report_lpath("root tags : %s",tagstostring(list)) + report_lpath("order : %s",order or "unset") + local collected = list + for i=1,nofparsed do + local pi = parsed[i] + local kind = pi.kind + if kind == "axis" then + collected = apply_axis[pi.axis](collected) + report_lpath("% 10i : ax : %s",(collected and #collected) or 0,pi.axis) + elseif kind == "nodes" then + collected = apply_nodes(collected,pi.nodetest,pi.nodes) + report_lpath("% 10i : ns : %s",(collected and #collected) or 0,nodesettostring(pi.nodes,pi.nodetest)) + elseif kind == "expression" then + collected = apply_expression(collected,pi.evaluator,order) + report_lpath("% 10i : ex : %s -> %s",(collected and #collected) or 0,pi.expression,pi.converted) + elseif kind == "finalizer" then + collected = pi.finalizer(collected) + report_lpath("% 10i : fi : %s : %s(%s)",(type(collected) == "table" and #collected) or 0,parsed.protocol or xml.defaultprotocol,pi.name,pi.arguments or "") return collected end - return nil + if not collected or #collected == 0 then + local pn = i < nofparsed and parsed[nofparsed] + if pn and pn.kind == "finalizer" then + collected = pn.finalizer(collected) + report_lpath("% 10i : fi : %s : %s(%s)",(type(collected) == "table" and #collected) or 0,parsed.protocol or xml.defaultprotocol,pn.name,pn.arguments or "") + return collected + end + return nil + end end + return collected end - return collected -end -local function normal_apply(list,parsed,nofparsed,order) - local collected = list - for i=1,nofparsed do - local pi = parsed[i] - local kind = pi.kind - if kind == "axis" then - local axis = pi.axis - if axis ~= "self" then - collected = apply_axis[axis](collected) + local function normal_apply(list,parsed,nofparsed,order) + local collected = list + for i=1,nofparsed do + local pi = parsed[i] + local kind = pi.kind + if kind == "axis" then + local axis = pi.axis + if axis ~= "self" then + collected = apply_axis[axis](collected) + end + elseif kind == "nodes" then + collected = apply_nodes(collected,pi.nodetest,pi.nodes) + elseif kind == "expression" then + collected = apply_expression(collected,pi.evaluator,order) + elseif kind == "finalizer" then + return pi.finalizer(collected) end - elseif kind == "nodes" then - collected = apply_nodes(collected,pi.nodetest,pi.nodes) - elseif kind == "expression" then - collected = apply_expression(collected,pi.evaluator,order) - elseif kind == "finalizer" then - return pi.finalizer(collected) - end - if not collected or #collected == 0 then - local pf = i < nofparsed and parsed[nofparsed].finalizer - if pf then - return pf(collected) -- can be anything + if not collected or #collected == 0 then + local pf = i < nofparsed and parsed[nofparsed].finalizer + if pf then + return pf(collected) -- can be anything + end + return nil end - return nil end + return collected end - return collected -end -local function applylpath(list,pattern) - if not list then - return - end - local parsed = cache[pattern] - if parsed then - lpathcalls = lpathcalls + 1 - lpathcached = lpathcached + 1 - elseif type(pattern) == "table" then - lpathcalls = lpathcalls + 1 - parsed = pattern - else - parsed = lpath(pattern) or pattern - end - if not parsed then - return + local apply = normal_apply + + if trackers then + -- local function check() + -- if trace_lprofile or then + -- apply = profiled_apply + -- elseif trace_lpath then + -- apply = traced_apply + -- else + -- apply = normal_apply + -- end + -- end + -- trackers.register("xml.path", check) -- can be "xml.path,xml.parse,xml.profile + -- trackers.register("xml.parse", check) + -- trackers.register("xml.profile",check) + + trackers.register("xml.path,xml.parse,xml.profile",function() + if trace_lprofile then + apply = profiled_apply + elseif trace_lpath then + apply = traced_apply + else + apply = normal_apply + end + end) end - local nofparsed = #parsed - if nofparsed == 0 then - return -- something is wrong + + + function xml.applylpath(list,pattern) + if not list then + lastmatch = nil + return + end + local parsed = cache[pattern] + if parsed then + lpathcalls = lpathcalls + 1 + lpathcached = lpathcached + 1 + elseif type(pattern) == "table" then + lpathcalls = lpathcalls + 1 + parsed = pattern + else + parsed = lpath(pattern) or pattern + end + if not parsed then + lastmatch = nil + return + end + local nofparsed = #parsed + if nofparsed == 0 then + lastmatch = nil + return -- something is wrong + end + local collected = apply({ list },parsed,nofparsed,list.mi) + lastmatch = keepmatch and collected or nil + return collected end - if not trace_lpath then - return normal_apply ({ list },parsed,nofparsed,list.mi) - elseif trace_lprofile then - return profiled_apply({ list },parsed,nofparsed,list.mi) - else - return traced_apply ({ list },parsed,nofparsed,list.mi) + + function xml.lastmatch() + return lastmatch end -end -xml.applylpath = applylpath -- takes a table as first argment, which is what xml.filter will do +end +local applylpath = xml.applylpath --[[ldx--
This is the main filter function. It returns whatever is asked for.
--ldx]]-- diff --git a/tex/context/base/mkiv/lxml-tex.lua b/tex/context/base/mkiv/lxml-tex.lua index 09f1e10f9..0ec981d68 100644 --- a/tex/context/base/mkiv/lxml-tex.lua +++ b/tex/context/base/mkiv/lxml-tex.lua @@ -52,6 +52,9 @@ local xmlinclusion = xml.inclusion local xmlinclusions = xml.inclusions local xmlbadinclusions = xml.badinclusions local xmlcontent = xml.content +local xmllastmatch = xml.lastmatch + +directives.enable("xml.path.keeplastmatch") local variables = interfaces and interfaces.variables or { } @@ -1849,6 +1852,13 @@ function lxml.flush(id) end end +function lxml.lastmatch() + local collected = xmllastmatch() + if collected then + all(collected) + end +end + function lxml.snippet(id,i) local e = getid(id) if e then diff --git a/tex/context/base/mkiv/node-res.lua b/tex/context/base/mkiv/node-res.lua index 892cd62f2..eec7f0c07 100644 --- a/tex/context/base/mkiv/node-res.lua +++ b/tex/context/base/mkiv/node-res.lua @@ -369,36 +369,38 @@ if context and _cldo_ then local setfield_node = nodes.setfield local setfield_nut = nuts .setfield - function nodepool.lateluafunction(f) - local n = copy_node(latelua_node) - setfield_node(n,"string",f_cldo(register(f))) - return n - end - function nutpool.lateluafunction(f) - local n = copy_nut(latelua_nut) - setfield_nut(n,"string",f_cldo(register(f))) - return n - end - - -- when function in latelua: - -- function nodepool.lateluafunction(f) -- local n = copy_node(latelua_node) - -- setfield_node(n,"string",f) + -- setfield_node(n,"string",f_cldo(register(f))) -- return n -- end + -- function nutpool.lateluafunction(f) -- local n = copy_nut(latelua_nut) - -- setfield_nut(n,"string",f) + -- setfield_nut(n,"string",f_cldo(register(f))) -- return n -- end + -- when function in latelua: + + function nodepool.lateluafunction(f) + local n = copy_node(latelua_node) + setfield_node(n,"string",f) + return n + end + + function nutpool.lateluafunction(f) + local n = copy_nut(latelua_nut) + setfield_nut(n,"string",f) + return n + end + local latefunction = nodepool.lateluafunction local flushnode = context.flushnode - function context.lateluafunction(f) - flushnode(latefunction(f)) -- hm, quite some indirect calls - end + -- function context.lateluafunction(f) + -- flushnode(latefunction(f)) -- hm, quite some indirect calls + -- end -- when function in latelua: @@ -420,11 +422,11 @@ if context and _cldo_ then -- when function in latelua: - -- function context.lateluafunction(f) - -- local n = copy_node(latelua_node) - -- setfield_node(n,"string",f) - -- contextsprint(ctxcatcodes,"\\cldl",storenode(n)," ") - -- end + function context.lateluafunction(f) + local n = copy_node(latelua_node) + setfield_node(n,"string",f) + contextsprint(ctxcatcodes,"\\cldl",storenode(n)," ") + end end diff --git a/tex/context/base/mkiv/publ-imp-apa.mkvi b/tex/context/base/mkiv/publ-imp-apa.mkvi index 1411042c9..b9d265105 100644 --- a/tex/context/base/mkiv/publ-imp-apa.mkvi +++ b/tex/context/base/mkiv/publ-imp-apa.mkvi @@ -872,7 +872,6 @@ \btxflush{withauthor} \btxrightparenthesis } - \btxperiod } \stoptexdefinition diff --git a/tex/context/base/mkiv/status-files.pdf b/tex/context/base/mkiv/status-files.pdf index 392bf9a1f..35df55af7 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 f7b9aa479..8d31b4caa 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/strc-flt.mkvi b/tex/context/base/mkiv/strc-flt.mkvi index 334d98a93..fb621c997 100644 --- a/tex/context/base/mkiv/strc-flt.mkvi +++ b/tex/context/base/mkiv/strc-flt.mkvi @@ -186,16 +186,36 @@ \unexpanded\def\definefloat {\dotripleempty\strc_floats_define} -\def\strc_floats_define[#1][#2][#3]% #1=naam #2=meervoud #3=parent +\def\strc_floats_define[#1][#2][#3]% name+plural+parent | name+parent+settings {\ifthirdargument - \strc_floats_define_cloned[#1][#2][#3]% + \doifassignmentelse{#3} + {\strc_floats_define_b[#1][#2][#3]}% + {\strc_floats_define_a[#1][#2][#3]}% \else\ifsecondargument - \strc_floats_define_normal[#1][#2]% + \doifelsecommandhandler\??float{#2}% + {\strc_floats_define_a[#1][#1][#2]}% + {\strc_floats_define_c[#1][#2]}% \else - \strc_floats_define_normal[#1][#1]% + \strc_floats_define_c[#1][#1]% \fi\fi} -\def\strc_floats_define_normal[#1][#2]% +\def\strc_floats_define_a[#1][#2][#3]% name names parent + {\definefloatcaption[#1][#3]% + \definecounter[#1][#3]% + \definelist[#1][#3]% + \copylabeltext[#1=#3]% + \strc_floats_define_saved[#1][#3]% + \strc_floats_define_commands{#1}{#2}} + +\def\strc_floats_define_b[#1][#2][#3]% name parent settings + {\definefloatcaption[#1][#2]% + \definecounter[#1][#2]% + \definelist[#1][#2]% + \copylabeltext[#1=#2]% + \strc_floats_define_saved[#1][#2][#3]% + \strc_floats_define_commands{#1}{#1}} + +\def\strc_floats_define_c[#1][#2]% name names {\registerfloatcaptioncounter{#1}% \definefloatcaption[#1]% \definecounter[#1]% @@ -205,15 +225,6 @@ \strc_floats_define_saved[#1]% \strc_floats_define_commands{#1}{#2}} -\def\strc_floats_define_cloned[#1][#2][#3]% - {\definefloatcaption[#1][#3]% - \definecounter[#1][#3]% - \definelist[#1][#3]% - \copylabeltext[#1=#3]% - %\presetheadtext[#2=\Word{#2}]% - \strc_floats_define_saved[#1][#3]% - \strc_floats_define_commands{#1}{#2}} - \def\strc_floats_define_commands#1#2% {\setuvalue {\e!place\e!listof#2}{\dodoubleempty\strc_lists_place[#1]}% call will change \setuvalue {\e!complete\e!listof#2}{\dotripleempty\strc_lists_complete_indeed[#1][#2]}% call will change diff --git a/tex/context/base/mkiv/syst-ini.mkiv b/tex/context/base/mkiv/syst-ini.mkiv index e165ee8a3..37ffc5768 100644 --- a/tex/context/base/mkiv/syst-ini.mkiv +++ b/tex/context/base/mkiv/syst-ini.mkiv @@ -1010,15 +1010,12 @@ \edef\pdfimagehicolor {\pdfvariable imagehicolor} \pdfimagehicolor \plusone \edef\pdfimageaddfilename {\pdfvariable imageaddfilename} \pdfimageaddfilename \plusone \edef\pdfpkresolution {\pdfvariable pkresolution} \pdfpkresolution 1200 -\edef\pdfpkfixeddpi {\pdfvariable pkfixeddpi} \pdfpkfixeddpi 1 \edef\pdfinclusioncopyfonts {\pdfvariable inclusioncopyfonts} \pdfinclusioncopyfonts \plusone \edef\pdfinclusionerrorlevel {\pdfvariable inclusionerrorlevel} \pdfinclusionerrorlevel \zerocount -\edef\pdfignoreunknownimages {\pdfvariable ignoreunknownimages} \pdfignoreunknownimages \zerocount \edef\pdfgentounicode {\pdfvariable gentounicode} \pdfgentounicode \plusone \edef\pdfpagebox {\pdfvariable pagebox} \pdfpagebox \zerocount \edef\pdfminorversion {\pdfvariable minorversion} \pdfminorversion \plusseven \edef\pdfuniqueresname {\pdfvariable uniqueresname} \pdfuniqueresname \zerocount - \edef\pdfhorigin {\pdfvariable horigin} \pdfhorigin 1in \edef\pdfvorigin {\pdfvariable vorigin} \pdfvorigin \pdfhorigin \edef\pdflinkmargin {\pdfvariable linkmargin} \pdflinkmargin \zeropoint @@ -1026,6 +1023,14 @@ \edef\pdfthreadmargin {\pdfvariable threadmargin} \pdfthreadmargin \zeropoint \edef\pdfxformmargin {\pdfvariable xformmargin} \pdfxformmargin \zeropoint +\ifnum\luatexversion>88 + \edef\pdfpkfixeddpi {\pdfvariable pkfixeddpi} \pdfpkfixeddpi \plusone + \edef\pdfignoreunknownimages {\pdfvariable ignoreunknownimages} \pdfignoreunknownimages \zerocount +\else + \newcount\pdfpkfixeddpi + \newcount\pdfignoreunknownimages +\fi + \edef\pdfpagesattr {\pdfvariable pagesattr} \edef\pdfpageattr {\pdfvariable pageattr} \edef\pdfpageresources {\pdfvariable pageresources} diff --git a/tex/context/interface/common/i-en-xml.xml b/tex/context/interface/common/i-en-xml.xml new file mode 100644 index 000000000..441ff07d2 --- /dev/null +++ b/tex/context/interface/common/i-en-xml.xml @@ -0,0 +1,722 @@ + + +