summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/syst-aux.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/syst-aux.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/syst-aux.lua40
1 files changed, 38 insertions, 2 deletions
diff --git a/Master/texmf-dist/tex/context/base/syst-aux.lua b/Master/texmf-dist/tex/context/base/syst-aux.lua
index b0fb8483b35..de15428f966 100644
--- a/Master/texmf-dist/tex/context/base/syst-aux.lua
+++ b/Master/texmf-dist/tex/context/base/syst-aux.lua
@@ -16,7 +16,8 @@ local commands, context = commands, context
local settings_to_array = utilities.parsers.settings_to_array
local format = string.format
local utfsub = utf.sub
-local P, C, Carg, lpegmatch, utf8char = lpeg.P, lpeg.C, lpeg.Carg, lpeg.match, lpeg.patterns.utf8char
+local P, S, C, Cc, Cs, Carg, lpegmatch, utf8char = lpeg.P, lpeg.S, lpeg.C, lpeg.Cc, lpeg.Cs, lpeg.Carg, lpeg.match, lpeg.patterns.utf8char
+
local setvalue = context.setvalue
@@ -28,6 +29,15 @@ function commands.getfirstcharacter(str)
setvalue("remainingcharacters",rest)
end
+function commands.thefirstcharacter(str)
+ local first, rest = lpegmatch(pattern,str)
+ context(first)
+end
+function commands.theremainingcharacters(str)
+ local first, rest = lpegmatch(pattern,str)
+ context(rest)
+end
+
local pattern = C(utf8char^-1)
function commands.doiffirstcharelse(chr,str)
@@ -68,7 +78,7 @@ end
-- end
-- end
-local pattern = (C((1-P("%"))^1) * Carg(1)) /function(n,d) return format("%.0fsp",d * tonumber(n)/100) end * P("%") * P(-1)
+local pattern = (C((1-P("%"))^1) * Carg(1)) /function(n,d) return format("%.0fsp",d * tonumber(n)/100) end * P("%") * P(-1) -- .0 ?
-- commands.percentageof("10%",65536*10)
@@ -78,3 +88,29 @@ end
-- \gdef\setpercentdimen#1#2%
-- {#1=\ctxcommand{percentageof("#2",\number#1)}\relax}
+
+local spaces = P(" ")^0/""
+
+local pattern = Cs(
+ ( P("global") / "\\global" )^0
+ * spaces
+ * ( P("unexpanded") / "\\unexpanded" )^0
+ * spaces
+ * Cc("\\expandafter\\")
+ * spaces
+ * ( P("expanded") / "e" )^0
+ * spaces
+ * ( P((1-S(" #"))^1) / "def\\csname %0\\endcsname" )
+ * spaces
+ * Cs( (P("##")/"#" + P(1))^0 )
+)
+
+function commands.thetexdefinition(str)
+ context(lpegmatch(pattern,str))
+end
+
+local upper, lower, strip = utf.upper, utf.lower, string.strip
+
+function commands.upper(s) context(upper(s)) end
+function commands.lower(s) context(lower(s)) end
+function commands.strip(s) context(strip(s)) end