summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/syst-lua.lua
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2015-04-18 22:52:45 +0000
committerKarl Berry <karl@freefriends.org>2015-04-18 22:52:45 +0000
commit16aa5a7c87f18a2483d0d61795899f886781b51c (patch)
tree1d72f00b2a4185425393598402fe055c61d1de58 /Master/texmf-dist/tex/context/base/syst-lua.lua
parente68dc4d5506d46bf72823234f902bc76d1f70352 (diff)
context, from www.pragma-ade.com/context/beta/cont-tmf.zip (18apr15)
git-svn-id: svn://tug.org/texlive/trunk@36923 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/syst-lua.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/syst-lua.lua151
1 files changed, 135 insertions, 16 deletions
diff --git a/Master/texmf-dist/tex/context/base/syst-lua.lua b/Master/texmf-dist/tex/context/base/syst-lua.lua
index cd7dcc062c5..a6665f4104a 100644
--- a/Master/texmf-dist/tex/context/base/syst-lua.lua
+++ b/Master/texmf-dist/tex/context/base/syst-lua.lua
@@ -6,16 +6,28 @@ if not modules then modules = { } end modules ['syst-lua'] = {
license = "see context related readme files"
}
-local format, find, match, rep = string.format, string.find, string.match, string.rep
+local find, match = string.find, string.match
local tonumber = tonumber
-local S, lpegmatch, lpegtsplitat = lpeg.S, lpeg.match, lpeg.tsplitat
+local S, C, P, lpegmatch, lpegtsplitat = lpeg.S, lpeg.C, lpeg.P, lpeg.match, lpeg.tsplitat
-commands = commands or { }
-local commands = commands
-local context = context
+commands = commands or { }
+local commands = commands
-function commands.writestatus(...) logs.status(...) end -- overloaded later
+local implement = interfaces.implement
+
+local two_strings = interfaces.strings[2]
+
+local context = context
+local csprint = context.sprint
+
+local prtcatcodes = tex.prtcatcodes
+
+implement { -- will b eoverloaded later
+ name = "writestatus",
+ arguments = two_strings,
+ actions = logs.status,
+}
local ctx_firstoftwoarguments = context.firstoftwoarguments -- context.constructcsonly("firstoftwoarguments" )
local ctx_secondoftwoarguments = context.secondoftwoarguments -- context.constructcsonly("secondoftwoarguments")
@@ -30,24 +42,60 @@ local ctx_gobbleoneargument = context.gobbleoneargument -- context.constru
function commands.doifelse(b)
if b then
ctx_firstoftwoarguments()
+-- csprint(prtcatcodes,[[\ui_ft]]) -- ctx_firstoftwoarguments
+ else
+ ctx_secondoftwoarguments()
+-- csprint(prtcatcodes,[[\ui_st]]) -- ctx_secondoftwoarguments
+ end
+end
+
+function commands.doifelsesomething(b)
+ if b and b ~= "" then
+ ctx_firstoftwoarguments()
+-- csprint(prtcatcodes,[[\ui_ft]]) -- ctx_firstoftwoarguments
else
ctx_secondoftwoarguments()
+-- csprint(prtcatcodes,[[\ui_st]]) -- ctx_secondoftwoarguments
end
end
function commands.doif(b)
if b then
ctx_firstofoneargument()
+-- context.__flushdirect(prtcatcodes,[[\ui_fo]]) -- ctx_firstofonearguments
+ else
+ ctx_gobbleoneargument()
+-- context.__flushdirect(prtcatcodes,[[\ui_go]]) -- ctx_gobbleonearguments
+ end
+end
+
+function commands.doifsomething(b)
+ if b and b ~= "" then
+ ctx_firstofoneargument()
+-- context.__flushdirect(prtcatcodes,[[\ui_fo]]) -- ctx_firstofonearguments
else
ctx_gobbleoneargument()
+-- context.__flushdirect(prtcatcodes,[[\ui_go]]) -- ctx_gobbleonearguments
end
end
function commands.doifnot(b)
if b then
ctx_gobbleoneargument()
+-- csprint(prtcatcodes,[[\ui_go]]) -- ctx_gobbleonearguments
+ else
+ ctx_firstofoneargument()
+-- csprint(prtcatcodes,[[\ui_fo]]) -- ctx_firstofonearguments
+ end
+end
+
+function commands.doifnotthing(b)
+ if b and b ~= "" then
+ ctx_gobbleoneargument()
+-- csprint(prtcatcodes,[[\ui_go]]) -- ctx_gobbleonearguments
else
ctx_firstofoneargument()
+-- csprint(prtcatcodes,[[\ui_fo]]) -- ctx_firstofonearguments
end
end
@@ -68,7 +116,7 @@ end
local s = lpegtsplitat(",")
local h = { }
-function commands.doifcommonelse(a,b) -- often the same test
+local function doifelsecommon(a,b) -- often the same test
local ha = h[a]
local hb = h[b]
if not ha then
@@ -92,7 +140,7 @@ function commands.doifcommonelse(a,b) -- often the same test
ctx_secondoftwoarguments()
end
-function commands.doifinsetelse(a,b)
+local function doifelseinset(a,b)
local hb = h[b]
if not hb then hb = lpegmatch(s,b) h[b] = hb end
for i=1,#hb do
@@ -104,9 +152,21 @@ function commands.doifinsetelse(a,b)
ctx_secondoftwoarguments()
end
+implement {
+ name = "doifelsecommon",
+ arguments = two_strings,
+ actions = doifelsecommon
+}
+
+implement {
+ name = "doifelseinset",
+ arguments = two_strings,
+ actions = doifelseinset
+}
+
local pattern = lpeg.patterns.validdimen
-function commands.doifdimenstringelse(str)
+function commands.doifelsedimenstring(str)
if lpegmatch(pattern,str) then
ctx_firstoftwoarguments()
else
@@ -114,11 +174,70 @@ function commands.doifdimenstringelse(str)
end
end
-function commands.firstinset(str)
- local first = match(str,"^([^,]+),")
- context(first or str)
-end
+local p_first = C((1-P(",")-P(-1))^0)
-function commands.ntimes(str,n)
- context(rep(str,n or 1))
-end
+implement {
+ name = "firstinset",
+ arguments = "string",
+ actions = function(str) context(lpegmatch(p_first,str or "")) end
+}
+
+implement {
+ name = "ntimes",
+ arguments = { "string", "integer" },
+ actions = { string.rep, context }
+}
+
+implement {
+ name = "execute",
+ arguments = "string",
+ actions = os.execute -- wrapped in sandbox
+}
+
+-- function commands.write(n,str)
+-- if n == 18 then
+-- os.execute(str)
+-- elseif n == 16 then
+-- -- immediate
+-- logs.report(str)
+-- else
+-- -- at the tex end we can still drop the write / also delayed vs immediate
+-- context.writeviatex(n,str)
+-- end
+-- end
+
+implement {
+ name = "doifelsesame",
+ arguments = two_strings,
+ actions = function(a,b)
+ if a == b then
+ ctx_firstoftwoarguments()
+ else
+ ctx_secondoftwoarguments()
+ end
+ end
+}
+
+implement {
+ name = "doifsame",
+ arguments = two_strings,
+ actions = function(a,b)
+ if a == b then
+ ctx_firstofoneargument()
+ else
+ ctx_gobbleoneargument()
+ end
+ end
+}
+
+implement {
+ name = "doifnotsame",
+ arguments = two_strings,
+ actions = function(a,b)
+ if a == b then
+ ctx_gobbleoneargument()
+ else
+ ctx_firstofoneargument()
+ end
+ end
+}