summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/meta-ini.lua
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2013-04-08 00:43:40 +0000
committerKarl Berry <karl@freefriends.org>2013-04-08 00:43:40 +0000
commit824f7b0903de8ad7f6ee3d7656005e4c59155e06 (patch)
treeabfc8673ef9916f3ab7074e811207384c301492b /Master/texmf-dist/tex/context/base/meta-ini.lua
parent689aefb0727676ed3cddf331337b4be226495e72 (diff)
context import for TL13, from www.pragma-ade.com/context/beta/cont-tmf.zip
git-svn-id: svn://tug.org/texlive/trunk@29731 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/meta-ini.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/meta-ini.lua127
1 files changed, 95 insertions, 32 deletions
diff --git a/Master/texmf-dist/tex/context/base/meta-ini.lua b/Master/texmf-dist/tex/context/base/meta-ini.lua
index bac1429ae1d..713ba3d5d01 100644
--- a/Master/texmf-dist/tex/context/base/meta-ini.lua
+++ b/Master/texmf-dist/tex/context/base/meta-ini.lua
@@ -7,7 +7,11 @@ if not modules then modules = { } end modules ['meta-ini'] = {
}
local tonumber = tonumber
-local format, gmatch, match, gsub = string.format, string.gmatch, string.match, string.gsub
+local format = string.format
+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 { }
@@ -19,14 +23,14 @@ local status_metapost = logs.messenger("metapost")
local patterns = { "meta-imp-%s.mkiv", "meta-imp-%s.tex", "meta-%s.mkiv", "meta-%s.tex" } -- we are compatible
local function action(name,foundname)
- status_metapost("loaded: library '%s'",name)
+ status_metapost("library %a is loaded",name)
context.startreadingfile()
context.input(foundname)
context.stopreadingfile()
end
local function failure(name)
- report_metapost("unknown: library '%s'",name)
+ report_metapost("library %a is unknown or invalid",name)
end
function commands.useMPlibrary(name)
@@ -43,46 +47,94 @@ end
local colorhash = attributes.list[attributes.private('color')]
-local validdimen = lpeg.patterns.validdimen * lpeg.P(-1)
-
-local lpegmatch = lpeg.match
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",f,s)
+ elseif t == "count" then
+ context("\\the\\numexpr \\%s * %s\\relax",s,f) -- <n>\scratchcounter is not permitted
+ end
+ end
+
+local splitter = lpeg.splitat(":",true)
+
function commands.prepareMPvariable(v) -- slow but ok
if v == "" then
MPcolor("black")
else
- local typ, var = match(v,"(.):(.*)")
- if not typ then
+ local typ, var = lpegmatch(splitter,v)
+ if not var 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,"\\(.-)") do
- 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
- return context("\\number %s",v) -- 0.4 ...
+ elseif not lpegmatch(dimenorname,v) then
+ context("\\number %s",v) -- 0.4 ...
end
- elseif typ == "d" then
+ elseif typ == "d" then -- to be documented
-- dimension
context("\\the\\dimexpr %s",var)
- elseif typ == "n" then
+ elseif typ == "n" then -- to be documented
-- number
context("\\the\\numexpr %s",var)
- elseif typ == "s" then
+ elseif typ == "s" then -- to be documented
-- string
context(var)
- elseif typ == "c" then
+ elseif typ == "c" then -- to be documented
-- color
MPcolor(var)
else
@@ -91,12 +143,23 @@ function commands.prepareMPvariable(v) -- slow but ok
end
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)
+-- 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) 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
+ context.mathematics(lpegmatch(two,format(lpegmatch(one,fmt),n)))
end