summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-prs.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/luatex/lualibs/lualibs-util-prs.lua')
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs-util-prs.lua67
1 files changed, 46 insertions, 21 deletions
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-prs.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-prs.lua
index 6d2f8c19e06..635b610e072 100644
--- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-prs.lua
+++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-prs.lua
@@ -55,9 +55,13 @@ local nobracket = 1 - (lbracket + rbracket)
local escape, left, right = P("\\"), P('{'), P('}')
+-- lpegpatterns.balanced = P {
+-- [1] = ((escape * (left+right)) + (1 - (left+right)) + V(2))^0,
+-- [2] = left * V(1) * right
+-- }
lpegpatterns.balanced = P {
- [1] = ((escape * (left+right)) + (1 - (left+right)) + V(2))^0,
- [2] = left * V(1) * right
+ ((escape * (left+right)) + (1 - (left+right)) + V(2))^0,
+ left * V(1) * right
}
local nestedbraces = P { lbrace * (nobrace + V(1))^0 * rbrace }
@@ -67,11 +71,12 @@ local spaces = space^0
local argument = Cs((lbrace/"") * ((nobrace + nestedbraces)^0) * (rbrace/""))
local content = (1-endofstring)^0
-lpegpatterns.nestedbraces = nestedbraces -- no capture
-lpegpatterns.nestedparents = nestedparents -- no capture
-lpegpatterns.nested = nestedbraces -- no capture
-lpegpatterns.argument = argument -- argument after e.g. =
-lpegpatterns.content = content -- rest after e.g =
+lpegpatterns.nestedbraces = nestedbraces -- no capture
+lpegpatterns.nestedparents = nestedparents -- no capture
+lpegpatterns.nestedbrackets = nestedbrackets -- no capture
+lpegpatterns.nested = nestedbraces -- no capture
+lpegpatterns.argument = argument -- argument after e.g. =
+lpegpatterns.content = content -- rest after e.g =
local value = lbrace * C((nobrace + nestedbraces)^0) * rbrace
+ C((nestedbraces + (1-comma))^0)
@@ -568,9 +573,9 @@ end
-- "1","2","3","4"
-- "5","6","7","8"
-- ]]
---
+
-- local mycsvsplitter = parsers.csvsplitter { numbers = true }
---
+
-- local list = mycsvsplitter(crap) inspect(list)
-- and this is a slightly patched version of a version posted by Philipp Gesang
@@ -617,12 +622,6 @@ end
-- local list, names = mycsvsplitter(crap,true) inspect(list) inspect(names)
-- local list, names = mycsvsplitter(crap) inspect(list) inspect(names)
--- parsers.stepper("1,7-",9,function(i) print(">>>",i) end)
--- parsers.stepper("1-3,7,8,9")
--- parsers.stepper("1-3,6,7",function(i) print(">>>",i) end)
--- parsers.stepper(" 1 : 3, ,7 ")
--- parsers.stepper("1:4,9:13,24:*",30)
-
local function ranger(first,last,n,action)
if not first then
-- forget about it
@@ -639,7 +638,7 @@ local function ranger(first,last,n,action)
end
end
-local cardinal = lpegpatterns.cardinal / tonumber
+local cardinal = (lpegpatterns.hexadecimal + lpegpatterns.cardinal) / tonumber
local spacers = lpegpatterns.spacer^0
local endofstring = lpegpatterns.endofstring
@@ -650,14 +649,29 @@ local stepper = spacers * ( cardinal * ( spacers * S(":-") * spacers * ( cardin
* Carg(1) * Carg(2) / ranger * S(", ")^0 )^1 * endofstring -- we're sort of strict (could do without endofstring)
function parsers.stepper(str,n,action)
+ local ts = type(str)
if type(n) == "function" then
- lpegmatch(stepper,str,1,false,n or print)
- else
+ if ts == "number" then
+ n(str)
+ elseif ts == "table" then
+ for i=1,#str do
+ n(str[i])
+ end
+ else
+ lpegmatch(stepper,str,1,false,n or print)
+ end
+ elseif ts == "string" then
lpegmatch(stepper,str,1,n,action or print)
end
end
---
+-- parsers.stepper("1,7-",9,function(i) print(">>>",i) end)
+-- parsers.stepper("1-3,7,8,9")
+-- parsers.stepper("1-3,6,7",function(i) print(">>>",i) end)
+-- parsers.stepper(" 1 : 3, ,7 ")
+-- parsers.stepper("1:4,9:13,24:*",30)
+-- parsers.stepper(1,print)
+-- parsers.stepper({1,3,4},print)
local pattern_math = Cs((P("%")/"\\percent " + P("^") * Cc("{") * lpegpatterns.integer * Cc("}") + anything)^0)
local pattern_text = Cs((P("%")/"\\percent " + (P("^")/"\\high") * Cc("{") * lpegpatterns.integer * Cc("}") + anything)^0)
@@ -681,7 +695,7 @@ local spaces = lpegpatterns.space^0
local dummy = function() end
setmetatableindex(cache,function(t,k)
- local separator = P(k)
+ local separator = S(k) -- was P
local value = (1-separator)^0
local pattern = spaces * C(value) * separator^0 * Cp()
t[k] = pattern
@@ -801,11 +815,20 @@ local pattern = Cf( Ct("") *
( Cg(Cc("day") * cardinal)
* S("-/") * Cg(Cc("month") * cardinal)
* S("-/") * Cg(Cc("year") * p_year)
+ ) +
+ ( Cg(Cc("year") * p_year)
+ * S("-/") * Cg(Cc("month") * cardinal)
+ ) +
+ ( Cg(Cc("month") * cardinal)
+ * S("-/") * Cg(Cc("year") * p_year)
)
)
- * P(" ") * Cg(Cc("hour") * cardinal)
+ * (
+ P(" ") * Cg(Cc("hour") * cardinal)
* P(":") * Cg(Cc("min") * cardinal)
* (P(":") * Cg(Cc("sec") * cardinal))^-1
+ + P(-1) )
+
, rawset)
lpegpatterns.splittime = pattern
@@ -814,6 +837,8 @@ function parsers.totime(str)
return lpegmatch(pattern,str)
end
+-- inspect(parsers.totime("2019-03-05"))
+-- inspect(parsers.totime("2019-03-05 12:12:12"))
-- print(os.time(parsers.totime("2019-03-05 12:12:12")))
-- print(os.time(parsers.totime("2019/03/05 12:12:12")))
-- print(os.time(parsers.totime("05-03-2019 12:12:12")))