From 5b4c6dd791dfcb02838191ccee764cbb215b7cc4 Mon Sep 17 00:00:00 2001 From: Marius Date: Fri, 7 Sep 2012 00:20:22 +0300 Subject: beta 2012.09.06 23:03 --- scripts/context/lua/mtxrun.lua | 26 ++++++++++--- scripts/context/stubs/mswin/mtxrun.lua | 26 ++++++++++--- scripts/context/stubs/unix/mtxrun | 26 ++++++++++--- tex/context/base/colo-ini.lua | 9 +++-- tex/context/base/cont-new.mkii | 2 +- tex/context/base/cont-new.mkiv | 2 +- tex/context/base/cont-yes.mkiv | 7 +--- tex/context/base/context-version.pdf | Bin 0 -> 4143 bytes tex/context/base/context-version.png | Bin 106798 -> 105007 bytes tex/context/base/context.mkii | 2 +- tex/context/base/context.mkiv | 2 +- tex/context/base/core-sys.lua | 42 +++++++++++---------- tex/context/base/core-sys.mkiv | 13 ++++--- tex/context/base/l-lpeg.lua | 4 ++ tex/context/base/page-mix.lua | 9 +++-- tex/context/base/phys-dim.lua | 10 ++--- tex/context/base/s-inf-03.mkiv | 10 ++--- tex/context/base/status-files.pdf | Bin 24596 -> 24587 bytes tex/context/base/status-lua.pdf | Bin 6242 -> 194861 bytes tex/context/base/status-mkiv.tex | 1 + tex/context/base/strc-doc.lua | 2 +- tex/context/base/util-sql.lua | 25 +++++++----- tex/context/base/util-tpl.lua | 22 ++++++++--- tex/generic/context/luatex/luatex-fonts-merged.lua | 6 ++- 24 files changed, 159 insertions(+), 87 deletions(-) create mode 100644 tex/context/base/context-version.pdf diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index 40fe71c0e..a299e3a2b 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -1312,6 +1312,10 @@ patterns.undouble = (dquote/"") * patterns.nodquote * (dquote/"") patterns.unquoted = patterns.undouble + patterns.unsingle -- more often undouble patterns.unspacer = ((patterns.spacer^1)/"")^0 +patterns.singlequoted = squote * patterns.nosquote * squote +patterns.doublequoted = dquote * patterns.nodquote * dquote +patterns.quoted = patterns.doublequoted + patterns.singlequoted + patterns.somecontent = (anything - newline - space)^1 -- (utf8char - newline - space)^1 patterns.beginline = #(1-newline) @@ -16439,6 +16443,7 @@ local templates = utilities.templates local trace_template = false trackers.register("templates.trace",function(v) trace_template = v end) local report_template = logs.reporter("template") +local format = string.format local P, C, Cs, Carg, lpegmatch = lpeg.P, lpeg.C, lpeg.Cs, lpeg.Carg, lpeg.match local replacer @@ -16462,13 +16467,22 @@ end ----- leftmarker = P("") / "" -local escape = P("%%") / "%%" -local leftmarker = P("%") / "" -local rightmarker = P("%") / "" +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 key = leftmarker * (C((1-rightmarker)^1 * Carg(1))/replacekey) * rightmarker +local key = nosingle * (C((1-nosingle)^1 * Carg(1))/replacekey) * nosingle +local unquoted = nolquoted * ((C((1 - norquoted)^1) * Carg(1))/function(s,t) return format("%q",replacekey(s,t)) end) * norquoted local any = P(1) - replacer = Cs((escape + key + any)^0) + + replacer = Cs((unquoted + escape + key + any)^0) local function replace(str,mapping) if mapping then @@ -16478,6 +16492,8 @@ local function replace(str,mapping) end end +-- print(replace("test %[x]% test",{ x = [[a "x" a]] })) + templates.replace = replace function templates.load(filename,mapping) diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index 40fe71c0e..a299e3a2b 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -1312,6 +1312,10 @@ patterns.undouble = (dquote/"") * patterns.nodquote * (dquote/"") patterns.unquoted = patterns.undouble + patterns.unsingle -- more often undouble patterns.unspacer = ((patterns.spacer^1)/"")^0 +patterns.singlequoted = squote * patterns.nosquote * squote +patterns.doublequoted = dquote * patterns.nodquote * dquote +patterns.quoted = patterns.doublequoted + patterns.singlequoted + patterns.somecontent = (anything - newline - space)^1 -- (utf8char - newline - space)^1 patterns.beginline = #(1-newline) @@ -16439,6 +16443,7 @@ local templates = utilities.templates local trace_template = false trackers.register("templates.trace",function(v) trace_template = v end) local report_template = logs.reporter("template") +local format = string.format local P, C, Cs, Carg, lpegmatch = lpeg.P, lpeg.C, lpeg.Cs, lpeg.Carg, lpeg.match local replacer @@ -16462,13 +16467,22 @@ end ----- leftmarker = P("") / "" -local escape = P("%%") / "%%" -local leftmarker = P("%") / "" -local rightmarker = P("%") / "" +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 key = leftmarker * (C((1-rightmarker)^1 * Carg(1))/replacekey) * rightmarker +local key = nosingle * (C((1-nosingle)^1 * Carg(1))/replacekey) * nosingle +local unquoted = nolquoted * ((C((1 - norquoted)^1) * Carg(1))/function(s,t) return format("%q",replacekey(s,t)) end) * norquoted local any = P(1) - replacer = Cs((escape + key + any)^0) + + replacer = Cs((unquoted + escape + key + any)^0) local function replace(str,mapping) if mapping then @@ -16478,6 +16492,8 @@ local function replace(str,mapping) end end +-- print(replace("test %[x]% test",{ x = [[a "x" a]] })) + templates.replace = replace function templates.load(filename,mapping) diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index 40fe71c0e..a299e3a2b 100644 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -1312,6 +1312,10 @@ patterns.undouble = (dquote/"") * patterns.nodquote * (dquote/"") patterns.unquoted = patterns.undouble + patterns.unsingle -- more often undouble patterns.unspacer = ((patterns.spacer^1)/"")^0 +patterns.singlequoted = squote * patterns.nosquote * squote +patterns.doublequoted = dquote * patterns.nodquote * dquote +patterns.quoted = patterns.doublequoted + patterns.singlequoted + patterns.somecontent = (anything - newline - space)^1 -- (utf8char - newline - space)^1 patterns.beginline = #(1-newline) @@ -16439,6 +16443,7 @@ local templates = utilities.templates local trace_template = false trackers.register("templates.trace",function(v) trace_template = v end) local report_template = logs.reporter("template") +local format = string.format local P, C, Cs, Carg, lpegmatch = lpeg.P, lpeg.C, lpeg.Cs, lpeg.Carg, lpeg.match local replacer @@ -16462,13 +16467,22 @@ end ----- leftmarker = P("") / "" -local escape = P("%%") / "%%" -local leftmarker = P("%") / "" -local rightmarker = P("%") / "" +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 key = leftmarker * (C((1-rightmarker)^1 * Carg(1))/replacekey) * rightmarker +local key = nosingle * (C((1-nosingle)^1 * Carg(1))/replacekey) * nosingle +local unquoted = nolquoted * ((C((1 - norquoted)^1) * Carg(1))/function(s,t) return format("%q",replacekey(s,t)) end) * norquoted local any = P(1) - replacer = Cs((escape + key + any)^0) + + replacer = Cs((unquoted + escape + key + any)^0) local function replace(str,mapping) if mapping then @@ -16478,6 +16492,8 @@ local function replace(str,mapping) end end +-- print(replace("test %[x]% test",{ x = [[a "x" a]] })) + templates.replace = replace function templates.load(filename,mapping) diff --git a/tex/context/base/colo-ini.lua b/tex/context/base/colo-ini.lua index f2437cd9d..e08f3d387 100644 --- a/tex/context/base/colo-ini.lua +++ b/tex/context/base/colo-ini.lua @@ -848,14 +848,15 @@ end -- handy -local models = storage.allocate { "gray", "rgb", "cmyk", "spot" } +local models = storage.allocate { "all", "gray", "rgb", "cmyk", "spot" } colors.models = models -- check for usage elsewhere -function attributes.colors.spec(name) - local t = colorvalues[attributes_list[name]] or colorvalues[attributes_list.black] +function colors.spec(name) + local l = attributes_list[a_color] + local t = colorvalues[l[name]] or colorvalues[l.black] return { - model = models[t[1]], + model = models[t[1]] or models[1], s = t[2], r = t[3], g = t[4], b = t[5], c = t[6], m = t[7], y = t[8], k = t[9], diff --git a/tex/context/base/cont-new.mkii b/tex/context/base/cont-new.mkii index 8fbb41f87..386f7e557 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{2012.09.04 18:08} +\newcontextversion{2012.09.06 23:03} %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 13e895931..3b53d7d5d 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{2012.09.04 18:08} +\newcontextversion{2012.09.06 23:03} %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/cont-yes.mkiv b/tex/context/base/cont-yes.mkiv index ba6dc166d..fe6a412ee 100644 --- a/tex/context/base/cont-yes.mkiv +++ b/tex/context/base/cont-yes.mkiv @@ -27,17 +27,12 @@ local input = arguments.input or fulljobname local result = arguments.result or file.removesuffix(jobname) - local input = file.suffix(input) == "tex" and file.removesuffix(input) or input - local filename = fulljobname local suffix = file.suffix(filename) local filename = ctxrunner.resolve(filename) -- in case we're prepped - commands.updatefilenames(jobname,input,result) -- job input output - --- texio.write_nl(string.format("{jobname: %s, input: %s, result: %s}",jobname,input,result)) - commands.writestatus("files",string.format("jobname: %s, input: %s, result: %s",jobname,input,result)) + commands.updatefilenames(jobname,fulljobname,input,result) if suffix == "xml" or arguments.forcexml then diff --git a/tex/context/base/context-version.pdf b/tex/context/base/context-version.pdf new file mode 100644 index 000000000..5642abc09 Binary files /dev/null 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 0933c9744..648fc8263 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 efb1028ec..8b40e2a7c 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{2012.09.04 18:08} +\edef\contextversion{2012.09.06 23:03} %D For those who want to use this: diff --git a/tex/context/base/context.mkiv b/tex/context/base/context.mkiv index 3905a49c6..5c81ac2e7 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{2012.09.04 18:08} +\edef\contextversion{2012.09.06 23:03} %D For those who want to use this: diff --git a/tex/context/base/core-sys.lua b/tex/context/base/core-sys.lua index 8e4286cae..cf027e1c6 100644 --- a/tex/context/base/core-sys.lua +++ b/tex/context/base/core-sys.lua @@ -6,33 +6,35 @@ if not modules then modules = { } end modules ['core-sys'] = { license = "see context related readme files" } -local lower, format = string.lower, string.format +local lower, format, gsub = string.lower, string.format, string.gsub local suffix, basename, removesuffix = file.suffix, file.basename, file.removesuffix local environment = environment --- function commands.updatefilenames(inputfilename,outputfilename) --- -- --- environment.jobfilename = inputfilename or tex.jobname or "" --- environment.jobfilesuffix = lower(suffix(environment.jobfilename)) --- -- --- environment.inputfilename = inputfilename or "" --- environment.inputfilebarename = removesuffix(basename(inputfilename)) --- environment.inputfilesuffix = lower(suffix(inputfilename)) --- -- --- environment.outputfilename = outputfilename or "" --- end - -function commands.updatefilenames(jobname,inputfilename,outputfilename) +function commands.updatefilenames(jobname,fulljobname,inputfilename,outputfilename) + -- + environment.jobname = jobname + -- + local jobfilename = gsub(fulljobname or jobname or inputfilename or tex.jobname or "","%./","") + -- + environment.jobfilename = jobfilename + environment.jobfilesuffix = lower(suffix(environment.jobfilename)) + -- + local inputfilename = gsub(inputfilename or "","%./","") + environment.inputfilename = inputfilename + environment.inputfilebarename = removesuffix(basename(inputfilename)) + -- + local inputfilerealsuffix = suffix(inputfilename) + environment.inputfilerealsuffix = inputfilerealsuffix -- - environment.jobfilename = jobname or inputfilename or tex.jobname or "" - environment.jobfilesuffix = lower(suffix(environment.jobfilename)) + local inputfilesuffix = inputfilerealsuffix == "" and "tex" or lower(inputfilerealsuffix) + environment.inputfilesuffix = inputfilesuffix -- - environment.inputfilename = inputfilename or "" - environment.inputfilebarename = removesuffix(basename(inputfilename)) - environment.inputfilesuffix = lower(suffix(inputfilename)) + local outputfilename = outputfilename or environment.inputfilebarename or "" + environment.outputfilename = outputfilename -- - environment.outputfilename = outputfilename or environment.inputfilebarename or "" + commands.writestatus("files",format("jobname: %q, input: %q, result: %q, suffix: %s", + jobfilename,inputfilename,outputfilename,inputfilesuffix)) end statistics.register("result saved in file", function() diff --git a/tex/context/base/core-sys.mkiv b/tex/context/base/core-sys.mkiv index 25b656341..249500e0a 100644 --- a/tex/context/base/core-sys.mkiv +++ b/tex/context/base/core-sys.mkiv @@ -40,18 +40,19 @@ %D The jobname is what gets loaded by the cont-yes stub file. This name %D also determines the name of tuc etc files. -\def \jobfilename {\cldcontext{environment.jobfilename or ""}} -\def \jobfilesuffix {\cldcontext{environment.jobfilesuffix or ""}} +\def \jobfilename {\cldcontext{environment.jobfilename or ""}} +\def \jobfilesuffix {\cldcontext{environment.jobfilesuffix or ""}} %D However, that one can itself load another file. -\def \inputfilebarename{\cldcontext{environment.inputfilebarename or ""}} -\def \inputfilesuffix {\cldcontext{environment.inputfilesuffix or ""}} -\def \inputfilename {\cldcontext{environment.inputfilename or ""}} +\def \inputfilebarename {\cldcontext{environment.inputfilebarename or ""}} +\def \inputfilerealsuffix{\cldcontext{environment.inputfilerealsuffix or ""}} +\def \inputfilesuffix {\cldcontext{environment.inputfilesuffix or ""}} +\def \inputfilename {\cldcontext{environment.inputfilename or ""}} %D The output name is only used for some checking. -\def \outputfilename {\cldcontext{environment.outputfilename or ""}} +\def \outputfilename {\cldcontext{environment.outputfilename or ""}} \installcorenamespace{system} diff --git a/tex/context/base/l-lpeg.lua b/tex/context/base/l-lpeg.lua index b00b4c3bb..d92b722ed 100644 --- a/tex/context/base/l-lpeg.lua +++ b/tex/context/base/l-lpeg.lua @@ -159,6 +159,10 @@ patterns.undouble = (dquote/"") * patterns.nodquote * (dquote/"") patterns.unquoted = patterns.undouble + patterns.unsingle -- more often undouble patterns.unspacer = ((patterns.spacer^1)/"")^0 +patterns.singlequoted = squote * patterns.nosquote * squote +patterns.doublequoted = dquote * patterns.nodquote * dquote +patterns.quoted = patterns.doublequoted + patterns.singlequoted + patterns.somecontent = (anything - newline - space)^1 -- (utf8char - newline - space)^1 patterns.beginline = #(1-newline) diff --git a/tex/context/base/page-mix.lua b/tex/context/base/page-mix.lua index 91e1f0755..be87b79a7 100644 --- a/tex/context/base/page-mix.lua +++ b/tex/context/base/page-mix.lua @@ -387,10 +387,11 @@ return false if nxt then current = nxt elseif head == lasthead then --- if trace_state then --- report_state("quit as head is lasthead") --- end --- break + -- to be checked but break needed as otherwise we have a loop + if trace_state then + report_state("quit as head is lasthead") + end + break else local r = results[column] r.head = head diff --git a/tex/context/base/phys-dim.lua b/tex/context/base/phys-dim.lua index c47821b1c..62a710dd3 100644 --- a/tex/context/base/phys-dim.lua +++ b/tex/context/base/phys-dim.lua @@ -482,7 +482,7 @@ local unitsNspace = context.unitsNspace local labels = languages.data.labels -labels.prefixes = { +labels.prefixes = allocate { yocto = { labels = { en = [[y]] } }, -- 10^{-24} zepto = { labels = { en = [[z]] } }, -- 10^{-21} atto = { labels = { en = [[a]] } }, -- 10^{-18} @@ -515,7 +515,7 @@ labels.prefixes = { root = { labels = { en = [[√]] } }, -- 0x221A } -labels.units = { +labels.units = allocate { meter = { labels = { en = [[m]] } }, gram = { labels = { en = [[g]] } }, -- strictly kg is the base unit second = { labels = { en = [[s]] } }, @@ -597,14 +597,14 @@ labels.units = { micron = { labels = { en = [[\textmu m]] } }, } -labels.operators = { +labels.operators = allocate { times = { labels = { en = [[\unitsTIMES]] } }, solidus = { labels = { en = [[\unitsSOLIDUS]] } }, per = { labels = { en = [[\unitsSOLIDUS]] } }, outof = { labels = { en = [[\unitsOUTOF]] } }, } -labels.suffixes = { +labels.suffixes = allocate { linear = { labels = { en = [[1]] } }, square = { labels = { en = [[2]] } }, cubic = { labels = { en = [[3]] } }, @@ -849,7 +849,7 @@ local t_shortcuts = { suffixes = setmetatablenewindex(short_suffixes,trigger), } -physics.units.tables = { +physics.units.tables = allocate { units = t_units, shortcuts = t_shortcuts, } diff --git a/tex/context/base/s-inf-03.mkiv b/tex/context/base/s-inf-03.mkiv index bd4ec5dbc..e2428ce5e 100644 --- a/tex/context/base/s-inf-03.mkiv +++ b/tex/context/base/s-inf-03.mkiv @@ -1,10 +1,8 @@ % \nopdfcompression -\starttext - -There is a loop somewhere ... todo. - -\stoptext +% \starttext +% There is a loop somewhere ... todo. +% \stoptext \enablemode[ipad] % whatever that means @@ -215,7 +213,6 @@ local function childtables(key,tab,handler,depth) else handler(s,t,depth) if variant == 3 then -print("UNMARKED",k) childtables(false,v,handler,depth+1) elseif variant == 2 then childtables(k,v,handler,depth+1) @@ -325,7 +322,6 @@ local function show(title,subtitle,alias,builtin,t,lib,libcolor,glo,glocolor,mar end NC() NR() if mark and t == "table" and title ~= "libraries" and title ~= "package" and not marked then -print(title,subtitle,k) childtables(false,v,handler) -- (k,v,handler) end end diff --git a/tex/context/base/status-files.pdf b/tex/context/base/status-files.pdf index 0b2b9db93..ca09992dd 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 7afcfb69b..8aa2791d6 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/status-mkiv.tex b/tex/context/base/status-mkiv.tex index 2fe00a8b9..7ca394a19 100644 --- a/tex/context/base/status-mkiv.tex +++ b/tex/context/base/status-mkiv.tex @@ -81,6 +81,7 @@ \startitem isolate tracers and showers \stopitem \startitem check all possible usage of ctxcommand \stopitem \startitem there are more s-* modules, like s-fnt-41 \stopitem + \startitem check (un)marked tables \stopitem \stopitemize \stoptitle diff --git a/tex/context/base/strc-doc.lua b/tex/context/base/strc-doc.lua index 618be1146..98d69f4ce 100644 --- a/tex/context/base/strc-doc.lua +++ b/tex/context/base/strc-doc.lua @@ -64,7 +64,7 @@ local a_internal = attributes.private('internal') local data function documents.initialize() - data = { + data = allocate { -- whole data is marked numbers = { }, forced = { }, ownnumbers = { }, diff --git a/tex/context/base/util-sql.lua b/tex/context/base/util-sql.lua index 3daa60d0b..798ef44af 100644 --- a/tex/context/base/util-sql.lua +++ b/tex/context/base/util-sql.lua @@ -316,10 +316,15 @@ local function connect(session,specification) ) end +local whitespace = patterns.whitespace^0 +local quoted = patterns.quoted +local separator = P(";") +local query = whitespace * Cs((quoted + 1 - separator)^1 * Cc(";")) * whitespace +local splitter = Ct(query * (separator * query)^0) + local function datafetched(specification,query) local id = specification.id local session, connection --- id = nil if id then local c = cache[id] if c then @@ -338,7 +343,13 @@ local function datafetched(specification,query) if not connection then return { }, { } end - local result, message = connection:execute(query) + query = lpegmatch(splitter,query) + local result, message + for i=1,#query do + local q = query[i] + result, message = connection:execute(q) +-- io.savedata("e:/tmp/oeps.sql",q) + end if not result and id then if session then session:close() @@ -349,7 +360,9 @@ local function datafetched(specification,query) session = mysql() -- maybe not needed connection = connect(session,specification) cache[id] = { session = session, connection = connection } - result, message = connection:execute(query) + for i=1,#query do + result, message = connection:execute(query[i]) + end end local data, keys if result and type(result) ~= "number" then @@ -464,25 +477,19 @@ local u_pattern = lpeg.replacer { { '\\\\','\\' }, { "\n","\\n" } } function methods.library.serialize(t) local str = fastserialize(t,"return") local escaped = lpegmatch(e_pattern,str) --- print("LIBRARY PUT STR",str) --- print("LIBRARY PUT ESC",escaped) return escaped end function methods.library.deserialize(str) local unescaped = lpegmatch(u_pattern,str) --- print("LIBRARY GET STR",str) --- print("LIBRARY GET UES",unescaped) if not unescaped then return end local code = loadstring(unescaped) --- print("INVALID CODE") if not code then return end code = code() --- table.print(code) if not code then return end diff --git a/tex/context/base/util-tpl.lua b/tex/context/base/util-tpl.lua index f97f97d11..2a728d373 100644 --- a/tex/context/base/util-tpl.lua +++ b/tex/context/base/util-tpl.lua @@ -17,6 +17,7 @@ local templates = utilities.templates local trace_template = false trackers.register("templates.trace",function(v) trace_template = v end) local report_template = logs.reporter("template") +local format = string.format local P, C, Cs, Carg, lpegmatch = lpeg.P, lpeg.C, lpeg.Cs, lpeg.Carg, lpeg.match local replacer @@ -40,13 +41,22 @@ end ----- leftmarker = P("") / "" -local escape = P("%%") / "%%" -local leftmarker = P("%") / "" -local rightmarker = P("%") / "" +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 key = leftmarker * (C((1-rightmarker)^1 * Carg(1))/replacekey) * rightmarker +local escape = double / "%%" +local nosingle = single / "" +local nodouble = double / "" +local nolquoted = lquoted / "" +local norquoted = rquoted / "" + +local key = nosingle * (C((1-nosingle)^1 * Carg(1))/replacekey) * nosingle +local unquoted = nolquoted * ((C((1 - norquoted)^1) * Carg(1))/function(s,t) return format("%q",replacekey(s,t)) end) * norquoted local any = P(1) - replacer = Cs((escape + key + any)^0) + + replacer = Cs((unquoted + escape + key + any)^0) local function replace(str,mapping) if mapping then @@ -56,6 +66,8 @@ local function replace(str,mapping) end end +-- print(replace("test %[x]% test",{ x = [[a "x" a]] })) + templates.replace = replace function templates.load(filename,mapping) diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index 9650b1024..1140ff916 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 : 09/04/12 18:08:16 +-- merge date : 09/06/12 23:03:51 do -- begin closure to overcome local limits and interference @@ -1293,6 +1293,10 @@ patterns.undouble = (dquote/"") * patterns.nodquote * (dquote/"") patterns.unquoted = patterns.undouble + patterns.unsingle -- more often undouble patterns.unspacer = ((patterns.spacer^1)/"")^0 +patterns.singlequoted = squote * patterns.nosquote * squote +patterns.doublequoted = dquote * patterns.nodquote * dquote +patterns.quoted = patterns.doublequoted + patterns.singlequoted + patterns.somecontent = (anything - newline - space)^1 -- (utf8char - newline - space)^1 patterns.beginline = #(1-newline) -- cgit v1.2.3