summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2014-01-21 02:00:14 +0200
committerMarius <mariausol@gmail.com>2014-01-21 02:00:14 +0200
commit7004566a3f05be822d9633027e5ff7d64768c99f (patch)
tree9759d19b7bdcda77f1acc2f04f7a7ec0590e24c9
parentf06cd924de5cfe8c1ffbe8de4cb0c4221258046c (diff)
downloadcontext-7004566a3f05be822d9633027e5ff7d64768c99f.tar.gz
beta 2014.01.21 00:35
-rw-r--r--doc/context/manuals/allkind/mkiv-publications.tex39
-rw-r--r--scripts/context/lua/mtxrun.lua80
-rw-r--r--scripts/context/stubs/mswin/mtxrun.lua80
-rw-r--r--scripts/context/stubs/unix/mtxrun80
-rw-r--r--tex/context/base/cont-new.mkiv2
-rw-r--r--tex/context/base/context-version.pdfbin4087 -> 4086 bytes
-rw-r--r--tex/context/base/context.mkiv2
-rw-r--r--tex/context/base/page-mak.mkvi12
-rw-r--r--tex/context/base/publ-tra.lua241
-rw-r--r--tex/context/base/publ-tra.mkiv8
-rw-r--r--tex/context/base/status-files.pdfbin24773 -> 24769 bytes
-rw-r--r--tex/context/base/status-lua.pdfbin229066 -> 231511 bytes
-rw-r--r--tex/context/base/util-str.lua138
-rw-r--r--tex/generic/context/luatex/luatex-fonts-merged.lua76
14 files changed, 539 insertions, 219 deletions
diff --git a/doc/context/manuals/allkind/mkiv-publications.tex b/doc/context/manuals/allkind/mkiv-publications.tex
index 9e2969277..f498fd622 100644
--- a/doc/context/manuals/allkind/mkiv-publications.tex
+++ b/doc/context/manuals/allkind/mkiv-publications.tex
@@ -426,6 +426,28 @@ but most publication|-|related commands accept optional arguments that denote th
dataset and references to entries can be prefixed with a dataset identifier.. More
about that later.
+Sometimes you want to check a database. One way of doing that is the following:
+
+\startbuffer
+\definebtxdataset[check]
+
+\usebtxdataset[check][mkiv-publications-check.bib]
+
+\showbtxdatasetcompleteness[check]
+\stopbuffer
+
+\typebuffer
+
+The database like like this:
+
+\typefile{mkiv-publications-check.bib}
+
+The completeness check shows (with green field names) the required fields and
+when one is missing this is indicated in red. In blue we show what gets
+inherited.
+
+\getbuffer
+
\stopchapter
\startchapter[title=Renderings]
@@ -1211,9 +1233,9 @@ suffix, you can do this:
\startchapter[title=Notes]
-The move from external \BIBTEX\ processing to internal processing has the advantage that
-we stay within the same run. In the traditional approach we had roughly the following
-steps:
+The move from external \BIBTEX\ processing to internal processing has the
+advantage that we stay within the same run. In the traditional approach we had
+roughly the following steps:
\startitemize[packed]
\startitem the first run information is collected and written to file \stopitem
@@ -1221,9 +1243,9 @@ steps:
\startitem successive runs use that data for references and producing lists \stopitem
\stopitemize
-In the \MKIV\ approach the bibliographic database is loaded in memory each run and
-processing also happens each run. On paper this looks less efficient but as \LUA\ is
-quite fast, in practice performance is much better.
+In the \MKIV\ approach the bibliographic database is loaded in memory each run
+and processing also happens each run. On paper this looks less efficient but as
+\LUA\ is quite fast, in practice performance is much better.
Probably most demanding is the treatment of authors as we have to analyze names,
split multiple authors and reassemble firstnames, vons, surnames and juniors.
@@ -1235,8 +1257,9 @@ typical one of these cases where using \LUAJITTEX\ saves quite time. On my
machine it took just over 100 seconds to get this done. Unfortunately not all
operating systems performed equally well: 32 bit versions worked fine, but 64 bit
\LINUX\ either crashed (stalled) the machine or ran out of memory rather fast,
-while \OSX\ and \WINDOWS\ performed fine. In practice you will never run into this,
-unless you produce massive amounts of bibliographic entries.
+while \MACOSX\ and \WINDOWS\ performed fine. In practice you will never run into
+this, unless you produce massive amounts of bibliographic entries. \LUAJIT\ has
+some benefits but also some drawbacks.
\stopchapter
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua
index cd1b06df0..ca5957f70 100644
--- a/scripts/context/lua/mtxrun.lua
+++ b/scripts/context/lua/mtxrun.lua
@@ -4810,7 +4810,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["util-str"] = package.loaded["util-str"] or true
--- original size: 26857, stripped down to: 15062
+-- original size: 29070, stripped down to: 15259
if not modules then modules={} end modules ['util-str']={
version=1.001,
@@ -4829,8 +4829,12 @@ 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=utf.char,utf.byte
-local loadstripped=_LUAVERSION<5.2 and load or function(str)
- return load(dump(load(str),true))
+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
local stripper=patterns.stripzeros
@@ -4980,31 +4984,33 @@ function number.sparseexponent(f,n)
end
return tostring(n)
end
-local preamble=[[
-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 tracedchar = string.tracedchar
-local autosingle = string.autosingle
-local autodouble = string.autodouble
-local sequenced = table.sequenced
-local formattednumber = number.formatted
-local sparseexponent = number.sparseexponent
-]]
local template=[[
%s
%s
return function(%s) return %s end
]]
+local environment={
+ 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,
+ tracedchar=string.tracedchar,
+ autosingle=string.autosingle,
+ autodouble=string.autodouble,
+ sequenced=table.sequenced,
+ formattednumber=number.formatted,
+ sparseexponent=number.sparseexponent,
+}
+local preamble=""
local arguments={ "a1" }
setmetatable(arguments,{ __index=function(t,k)
local v=t[k-1]..",a"..k
@@ -5326,8 +5332,8 @@ local builder=Cs { "start",
["!"]=Carg(2)*prefix_any*P("!")*C((1-P("!"))^1)*P("!")/format_extension,
}
local direct=Cs (
- P("%")/""*Cc([[local format = string.format return function(str) return format("%]])*(S("+- .")+R("09"))^0*S("sqidfgGeExXo")*Cc([[",str) end]])*P(-1)
- )
+ P("%")*(S("+- .")+R("09"))^0*S("sqidfgGeExXo")*P(-1)/[[local format = string.format return function(str) return format("%0",str) end]]
+)
local function make(t,str)
local f
local p
@@ -5339,7 +5345,7 @@ local function make(t,str)
p=lpegmatch(builder,str,1,"..",t._extensions_)
if n>0 then
p=format(template,preamble,t._preamble_,arguments[n],p)
- f=loadstripped(p)()
+ f=loadstripped(p,t._environment_)()
else
f=function() return str end
end
@@ -5352,7 +5358,11 @@ local function use(t,fmt,...)
end
strings.formatters={}
function strings.formatters.new()
- local t={ _extensions_={},_preamble_="",_type_="formatter" }
+ local e={}
+ for k,v in next,environment do
+ e[k]=v
+ end
+ local t={ _extensions_={},_preamble_="",_environment_=e,_type_="formatter" }
setmetatable(t,{ __index=make,__call=use })
return t
end
@@ -5362,8 +5372,12 @@ string.formatter=function(str,...) return formatters[str](...) end
local function add(t,name,template,preamble)
if type(t)=="table" and t._type_=="formatter" then
t._extensions_[name]=template or "%s"
- if preamble then
+ if type(preamble)=="string" then
t._preamble_=preamble.."\n"..t._preamble_
+ elseif type(preamble)=="table" then
+ for k,v in next,preamble do
+ t._environment_[k]=v
+ end
end
end
end
@@ -5372,9 +5386,9 @@ patterns.xmlescape=Cs((P("<")/"&lt;"+P(">")/"&gt;"+P("&")/"&amp;"+P('"')/"&quot;
patterns.texescape=Cs((C(S("#$%\\{}"))/"\\%1"+P(1))^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('"'))
-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]])
+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 -- of closure
@@ -16691,8 +16705,8 @@ end -- of closure
-- used libraries : l-lua.lua l-package.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-gzip.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-mrg.lua util-tpl.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua
-- skipped libraries : -
--- original bytes : 685669
--- stripped bytes : 242778
+-- original bytes : 687882
+-- stripped bytes : 244794
-- end library merge
diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua
index cd1b06df0..ca5957f70 100644
--- a/scripts/context/stubs/mswin/mtxrun.lua
+++ b/scripts/context/stubs/mswin/mtxrun.lua
@@ -4810,7 +4810,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["util-str"] = package.loaded["util-str"] or true
--- original size: 26857, stripped down to: 15062
+-- original size: 29070, stripped down to: 15259
if not modules then modules={} end modules ['util-str']={
version=1.001,
@@ -4829,8 +4829,12 @@ 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=utf.char,utf.byte
-local loadstripped=_LUAVERSION<5.2 and load or function(str)
- return load(dump(load(str),true))
+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
local stripper=patterns.stripzeros
@@ -4980,31 +4984,33 @@ function number.sparseexponent(f,n)
end
return tostring(n)
end
-local preamble=[[
-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 tracedchar = string.tracedchar
-local autosingle = string.autosingle
-local autodouble = string.autodouble
-local sequenced = table.sequenced
-local formattednumber = number.formatted
-local sparseexponent = number.sparseexponent
-]]
local template=[[
%s
%s
return function(%s) return %s end
]]
+local environment={
+ 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,
+ tracedchar=string.tracedchar,
+ autosingle=string.autosingle,
+ autodouble=string.autodouble,
+ sequenced=table.sequenced,
+ formattednumber=number.formatted,
+ sparseexponent=number.sparseexponent,
+}
+local preamble=""
local arguments={ "a1" }
setmetatable(arguments,{ __index=function(t,k)
local v=t[k-1]..",a"..k
@@ -5326,8 +5332,8 @@ local builder=Cs { "start",
["!"]=Carg(2)*prefix_any*P("!")*C((1-P("!"))^1)*P("!")/format_extension,
}
local direct=Cs (
- P("%")/""*Cc([[local format = string.format return function(str) return format("%]])*(S("+- .")+R("09"))^0*S("sqidfgGeExXo")*Cc([[",str) end]])*P(-1)
- )
+ P("%")*(S("+- .")+R("09"))^0*S("sqidfgGeExXo")*P(-1)/[[local format = string.format return function(str) return format("%0",str) end]]
+)
local function make(t,str)
local f
local p
@@ -5339,7 +5345,7 @@ local function make(t,str)
p=lpegmatch(builder,str,1,"..",t._extensions_)
if n>0 then
p=format(template,preamble,t._preamble_,arguments[n],p)
- f=loadstripped(p)()
+ f=loadstripped(p,t._environment_)()
else
f=function() return str end
end
@@ -5352,7 +5358,11 @@ local function use(t,fmt,...)
end
strings.formatters={}
function strings.formatters.new()
- local t={ _extensions_={},_preamble_="",_type_="formatter" }
+ local e={}
+ for k,v in next,environment do
+ e[k]=v
+ end
+ local t={ _extensions_={},_preamble_="",_environment_=e,_type_="formatter" }
setmetatable(t,{ __index=make,__call=use })
return t
end
@@ -5362,8 +5372,12 @@ string.formatter=function(str,...) return formatters[str](...) end
local function add(t,name,template,preamble)
if type(t)=="table" and t._type_=="formatter" then
t._extensions_[name]=template or "%s"
- if preamble then
+ if type(preamble)=="string" then
t._preamble_=preamble.."\n"..t._preamble_
+ elseif type(preamble)=="table" then
+ for k,v in next,preamble do
+ t._environment_[k]=v
+ end
end
end
end
@@ -5372,9 +5386,9 @@ patterns.xmlescape=Cs((P("<")/"&lt;"+P(">")/"&gt;"+P("&")/"&amp;"+P('"')/"&quot;
patterns.texescape=Cs((C(S("#$%\\{}"))/"\\%1"+P(1))^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('"'))
-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]])
+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 -- of closure
@@ -16691,8 +16705,8 @@ end -- of closure
-- used libraries : l-lua.lua l-package.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-gzip.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-mrg.lua util-tpl.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua
-- skipped libraries : -
--- original bytes : 685669
--- stripped bytes : 242778
+-- original bytes : 687882
+-- stripped bytes : 244794
-- end library merge
diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun
index cd1b06df0..ca5957f70 100644
--- a/scripts/context/stubs/unix/mtxrun
+++ b/scripts/context/stubs/unix/mtxrun
@@ -4810,7 +4810,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["util-str"] = package.loaded["util-str"] or true
--- original size: 26857, stripped down to: 15062
+-- original size: 29070, stripped down to: 15259
if not modules then modules={} end modules ['util-str']={
version=1.001,
@@ -4829,8 +4829,12 @@ 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=utf.char,utf.byte
-local loadstripped=_LUAVERSION<5.2 and load or function(str)
- return load(dump(load(str),true))
+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
local stripper=patterns.stripzeros
@@ -4980,31 +4984,33 @@ function number.sparseexponent(f,n)
end
return tostring(n)
end
-local preamble=[[
-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 tracedchar = string.tracedchar
-local autosingle = string.autosingle
-local autodouble = string.autodouble
-local sequenced = table.sequenced
-local formattednumber = number.formatted
-local sparseexponent = number.sparseexponent
-]]
local template=[[
%s
%s
return function(%s) return %s end
]]
+local environment={
+ 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,
+ tracedchar=string.tracedchar,
+ autosingle=string.autosingle,
+ autodouble=string.autodouble,
+ sequenced=table.sequenced,
+ formattednumber=number.formatted,
+ sparseexponent=number.sparseexponent,
+}
+local preamble=""
local arguments={ "a1" }
setmetatable(arguments,{ __index=function(t,k)
local v=t[k-1]..",a"..k
@@ -5326,8 +5332,8 @@ local builder=Cs { "start",
["!"]=Carg(2)*prefix_any*P("!")*C((1-P("!"))^1)*P("!")/format_extension,
}
local direct=Cs (
- P("%")/""*Cc([[local format = string.format return function(str) return format("%]])*(S("+- .")+R("09"))^0*S("sqidfgGeExXo")*Cc([[",str) end]])*P(-1)
- )
+ P("%")*(S("+- .")+R("09"))^0*S("sqidfgGeExXo")*P(-1)/[[local format = string.format return function(str) return format("%0",str) end]]
+)
local function make(t,str)
local f
local p
@@ -5339,7 +5345,7 @@ local function make(t,str)
p=lpegmatch(builder,str,1,"..",t._extensions_)
if n>0 then
p=format(template,preamble,t._preamble_,arguments[n],p)
- f=loadstripped(p)()
+ f=loadstripped(p,t._environment_)()
else
f=function() return str end
end
@@ -5352,7 +5358,11 @@ local function use(t,fmt,...)
end
strings.formatters={}
function strings.formatters.new()
- local t={ _extensions_={},_preamble_="",_type_="formatter" }
+ local e={}
+ for k,v in next,environment do
+ e[k]=v
+ end
+ local t={ _extensions_={},_preamble_="",_environment_=e,_type_="formatter" }
setmetatable(t,{ __index=make,__call=use })
return t
end
@@ -5362,8 +5372,12 @@ string.formatter=function(str,...) return formatters[str](...) end
local function add(t,name,template,preamble)
if type(t)=="table" and t._type_=="formatter" then
t._extensions_[name]=template or "%s"
- if preamble then
+ if type(preamble)=="string" then
t._preamble_=preamble.."\n"..t._preamble_
+ elseif type(preamble)=="table" then
+ for k,v in next,preamble do
+ t._environment_[k]=v
+ end
end
end
end
@@ -5372,9 +5386,9 @@ patterns.xmlescape=Cs((P("<")/"&lt;"+P(">")/"&gt;"+P("&")/"&amp;"+P('"')/"&quot;
patterns.texescape=Cs((C(S("#$%\\{}"))/"\\%1"+P(1))^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('"'))
-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]])
+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 -- of closure
@@ -16691,8 +16705,8 @@ end -- of closure
-- used libraries : l-lua.lua l-package.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-gzip.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-mrg.lua util-tpl.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua
-- skipped libraries : -
--- original bytes : 685669
--- stripped bytes : 242778
+-- original bytes : 687882
+-- stripped bytes : 244794
-- end library merge
diff --git a/tex/context/base/cont-new.mkiv b/tex/context/base/cont-new.mkiv
index 2476d4af1..3e00fa124 100644
--- a/tex/context/base/cont-new.mkiv
+++ b/tex/context/base/cont-new.mkiv
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\newcontextversion{2014.01.20 14:44}
+\newcontextversion{2014.01.21 00:35}
%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/context-version.pdf b/tex/context/base/context-version.pdf
index 11877c24a..d773a32d5 100644
--- a/tex/context/base/context-version.pdf
+++ b/tex/context/base/context-version.pdf
Binary files differ
diff --git a/tex/context/base/context.mkiv b/tex/context/base/context.mkiv
index 3ba9c3230..997c6422d 100644
--- a/tex/context/base/context.mkiv
+++ b/tex/context/base/context.mkiv
@@ -28,7 +28,7 @@
%D up and the dependencies are more consistent.
\edef\contextformat {\jobname}
-\edef\contextversion{2014.01.20 14:44}
+\edef\contextversion{2014.01.21 00:35}
\edef\contextkind {beta}
%D For those who want to use this:
diff --git a/tex/context/base/page-mak.mkvi b/tex/context/base/page-mak.mkvi
index 71af520a1..708678878 100644
--- a/tex/context/base/page-mak.mkvi
+++ b/tex/context/base/page-mak.mkvi
@@ -92,9 +92,12 @@
{\doifelsecommandhandler\??makeup{#name}\page_makeup_start_indeed\page_makeup_start_nop[#name]}%
\def\page_makeup_start_indeed[#name][#settings]%
- {\doifelsenothing{\namedmakeupparameter{#name}\c!page}
- {\page}% new, so best not have dangling mess here like references (we could capture then and flush embedded)
- {\page[\namedmakeupparameter{#name}\c!page]}%
+ {\edef\p_page{\namedmakeupparameter{#name}\c!page}
+ \ifx\p_page\empty
+ \page % new, so best not have dangling mess here like references (we could capture then and flush embedded)
+ \else
+ \page[\p_page]%
+ \fi
\startlayout[#name]% includes \page
\bgroup
\edef\currentmakeup{#name}%
@@ -183,7 +186,8 @@
\c!textstate=\v!normal,
\c!headerstate=\v!stop,
\c!footerstate=\v!stop,
- \c!pagestate=\v!stop] % in manual ! ! !
+ % \c!pagestate=\v!stop] % in manual ! ! !
+ \c!pagestate=\v!start]
\definemakeup
[\v!standard]
diff --git a/tex/context/base/publ-tra.lua b/tex/context/base/publ-tra.lua
index 90bae67e9..98c81d800 100644
--- a/tex/context/base/publ-tra.lua
+++ b/tex/context/base/publ-tra.lua
@@ -10,11 +10,14 @@ local sortedhash = table.sortedhash
local tracers = { }
publications.tracers = tracers
+local datasets = publications.datasets
local context = context
-local NC, NR, bold = context.NC, context.NR, context.bold
+local NC, NR = context.NC, context.NR
+local bold = context.bold
+local darkgreen, darkred, darkblue = context.darkgreen, context.darkred, context.darkblue
-publications.tracers.fields = table.sorted {
+local fields = table.sorted {
"abstract",
"address",
"annotate",
@@ -63,7 +66,7 @@ publications.tracers.fields = table.sorted {
"revision",
}
-publications.tracers.citevariants = table.sorted {
+local citevariants = table.sorted {
"author",
"authoryear",
"authoryears",
@@ -80,52 +83,214 @@ publications.tracers.citevariants = table.sorted {
"num",
}
-publications.tracers.listvariants = table.sorted {
+local listvariants = table.sorted {
"author",
"editor",
"artauthor",
}
-publications.tracers.categories = table.sorted {
- "article",
- "book",
- "booklet",
- "conference",
- "inbook",
- "incollection",
- "inproceedings",
- "manual",
- "mastersthesis",
- "misc",
- "phdthesis",
- "proceedings",
- "techreport",
- "unpublished",
+-- local categories = table.sorted {
+-- "article",
+-- "book",
+-- "booklet",
+-- "conference",
+-- "inbook",
+-- "incollection",
+-- "inproceedings",
+-- "manual",
+-- "mastersthesis",
+-- "misc",
+-- "phdthesis",
+-- "proceedings",
+-- "techreport",
+-- "unpublished",
+-- }
+
+local categories = {
+ article = {
+ required = { "author", "title", "journal", "year" },
+ optional = { "volume", "number", "pages", "month", "note" },
+ },
+ book = {
+ required = { { "author", "editor" }, "title", "publisher", "year" },
+ optional = { { "volume", "number" }, "series", "address", "edition", "month","note" },
+ },
+ booklet = {
+ required = { "title" },
+ optional = { "author", "howpublished", "address", "month", "year", "note" },
+ },
+ inbook = {
+ required = { { "author", "editor" }, "title", { "chapter", "pages" }, "publisher","year" },
+ optional = { { "volume", "number" }, "series", "type", "address", "edition", "month", "note" },
+ },
+ incollection = {
+ required = { "author", "title", "booktitle", "publisher", "year" },
+ optional = { "editor", { "volume", "number" }, "series", "type", "chapter", "pages", "address", "edition", "month", "note" },
+ },
+ inproceedings = {
+ required = { "author", "title", "booktitle", "year" },
+ optional = { "editor", { "volume", "number" }, "series", "pages", "address", "month","organization", "publisher", "note" },
+ },
+ manual = {
+ required = { "title" },
+ optional = { "author", "organization", "address", "edition", "month", "year", "note" },
+ },
+ mastersthesis = {
+ required = { "author", "title", "school", "year" },
+ optional = { "type", "address", "month", "note" },
+ },
+ misc = {
+ required = { "author", "title", "howpublished", "month", "year", "note" },
+ optional = { "author", "title", "howpublished", "month", "year", "note" },
+ },
+ phdthesis = {
+ required = { "author", "title", "school", "year" },
+ optional = { "type", "address", "month", "note" },
+ },
+ proceedings = {
+ required = { "title", "year" },
+ optional = { "editor", { "volume", "number" }, "series", "address", "month", "organization", "publisher", "note" },
+ },
+ techreport = {
+ required = { "author", "title", "institution", "year" },
+ optional = { "type", "number", "address", "month", "note" },
+ },
+ unpublished = {
+ required = { "author", "title", "note" },
+ optional = { "month", "year" },
+ },
}
-function tracers.showdatasetfields(name)
- if name and name ~= "" then
- local luadata = publications.datasets[name].luadata
- if next(luadata) then
- context.starttabulate { "|lT|lT|pT|" }
- NC() bold("tag")
- NC() bold("category")
- NC() bold("fields")
- NC() NR() context.FL() -- HL()
- for k, v in sortedhash(luadata) do
- NC() context(k)
- NC() context(v.category)
- NC()
- for k, v in sortedhash(v) do
- if k ~= "details" and k ~= "tag" and k ~= "category" then
- context("%s ",k)
+
+publications.tracers.fields = fields
+publications.tracers.categories = categories
+publications.tracers.citevariants = citevariants
+publications.tracers.listvariants = listvariants
+-- -- --
+
+function tracers.showdatasetfields(dataset)
+ local luadata = datasets[dataset].luadata
+ if next(luadata) then
+ context.starttabulate { "|lT|lT|pT|" }
+ NC() bold("tag")
+ NC() bold("category")
+ NC() bold("fields")
+ NC() NR() context.FL() -- HL()
+ for k, v in sortedhash(luadata) do
+ NC() context(k)
+ NC() context(v.category)
+ NC()
+ for k, v in sortedhash(v) do
+ if k ~= "details" and k ~= "tag" and k ~= "category" then
+ context("%s ",k)
+ end
+ end
+ NC() NR()
+ end
+ context.stoptabulate()
+ end
+end
+
+function tracers.showdatasetcompleteness(dataset)
+
+ dataset = datasets[dataset]
+
+ local preamble = { "|lBTw(10em)|p|" }
+
+ local function required(key,value,indirect)
+ NC() darkgreen(key)
+ NC() if indirect then
+ darkblue(value)
+ elseif value then
+ context(value)
+ else
+ darkred("\\tttf [missing]")
+ end
+ NC() NR()
+ end
+
+ local function optional(key,value,indirect)
+ NC() context(key)
+ NC() if indirect then
+ darkblue(value)
+ elseif value then
+ context(value)
+ end
+ NC() NR()
+ end
+
+ local function identified(tag,crossref)
+ NC() context("tag")
+ NC() if crossref then
+ context("\\tttf %s\\hfill\\darkblue => %s",tag,crossref)
+ else
+ context("\\tttf %s",tag)
+ end
+ NC() NR()
+ end
+
+ local luadata = datasets[dataset].luadata
+
+ if next(luadata) then
+ for tag, entry in table.sortedhash(luadata) do
+ local category = entry.category
+ local fields = categories[category]
+ if fields then
+ context.starttabulate(preamble)
+ identified(tag,entry.crossref)
+ context.HL()
+ local requiredfields = fields.required
+ local optionalfields = fields.optional
+ for i=1,#requiredfields do
+ local r = requiredfields[i]
+ if type(r) == "table" then
+ local okay = true
+ for i=1,#r do
+ local ri = r[i]
+ if rawget(entry,ri) then
+ required(ri,entry[ri])
+ okay = true
+ elseif entry[ri] then
+ required(ri,entry[ri],true)
+ okay = true
+ end
end
+ if not okay then
+ required(table.concat(r,"\\letterbar "))
+ end
+ elseif rawget(entry,r) then
+ required(r,entry[r])
+ elseif entry[r] then
+ required(r,entry[r],true)
+ else
+ required(r)
end
- NC() NR()
end
- context.stoptabulate()
+ for i=1,#optionalfields do
+ local o = optionalfields[i]
+ if type(o) == "table" then
+ for i=1,#o do
+ local oi = o[i]
+ if rawget(entry,oi) then
+ optional(oi,entry[oi])
+ elseif entry[oi] then
+ optional(oi,entry[oi],true)
+ end
+ end
+ elseif rawget(entry,o) then
+ optional(o,entry[o])
+ elseif entry[o] then
+ optional(o,entry[o],true)
+ end
+ end
+ context.stoptabulate()
+ else
+ -- error
+ end
end
end
+
end
-commands.showbtxdatasetfields = tracers.showdatasetfields
+commands.showbtxdatasetfields = tracers.showdatasetfields
+commands.showbtxdatasetcompleteness = tracers.showdatasetcompleteness
diff --git a/tex/context/base/publ-tra.mkiv b/tex/context/base/publ-tra.mkiv
index 70db634fe..5f50d99f3 100644
--- a/tex/context/base/publ-tra.mkiv
+++ b/tex/context/base/publ-tra.mkiv
@@ -15,6 +15,8 @@
\registerctxluafile{publ-tra}{1.001}
+% todo: use the module interface
+
\unprotect
\unexpanded\def\showbtxdatasetfields
@@ -23,4 +25,10 @@
\def\publ_dataset_show_fields[#1]%
{\ctxcommand{showbtxdatasetfields("\iffirstargument#1\else\currentbtxdataset\fi")}}
+\unexpanded\def\showbtxdatasetcompleteness
+ {\dosingleempty\publ_dataset_show_completeness}
+
+\def\publ_dataset_show_completeness[#1]%
+ {\ctxcommand{showbtxdatasetcompleteness("\iffirstargument#1\else\currentbtxdataset\fi")}}
+
\protect \endinput
diff --git a/tex/context/base/status-files.pdf b/tex/context/base/status-files.pdf
index 6f85c7114..5fb2325b2 100644
--- a/tex/context/base/status-files.pdf
+++ b/tex/context/base/status-files.pdf
Binary files differ
diff --git a/tex/context/base/status-lua.pdf b/tex/context/base/status-lua.pdf
index 19310e11b..b64c5f130 100644
--- a/tex/context/base/status-lua.pdf
+++ b/tex/context/base/status-lua.pdf
Binary files differ
diff --git a/tex/context/base/util-str.lua b/tex/context/base/util-str.lua
index af8b1651e..421eefdf3 100644
--- a/tex/context/base/util-str.lua
+++ b/tex/context/base/util-str.lua
@@ -20,8 +20,16 @@ local utfchar, utfbyte = utf.char, utf.byte
----- loadstripped = utilities.lua.loadstripped
----- setmetatableindex = table.setmetatableindex
-local loadstripped = _LUAVERSION < 5.2 and load or function(str)
- return load(dump(load(str),true)) -- it only makes sense in luajit and luatex where we have a stipped load
+-- local loadstripped = _LUAVERSION < 5.2 and load or function(str)
+-- return load(dump(load(str),true)) -- it only makes sense in luajit and luatex where we have a stipped load
+-- 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
@@ -291,33 +299,68 @@ function number.sparseexponent(f,n)
return tostring(n)
end
-local preamble = [[
-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 tracedchar = string.tracedchar
-local autosingle = string.autosingle
-local autodouble = string.autodouble
-local sequenced = table.sequenced
-local formattednumber = number.formatted
-local sparseexponent = number.sparseexponent
-]]
-
local template = [[
%s
%s
return function(%s) return %s end
]]
+-- local environment = {
+-- lpeg = lpeg,
+-- type = type,
+-- string = string,
+-- number = number,
+-- table = table,
+-- utf = utf,
+-- }
+--
+-- local preamble = [[
+-- 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 tracedchar = string.tracedchar
+-- local autosingle = string.autosingle
+-- local autodouble = string.autodouble
+-- local sequenced = table.sequenced
+-- local formattednumber = number.formatted
+-- local sparseexponent = number.sparseexponent
+-- ]]
+
+local environment = {
+ 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,
+ tracedchar = string.tracedchar,
+ autosingle = string.autosingle,
+ autodouble = string.autodouble,
+ sequenced = table.sequenced,
+ formattednumber = number.formatted,
+ sparseexponent = number.sparseexponent,
+}
+
+local preamble = ""
+
+-- -- --
+
local arguments = { "a1" } -- faster than previously used (select(n,...))
setmetatable(arguments, { __index =
@@ -740,28 +783,37 @@ local builder = Cs { "start",
-- we can be clever and only alias what is needed
+-- local direct = Cs (
+-- P("%")/""
+-- * Cc([[local format = string.format return function(str) return format("%]])
+-- * (S("+- .") + R("09"))^0
+-- * S("sqidfgGeExXo")
+-- * Cc([[",str) end]])
+-- * P(-1)
+-- )
+
local direct = Cs (
- P("%")/""
- * Cc([[local format = string.format return function(str) return format("%]])
- * (S("+- .") + R("09"))^0
- * S("sqidfgGeExXo")
- * Cc([[",str) end]])
- * P(-1)
- )
+ P("%")
+ * (S("+- .") + R("09"))^0
+ * S("sqidfgGeExXo")
+ * P(-1) / [[local format = string.format return function(str) return format("%0",str) end]]
+)
local function make(t,str)
local f
local p
local p = lpegmatch(direct,str)
if p then
+ -- f = loadstripped(p)()
+ -- print("builder 1 >",p)
f = loadstripped(p)()
else
n = 0
p = lpegmatch(builder,str,1,"..",t._extensions_) -- after this we know n
if n > 0 then
p = format(template,preamble,t._preamble_,arguments[n],p)
--- print("builder>",p)
- f = loadstripped(p)()
+ -- print("builder 2 >",p)
+ f = loadstripped(p,t._environment_)() -- t._environment is not populated (was experiment)
else
f = function() return str end
end
@@ -817,7 +869,11 @@ strings.formatters = { }
-- clear that table when a threshold is reached
function strings.formatters.new()
- local t = { _extensions_ = { }, _preamble_ = "", _type_ = "formatter" }
+ local e = { } -- better make a copy as we can overload
+ for k, v in next, environment do
+ e[k] = v
+ end
+ local t = { _extensions_ = { }, _preamble_ = "", _environment_ = e, _type_ = "formatter" }
setmetatable(t, { __index = make, __call = use })
return t
end
@@ -838,8 +894,12 @@ string.formatter = function(str,...) return formatters[str](...) end -- someti
local function add(t,name,template,preamble)
if type(t) == "table" and t._type_ == "formatter" then
t._extensions_[name] = template or "%s"
- if preamble then
+ if type(preamble) == "string" then
t._preamble_ = preamble .. "\n" .. t._preamble_ -- so no overload !
+ elseif type(preamble) == "table" then
+ for k, v in next, preamble do
+ t._environment_[k] = v
+ end
end
end
end
@@ -856,9 +916,13 @@ 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)
-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]])
+-- 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]])
+
+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/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua
index 8afec4770..945039150 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 : luatex-fonts-merged.lua
-- parent file : luatex-fonts.lua
--- merge date : 01/20/14 14:44:35
+-- merge date : 01/21/14 00:35:43
do -- begin closure to overcome local limits and interference
@@ -2516,8 +2516,12 @@ 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=utf.char,utf.byte
-local loadstripped=_LUAVERSION<5.2 and load or function(str)
- return load(dump(load(str),true))
+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
local stripper=patterns.stripzeros
@@ -2667,31 +2671,33 @@ function number.sparseexponent(f,n)
end
return tostring(n)
end
-local preamble=[[
-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 tracedchar = string.tracedchar
-local autosingle = string.autosingle
-local autodouble = string.autodouble
-local sequenced = table.sequenced
-local formattednumber = number.formatted
-local sparseexponent = number.sparseexponent
-]]
local template=[[
%s
%s
return function(%s) return %s end
]]
+local environment={
+ 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,
+ tracedchar=string.tracedchar,
+ autosingle=string.autosingle,
+ autodouble=string.autodouble,
+ sequenced=table.sequenced,
+ formattednumber=number.formatted,
+ sparseexponent=number.sparseexponent,
+}
+local preamble=""
local arguments={ "a1" }
setmetatable(arguments,{ __index=function(t,k)
local v=t[k-1]..",a"..k
@@ -3013,8 +3019,8 @@ local builder=Cs { "start",
["!"]=Carg(2)*prefix_any*P("!")*C((1-P("!"))^1)*P("!")/format_extension,
}
local direct=Cs (
- P("%")/""*Cc([[local format = string.format return function(str) return format("%]])*(S("+- .")+R("09"))^0*S("sqidfgGeExXo")*Cc([[",str) end]])*P(-1)
- )
+ P("%")*(S("+- .")+R("09"))^0*S("sqidfgGeExXo")*P(-1)/[[local format = string.format return function(str) return format("%0",str) end]]
+)
local function make(t,str)
local f
local p
@@ -3026,7 +3032,7 @@ local function make(t,str)
p=lpegmatch(builder,str,1,"..",t._extensions_)
if n>0 then
p=format(template,preamble,t._preamble_,arguments[n],p)
- f=loadstripped(p)()
+ f=loadstripped(p,t._environment_)()
else
f=function() return str end
end
@@ -3039,7 +3045,11 @@ local function use(t,fmt,...)
end
strings.formatters={}
function strings.formatters.new()
- local t={ _extensions_={},_preamble_="",_type_="formatter" }
+ local e={}
+ for k,v in next,environment do
+ e[k]=v
+ end
+ local t={ _extensions_={},_preamble_="",_environment_=e,_type_="formatter" }
setmetatable(t,{ __index=make,__call=use })
return t
end
@@ -3049,8 +3059,12 @@ string.formatter=function(str,...) return formatters[str](...) end
local function add(t,name,template,preamble)
if type(t)=="table" and t._type_=="formatter" then
t._extensions_[name]=template or "%s"
- if preamble then
+ if type(preamble)=="string" then
t._preamble_=preamble.."\n"..t._preamble_
+ elseif type(preamble)=="table" then
+ for k,v in next,preamble do
+ t._environment_[k]=v
+ end
end
end
end
@@ -3059,9 +3073,9 @@ patterns.xmlescape=Cs((P("<")/"&lt;"+P(">")/"&gt;"+P("&")/"&amp;"+P('"')/"&quot;
patterns.texescape=Cs((C(S("#$%\\{}"))/"\\%1"+P(1))^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('"'))
-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]])
+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 -- closure