From a88e6c978e2848ed6a557b13a39c39dd2eb7d7f3 Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 5 Mar 2013 20:20:17 +0200 Subject: beta 2013.03.05 19:10 --- tex/context/base/cont-new.mkii | 2 +- tex/context/base/cont-new.mkiv | 2 +- tex/context/base/context-version.pdf | Bin 4135 -> 4131 bytes tex/context/base/context-version.png | Bin 40313 -> 40017 bytes tex/context/base/context.mkii | 2 +- tex/context/base/context.mkiv | 2 +- tex/context/base/status-files.pdf | Bin 24803 -> 24817 bytes tex/context/base/status-lua.pdf | Bin 209215 -> 209244 bytes tex/context/base/util-ran.lua | 107 +++++++++++++++++++++ tex/context/base/util-tpl.lua | 92 ++++++++++++++---- tex/generic/context/luatex/luatex-fonts-merged.lua | 2 +- 11 files changed, 184 insertions(+), 25 deletions(-) create mode 100644 tex/context/base/util-ran.lua (limited to 'tex') diff --git a/tex/context/base/cont-new.mkii b/tex/context/base/cont-new.mkii index d48699773..43e85bbda 100644 --- a/tex/context/base/cont-new.mkii +++ b/tex/context/base/cont-new.mkii @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2013.03.05 16:40} +\newcontextversion{2013.03.05 19:10} %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/cont-new.mkiv b/tex/context/base/cont-new.mkiv index 5f1458551..458c168af 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{2013.03.05 16:40} +\newcontextversion{2013.03.05 19:10} %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 b4229a6ae..597c8952e 100644 Binary files a/tex/context/base/context-version.pdf and b/tex/context/base/context-version.pdf differ diff --git a/tex/context/base/context-version.png b/tex/context/base/context-version.png index 429cde9e0..2940bcabd 100644 Binary files a/tex/context/base/context-version.png and b/tex/context/base/context-version.png differ diff --git a/tex/context/base/context.mkii b/tex/context/base/context.mkii index 6295767a5..a24c9939b 100644 --- a/tex/context/base/context.mkii +++ b/tex/context/base/context.mkii @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2013.03.05 16:40} +\edef\contextversion{2013.03.05 19:10} %D For those who want to use this: diff --git a/tex/context/base/context.mkiv b/tex/context/base/context.mkiv index 991356070..d846c90c3 100644 --- a/tex/context/base/context.mkiv +++ b/tex/context/base/context.mkiv @@ -25,7 +25,7 @@ %D up and the dependencies are more consistent. \edef\contextformat {\jobname} -\edef\contextversion{2013.03.05 16:40} +\edef\contextversion{2013.03.05 19:10} %D For those who want to use this: diff --git a/tex/context/base/status-files.pdf b/tex/context/base/status-files.pdf index 3bd3b5a33..af6e79ce9 100644 Binary files a/tex/context/base/status-files.pdf and b/tex/context/base/status-files.pdf differ diff --git a/tex/context/base/status-lua.pdf b/tex/context/base/status-lua.pdf index bd56f837b..f6e8fb0a8 100644 Binary files a/tex/context/base/status-lua.pdf and b/tex/context/base/status-lua.pdf differ diff --git a/tex/context/base/util-ran.lua b/tex/context/base/util-ran.lua new file mode 100644 index 000000000..50d0a7082 --- /dev/null +++ b/tex/context/base/util-ran.lua @@ -0,0 +1,107 @@ +if not modules then modules = { } end modules ['util-ran'] = { + version = 1.001, + comment = "companion to luat-lib.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +local random = math.random +local concat = table.concat +local sub, upper = string.sub, string.upper + +local randomizers = utilities.randomizers or { } +utilities.randomizers = randomizers + +local l_one = "bcdfghjklmnpqrstvwxz" +local l_two = "aeiouy" + +local u_one = upper(l_one) +local u_two = upper(l_two) + +local n_one = #l_one +local n_two = #l_two + +function randomizers.word(min,max,separator) + local t = { } + for i=1,random(min,max) do + if i % 2 == 0 then + local r = random(1,n_one) + t[i] = sub(l_one,r,r) + else + local r = random(1,n_two) + t[i] = sub(l_two,r,r) + end + end + return concat(t,separator) +end + +function randomizers.initials(min,max) + if not min then + if not max then + min, max = 1, 3 + else + min, max = 1, min + end + elseif not max then + max = min + end + local t = { } + local n = random(min or 1,max or 3) + local m = 0 + for i=1,n do + m = m + 1 + if i % 2 == 0 then + local r = random(1,n_one) + t[m] = sub(u_one,r,r) + else + local r = random(1,n_two) + t[m] = sub(u_two,r,r) + end + m = m + 1 + t[m] = "." + end + return concat(t) +end + +function randomizers.firstname(min,max) + if not min then + if not max then + min, max = 3, 10 + else + min, max = 1, min + end + elseif not max then + max = min + end + local t = { } + local n = random(min,max) + local b = true + if n % 2 == 0 then + local r = random(1,n_two) + t[1] = sub(u_two,r,r) + b = true + else + local r = random(1,n_one) + t[1] = sub(u_one,r,r) + b = false + end + for i=2,n do + if b then + local r = random(1,n_one) + t[i] = sub(l_one,r,r) + b = false + else + local r = random(1,n_two) + t[i] = sub(l_two,r,r) + b = true + end + end + return concat(t,separator) +end + +randomizers.surname = randomizers.firstname + +-- for i=1,10 do +-- print(randomizers.initials(1,3),randomizers.firstname(5,10),randomizers.surname(5,15)) +-- end diff --git a/tex/context/base/util-tpl.lua b/tex/context/base/util-tpl.lua index 31b2ae1f1..304c9c739 100644 --- a/tex/context/base/util-tpl.lua +++ b/tex/context/base/util-tpl.lua @@ -17,14 +17,14 @@ local trace_template = false trackers.register("templates.trace",function(v) t local report_template = logs.reporter("template") local tostring = tostring -local format = string.format +local format, sub = string.format, string.sub local P, C, Cs, Carg, lpegmatch = lpeg.P, lpeg.C, lpeg.Cs, lpeg.Carg, lpeg.match -- todo: make installable template.new local replacer -local function replacekey(k,t,recursive) +local function replacekey(k,t,how,recursive) local v = t[k] if not v then if trace_template then @@ -37,7 +37,7 @@ local function replacekey(k,t,recursive) report_template("setting key %q to value %q",k,v) end if recursive then - return lpegmatch(replacer,v,1,t) + return lpegmatch(replacer,v,1,t,how,recursive) else return v end @@ -52,38 +52,87 @@ local sqlescape = lpeg.replacer { -- { "\t", "\\t" }, } +local sqlquotedescape = lpeg.Cs(lpeg.Cc("'") * sqlescape * lpeg.Cc("'")) + +-- escapeset : \0\1\2\3\4\5\6\7\8\9\10\11\12\13\14\15\16\17\18\19\20\21\22\23\24\25\26\27\28\29\30\31\"\\\127 +-- test string: [[1\0\31test23"\\]] .. string.char(19) .. "23" +-- +-- slow: +-- +-- local luaescape = lpeg.replacer { +-- { '"', [[\"]] }, +-- { '\\', [[\\]] }, +-- { R("\0\9") * #R("09"), function(s) return "\\00" .. byte(s) end }, +-- { R("\10\31") * #R("09"), function(s) return "\\0" .. byte(s) end }, +-- { R("\0\31") , function(s) return "\\" .. byte(s) end }, +-- } +-- +-- slightly faster: +-- +-- local luaescape = Cs (( +-- P('"' ) / [[\"]] + +-- P('\\') / [[\\]] + +-- Cc("\\00") * (R("\0\9") / byte) * #R("09") + +-- Cc("\\0") * (R("\10\31") / byte) * #R("09") + +-- Cc("\\") * (R("\0\31") / byte) + +-- P(1) +-- )^0) + local escapers = { lua = function(s) - return format("%q",s) + return sub(format("%q",s),2,-2) end, sql = function(s) return lpegmatch(sqlescape,s) end, } +local quotedescapers = { + lua = function(s) + return format("%q",s) + end, + sql = function(s) + return lpegmatch(sqlquotedescape,s) + end, +} + lpeg.patterns.sqlescape = sqlescape +lpeg.patterns.sqlescape = sqlquotedescape + +local luaescaper = escapers.lua +local quotedluaescaper = quotedescapers.lua local function replacekeyunquoted(s,t,how,recurse) -- ".. \" " - local escaper = how and escapers[how] or escapers.lua - return escaper(replacekey(s,t,recurse)) + local escaper = how and escapers[how] or luaescaper + return escaper(replacekey(s,t,how,recurse)) end -local single = P("%") -- test %test% test : resolves test -local double = P("%%") -- test 10%% test : %% becomes % -local lquoted = P("%[") -- test %[test]" test : resolves test with escaped "'s -local rquoted = P("]%") -- - -local escape = double / '%%' -local nosingle = single / '' -local nodouble = double / '' -local nolquoted = lquoted / '' -local norquoted = rquoted / '' +local function replacekeyquoted(s,t,how,recurse) -- ".. \" " + local escaper = how and quotedescapers[how] or quotedluaescaper + return escaper(replacekey(s,t,how,recurse)) +end -local key = nosingle * (C((1-nosingle)^1 * Carg(1) * Carg(2) * Carg(3))/replacekey) * nosingle -local unquoted = nolquoted * ((C((1 - norquoted)^1) * Carg(1) * Carg(2) * Carg(3))/replacekeyunquoted) * norquoted +local single = P("%") -- test %test% test : resolves test +local double = P("%%") -- test 10%% test : %% becomes % +local lquoted = P("%[") -- test '%[test]%' test : resolves to test with escaped "'s +local rquoted = P("]%") -- +local lquotedq = P("%(") -- test %(test)% test : resolves to 'test' with escaped "'s +local rquotedq = P(")%") -- + +local escape = double / '%%' +local nosingle = single / '' +local nodouble = double / '' +local nolquoted = lquoted / '' +local norquoted = rquoted / '' +local nolquotedq = lquotedq / '' +local norquotedq = rquotedq / '' + +local key = nosingle * ((C((1-nosingle )^1) * Carg(1) * Carg(2) * Carg(3)) / replacekey ) * nosingle +local quoted = nolquotedq * ((C((1-norquotedq)^1) * Carg(1) * Carg(2) * Carg(3)) / replacekeyquoted ) * norquotedq +local unquoted = nolquoted * ((C((1-norquoted )^1) * Carg(1) * Carg(2) * Carg(3)) / replacekeyunquoted) * norquoted local any = P(1) - replacer = Cs((unquoted + escape + key + any)^0) + replacer = Cs((unquoted + quoted + escape + key + any)^0) local function replace(str,mapping,how,recurse) if mapping and str then @@ -95,7 +144,10 @@ end -- print(replace("test '%[x]%' test",{ x = [[a 'x'  a]] })) -- print(replace("test '%[x]%' test",{ x = true })) --- print(replace("test '%[x]%' test",{ x = [[a 'x'  a]] },'sql')) +-- print(replace("test '%[x]%' test",{ x = [[a 'x'  a]], y = "oeps" },'sql')) +-- print(replace("test '%[x]%' test",{ x = [[a '%y%'  a]], y = "oeps" },'sql',true)) +-- print(replace([[test %[x]% test]],{ x = [[a "x"  a]]})) +-- print(replace([[test %(x)% test]],{ x = [[a "x"  a]]})) templates.replace = replace diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index 9b7689ac1..9dd1797e9 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 : 03/05/13 16:40:59 +-- merge date : 03/05/13 19:10:20 do -- begin closure to overcome local limits and interference -- cgit v1.2.3