diff options
author | Hans Hagen <pragma@wxs.nl> | 2012-09-06 23:03:00 +0200 |
---|---|---|
committer | Hans Hagen <pragma@wxs.nl> | 2012-09-06 23:03:00 +0200 |
commit | 3e104e2078f619b5f73eb5983f2308a672c18c5f (patch) | |
tree | c75d1a7a400d0e687d6a1ea95b89ee55cc25e11a /scripts | |
parent | 425cbd3c69a5e8fc3ded0a48749205ba52641eb4 (diff) | |
download | context-3e104e2078f619b5f73eb5983f2308a672c18c5f.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 | ||||
-rwxr-xr-x | 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 100755 --- 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) |