summaryrefslogtreecommitdiff
path: root/scripts/context/stubs
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2012-09-07 00:20:22 +0300
committerMarius <mariausol@gmail.com>2012-09-07 00:20:22 +0300
commit5b4c6dd791dfcb02838191ccee764cbb215b7cc4 (patch)
treebfd6e20699fd7d82734057723f2e765ce0d74da5 /scripts/context/stubs
parentedd2b22c9d92fd77d47b5fb6517a230470ec7038 (diff)
downloadcontext-5b4c6dd791dfcb02838191ccee764cbb215b7cc4.tar.gz
beta 2012.09.06 23:03
Diffstat (limited to 'scripts/context/stubs')
-rw-r--r--scripts/context/stubs/mswin/mtxrun.lua26
-rw-r--r--scripts/context/stubs/unix/mtxrun26
2 files changed, 42 insertions, 10 deletions
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)