diff options
author | Karl Berry <karl@freefriends.org> | 2018-03-20 22:10:59 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2018-03-20 22:10:59 +0000 |
commit | 65d009a0596b194597f47531523addd3e64ed005 (patch) | |
tree | e13bd9beecf63e26491a66aa7a8fa702482f0067 /Master/texmf-dist/tex/context/base/mkiv/meta-ini.lua | |
parent | d1a186333ced7b341e26877907343f08211199f7 (diff) |
context [current] (20mar18)
git-svn-id: svn://tug.org/texlive/trunk@47050 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/meta-ini.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/mkiv/meta-ini.lua | 234 |
1 files changed, 120 insertions, 114 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/meta-ini.lua b/Master/texmf-dist/tex/context/base/mkiv/meta-ini.lua index d3865c4330d..6c4768671f1 100644 --- a/Master/texmf-dist/tex/context/base/mkiv/meta-ini.lua +++ b/Master/texmf-dist/tex/context/base/mkiv/meta-ini.lua @@ -8,138 +8,144 @@ if not modules then modules = { } end modules ['meta-ini'] = { local tonumber = tonumber local format = string.format +local concat = table.concat local lpegmatch, lpegpatterns = lpeg.match, lpeg.patterns local P, Cs, R, S, C, Cc = lpeg.P, lpeg.Cs, lpeg.R, lpeg.S, lpeg.C, lpeg.Cc -local context = context - -metapost = metapost or { } - --- experimental +metapost = metapost or { } +local metapost = metapost +local context = context local colorhash = attributes.list[attributes.private('color')] - local textype = tex.type local MPcolor = context.MPcolor --- local validdimen = lpegpatterns.validdimen * P(-1) --- --- function commands.prepareMPvariable(v) -- slow but ok --- if v == "" then --- MPcolor("black") --- else --- local typ, var = match(v,"(.):(.*)") --- if not typ then --- -- parse --- if colorhash[v] then --- MPcolor(v) --- elseif tonumber(v) then --- context(v) --- elseif lpegmatch(validdimen,v) then --- return context("\\the\\dimexpr %s",v) --- else --- for s in gmatch(v,"\\([a-zA-Z]+)") do -- can have trailing space --- local t = textype(s) --- if t == "dimen" then --- return context("\\the\\dimexpr %s",v) --- elseif t == "count" then --- return context("\\the\\numexpr %s",v) --- end --- end --- context("\\number %s",v) -- 0.4 ... --- end --- elseif typ == "d" then -- to be documented --- -- dimension --- context("\\the\\dimexpr %s",var) --- elseif typ == "n" then -- to be documented --- -- number --- context("\\the\\numexpr %s",var) --- elseif typ == "s" then -- to be documented --- -- string --- context(var) --- elseif typ == "c" then -- to be documented --- -- color --- MPcolor(var) --- else --- context(var) --- end --- end --- end - --- we can actually get the dimen/count values here - -local dimenorname = - lpegpatterns.validdimen / function(s) - context("\\the\\dimexpr %s",s) - end - + (C(lpegpatterns.float) + Cc(1)) * lpegpatterns.space^0 * P("\\") * C(lpegpatterns.letter^1) / function(f,s) - local t = textype(s) - if t == "dimen" then - context("\\the\\dimexpr %s\\%s\\relax",f,s) - elseif t == "count" then - context("\\the\\numexpr \\%s * %s\\relax",s,f) -- <n>\scratchcounter is not permitted +do + + local dimenorname = + lpegpatterns.validdimen / function(s) + context("\\the\\dimexpr %s",s) + end + + (C(lpegpatterns.float) + Cc(1)) * lpegpatterns.space^0 * P("\\") * C(lpegpatterns.letter^1) / function(f,s) + local t = textype(s) + if t == "dimen" then + context("\\the\\dimexpr %s\\%s\\relax",f,s) + elseif t == "count" then + context("\\the\\numexpr \\%s * %s\\relax",s,f) -- <n>\scratchcounter is not permitted + end end - end -local splitter = lpeg.splitat("::",true) - -interfaces.implement { - name = "prepareMPvariable", - arguments = "string", - actions = function(v) - if v == "" then - -- MPcolor("black") - context("black") - else - local typ, var = lpegmatch(splitter,v) - if not var then - -- parse - if colorhash[v] then - -- MPcolor(v) + local splitter = lpeg.splitat("::",true) + + interfaces.implement { + name = "prepareMPvariable", + arguments = "string", + actions = function(v) + if v == "" then + -- MPcolor("black") + context("black") + else + local typ, var = lpegmatch(splitter,v) + if not var then + -- parse + if colorhash[v] then + -- MPcolor(v) + context("%q",var) + elseif tonumber(v) then + context(v) + elseif not lpegmatch(dimenorname,v) then + context("\\number %s",v) -- 0.4 ... + end + elseif typ == "d" then -- to be documented + -- dimension + context("\\the\\dimexpr %s\\relax",var) + elseif typ == "n" then -- to be documented + -- number + context("\\the\\numexpr %s\\relax",var) + elseif typ == "s" then -- to be documented + -- string + -- context(var) context("%q",var) - elseif tonumber(v) then - context(v) - elseif not lpegmatch(dimenorname,v) then - context("\\number %s",v) -- 0.4 ... + elseif typ == "c" then -- to be documented + -- color + -- MPcolor(var) + context("%q",var) + else + context(var) end - elseif typ == "d" then -- to be documented - -- dimension - context("\\the\\dimexpr %s\\relax",var) - elseif typ == "n" then -- to be documented - -- number - context("\\the\\numexpr %s\\relax",var) - elseif typ == "s" then -- to be documented - -- string - -- context(var) - context("%q",var) - elseif typ == "c" then -- to be documented - -- color - -- MPcolor(var) - context("%q",var) - else - context(var) end end + } + +end + +do + + local ctx_mathematics = context.mathematics + + -- function metapost.formatnumber(f,n) -- just lua format + -- f = gsub(f,"@(%d)","%%.%1") + -- f = gsub(f,"@","%%") + -- f = format(f,tonumber(n) or 0) + -- f = gsub(f,"e([%+%-%d]+)",function(s) + -- return format("\\times10^{%s}",tonumber(s) or s) -- strips leading zeros + -- end) + -- context.mathematics(f) + -- end + + -- formatters["\\times10^{%N}"](s) -- strips leading zeros too + + local one = Cs((P("@")/"%%." * (R("09")^1) + P("@")/"%%" + 1)^0) + local two = Cs((P("e")/"" * ((S("+-")^0 * R("09")^1) / function(s) + -- return format("\\times10^{%s}",tonumber(s) or s) + return "\\times10^{" .. (tonumber(s) or s) .."}" + end) + 1)^1) + + -- local two = Cs((P("e")/"" * ((S("+-")^0 * R("09")^1) / formatters["\\times10^{%N}"]) + 1)^1) + + function metapost.formatnumber(fmt,n) -- just lua format + ctx_mathematics(lpegmatch(two,format(lpegmatch(one,fmt),n))) end -} --- function metapost.formatnumber(f,n) -- just lua format --- f = gsub(f,"@(%d)","%%.%1") --- f = gsub(f,"@","%%") --- f = format(f,tonumber(n) or 0) --- f = gsub(f,"e([%+%-%d]+)",function(s) --- return format("\\times10^{%s}",tonumber(s) or s) -- strips leading zeros --- end) --- context.mathematics(f) --- end +end + +do --- formatters["\\times10^{%N}"](s) -- strips leading zeros too + -- this is an old pass-data-to-tex mechanism -local one = Cs((P("@")/"%%." * (R("09")^1) + P("@")/"%%" + 1)^0) -local two = Cs((P("e")/"" * ((S("+-")^0 * R("09")^1) / function(s) return format("\\times10^{%s}",tonumber(s) or s) end) + 1)^1) + local ctx_printtable = context.printtable --- local two = Cs((P("e")/"" * ((S("+-")^0 * R("09")^1) / formatters["\\times10^{%N}"]) + 1)^1) + local data = false + + function mp.start_saving_data(n) + data = { } + end + + function mp.stop_saving_data() + if data then + -- nothing + end + end + + function mp.finish_saving_data() + if data then + -- nothing + end + end + + function mp.save_data(str) + if data then + data[#data+1] = str + end + end + + interfaces.implement { + name = "getMPdata", + actions = function() + if data then + ctx_printtable(data,"\r") + end + end + } -function metapost.formatnumber(fmt,n) -- just lua format - context.mathematics(lpegmatch(two,format(lpegmatch(one,fmt),n))) end |