diff options
Diffstat (limited to 'tex/context/base/syst-lua.lua')
-rw-r--r-- | tex/context/base/syst-lua.lua | 52 |
1 files changed, 16 insertions, 36 deletions
diff --git a/tex/context/base/syst-lua.lua b/tex/context/base/syst-lua.lua index ef524c339..f735b1962 100644 --- a/tex/context/base/syst-lua.lua +++ b/tex/context/base/syst-lua.lua @@ -16,17 +16,14 @@ commands = commands or { } function commands.writestatus(...) logs.status(...) end -- overloaded later +-- todo: use shorter names i.e. less tokenization, like prtcatcodes + f_o_t_a + local firstoftwoarguments = context.firstoftwoarguments -- context.constructcsonly("firstoftwoarguments" ) local secondoftwoarguments = context.secondoftwoarguments -- context.constructcsonly("secondoftwoarguments") local firstofoneargument = context.firstofoneargument -- context.constructcsonly("firstofoneargument" ) local gobbleoneargument = context.gobbleoneargument -- context.constructcsonly("gobbleoneargument" ) --- contextsprint(prtcatcodes,[[\ui_fo]]) -- firstofonearguments --- contextsprint(prtcatcodes,[[\ui_go]]) -- gobbleonearguments --- contextsprint(prtcatcodes,[[\ui_ft]]) -- firstoftwoarguments --- contextsprint(prtcatcodes,[[\ui_st]]) -- secondoftwoarguments - -function commands.doifelse(b) +local function testcase(b) if b then firstoftwoarguments() else @@ -50,45 +47,33 @@ function commands.doifnot(b) end end -commands.testcase = commands.doifelse -- obsolete +commands.testcase = testcase +commands.doifelse = testcase function commands.boolcase(b) context(b and 1 or 0) end function commands.doifelsespaces(str) - if find(str,"^ +$") then - firstoftwoarguments() - else - secondoftwoarguments() - end + return testcase(find(str,"^ +$")) end local s = lpegtsplitat(",") local h = { } -function commands.doifcommonelse(a,b) -- often the same test +function commands.doifcommonelse(a,b) local ha = h[a] local hb = h[b] - if not ha then - ha = lpegmatch(s,a) - h[a] = ha - end - if not hb then - hb = lpegmatch(s,b) - h[b] = hb - end - local na = #ha - local nb = #hb - for i=1,na do - for j=1,nb do + if not ha then ha = lpegmatch(s,a) h[a] = ha end + if not hb then hb = lpegmatch(s,b) h[b] = hb end + for i=1,#ha do + for j=1,#hb do if ha[i] == hb[j] then - firstoftwoarguments() - return + return testcase(true) end end end - secondoftwoarguments() + return testcase(false) end function commands.doifinsetelse(a,b) @@ -96,21 +81,16 @@ function commands.doifinsetelse(a,b) if not hb then hb = lpegmatch(s,b) h[b] = hb end for i=1,#hb do if a == hb[i] then - firstoftwoarguments() - return + return testcase(true) end end - secondoftwoarguments() + return testcase(false) end local pattern = lpeg.patterns.validdimen function commands.doifdimenstringelse(str) - if lpegmatch(pattern,str) then - firstoftwoarguments() - else - secondoftwoarguments() - end + testcase(lpegmatch(pattern,str)) end function commands.firstinset(str) |