summaryrefslogtreecommitdiff
path: root/tex/context/base/luat-mac.lua
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2012-10-19 01:21:22 +0300
committerMarius <mariausol@gmail.com>2012-10-19 01:21:22 +0300
commitc36e19abdfd15bf6cae6fa379c6ce51f3ef5332d (patch)
tree385d8e72bcaf31513b9ae46ec947818648187082 /tex/context/base/luat-mac.lua
parent69d2352af4b60929b37fc49f3bdb263977016244 (diff)
downloadcontext-c36e19abdfd15bf6cae6fa379c6ce51f3ef5332d.tar.gz
beta 2012.10.19 00:06
Diffstat (limited to 'tex/context/base/luat-mac.lua')
-rw-r--r--tex/context/base/luat-mac.lua92
1 files changed, 82 insertions, 10 deletions
diff --git a/tex/context/base/luat-mac.lua b/tex/context/base/luat-mac.lua
index f8f87a25a..199332bba 100644
--- a/tex/context/base/luat-mac.lua
+++ b/tex/context/base/luat-mac.lua
@@ -20,6 +20,8 @@ local lpegmatch, patterns = lpeg.match, lpeg.patterns
local insert, remove = table.insert, table.remove
local rep, sub = string.rep, string.sub
local setmetatable = setmetatable
+local filesuffix = file.suffix
+local convertlmxstring = lmx.convertstring
local pushtarget, poptarget = logs.pushtarget, logs.poptarget
@@ -199,18 +201,91 @@ function macros.version(data)
return lpegmatch(checker,data)
end
+-- function macros.processmkvi(str,filename)
+-- if filename and filesuffix(filename) == "mkvi" or lpegmatch(checker,str) == "mkvi" then
+-- local oldsize = #str
+-- str = lpegmatch(parser,str,1,true) or str
+-- pushtarget("log")
+-- report_macros("processed mkvi file %q, delta %s",filename,oldsize-#str)
+-- poptarget("log")
+-- end
+-- return str
+-- end
+--
+-- utilities.sequencers.appendaction(resolvers.openers.helpers.textfileactions,"system","resolvers.macros.processmkvi")
+
+-- the document variables hack is temporary
+
+local processors = { }
+
+function processors.mkvi(str,filename)
+ local oldsize = #str
+ str = lpegmatch(parser,str,1,true) or str
+ pushtarget("log")
+ report_macros("processed mkvi file %q, delta %s",filename,oldsize-#str)
+ poptarget("log")
+ return str
+end
+
+function processors.mkix(str,filename) -- we could intercept earlier so that caching works better
+ if not document then -- because now we hash the string as well as the
+ document = { }
+ end
+ if not document.variables then
+ document.variables = { }
+ end
+ local oldsize = #str
+ str = convertlmxstring(str,document.variables,false) or str
+ pushtarget("log")
+ report_macros("processed mkix file %q, delta %s",filename,oldsize-#str)
+ poptarget("log")
+ return str
+end
+
+function processors.mkxi(str,filename)
+ if not document then
+ document = { }
+ end
+ if not document.variables then
+ document.variables = { }
+ end
+ local oldsize = #str
+ str = convertlmxstring(str,document.variables,false) or str
+ str = lpegmatch(parser,str,1,true) or str
+ pushtarget("log")
+ report_macros("processed mkxi file %q, delta %s",filename,oldsize-#str)
+ poptarget("log")
+ return str
+end
+
+function macros.processmk(str,filename)
+ if filename then
+ local suffix = filesuffix(filename)
+ local processor = processors[suffix] or processors[lpegmatch(checker,str)]
+ if processor then
+ str = processor(str,filename)
+ end
+ end
+ return str
+end
+
+utilities.sequencers.appendaction(resolvers.openers.helpers.textfileactions,"system","resolvers.macros.processmk")
+
function macros.processmkvi(str,filename)
- if (filename and file.suffix(filename) == "mkvi") or lpegmatch(checker,str) == "mkvi" then
- local result = lpegmatch(parser,str,1,true) or str
+ if filename and filesuffix(filename) == "mkvi" or lpegmatch(checker,str) == "mkvi" then
+ local oldsize = #str
+ str = lpegmatch(parser,str,1,true) or str
pushtarget("log")
- report_macros("processed file '%s', delta %s",filename,#str-#result)
+ report_macros("processed mkvi file %q, delta %s",filename,oldsize-#str)
poptarget("log")
- return result
- else
- return str
end
+ return str
end
+utilities.sequencers.appendaction(resolvers.openers.helpers.textfileactions,"system","resolvers.macros.processmkvi")
+
+-- bonus
+
if resolvers.schemes then
local function handler(protocol,name,cachename)
@@ -218,7 +293,7 @@ if resolvers.schemes then
local path = hashed.path
if path and path ~= "" then
local str = resolvers.loadtexfile(path)
- if file.suffix(path) == "mkvi" or lpegmatch(checker,str) == "mkvi" then
+ if filesuffix(path) == "mkvi" or lpegmatch(checker,str) == "mkvi" then
-- already done automatically
io.savedata(cachename,str)
else
@@ -234,9 +309,6 @@ if resolvers.schemes then
resolvers.schemes.install('mkvi',handler,1) -- this will cache !
- utilities.sequencers.appendaction(resolvers.openers.helpers.textfileactions,"system","resolvers.macros.processmkvi")
- -- utilities.sequencers.disableaction(resolvers.openers.helpers.textfileactions,"resolvers.macros.processmkvi")
-
end
-- print(macros.preprocessed(