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 +++++++++++++++++++++----- 3 files changed, 63 insertions(+), 15 deletions(-) (limited to 'scripts') 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) -- cgit v1.2.3