diff options
author | Marius <mariausol@gmail.com> | 2012-09-07 00:20:22 +0300 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2012-09-07 00:20:22 +0300 |
commit | 5b4c6dd791dfcb02838191ccee764cbb215b7cc4 (patch) | |
tree | bfd6e20699fd7d82734057723f2e765ce0d74da5 /scripts | |
parent | edd2b22c9d92fd77d47b5fb6517a230470ec7038 (diff) | |
download | context-5b4c6dd791dfcb02838191ccee764cbb215b7cc4.tar.gz |
beta 2012.09.06 23:03
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/context/lua/mtxrun.lua | 26 | ||||
-rw-r--r-- | scripts/context/stubs/mswin/mtxrun.lua | 26 | ||||
-rw-r--r-- | scripts/context/stubs/unix/mtxrun | 26 |
3 files changed, 63 insertions, 15 deletions
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("<!-- ") / "" ----- rightmarker = 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("<!-- ") / "" ----- rightmarker = 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("<!-- ") / "" ----- rightmarker = 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) |