summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lualibs-file.lua2
-rw-r--r--lualibs-table.lua16
-rw-r--r--lualibs-trac-inf.lua3
-rw-r--r--lualibs-util-prs.lua49
-rw-r--r--lualibs-util-str.lua8
-rw-r--r--lualibs-util-tab.lua2
6 files changed, 63 insertions, 17 deletions
diff --git a/lualibs-file.lua b/lualibs-file.lua
index 7ed6370..b6822e9 100644
--- a/lualibs-file.lua
+++ b/lualibs-file.lua
@@ -436,7 +436,7 @@ local deslasher = lpeg.replacer(S("\\/")^1,"/")
function file.join(one, two, three, ...)
if not two then
- return one == "" and one or lpegmatch(stripper,one)
+ return one == "" and one or lpegmatch(reslasher,one)
end
if one == "" then
return lpegmatch(stripper,three and concat({ two, three, ... },"/") or two)
diff --git a/lualibs-table.lua b/lualibs-table.lua
index 552097e..d1e0592 100644
--- a/lualibs-table.lua
+++ b/lualibs-table.lua
@@ -673,6 +673,8 @@ local function do_serialize(root,name,depth,level,indexed)
else
handle(format("%s [%s]=%s,",depth,k and "true" or "false",v)) -- %.99g
end
+ elseif tk ~= "string" then
+ -- ignore
elseif noquotes and not reserved[k] and lpegmatch(propername,k) then
if hexify then
handle(format("%s %s=0x%X,",depth,k,v))
@@ -695,6 +697,8 @@ local function do_serialize(root,name,depth,level,indexed)
end
elseif tk == "boolean" then
handle(format("%s [%s]=%q,",depth,k and "true" or "false",v))
+ elseif tk ~= "string" then
+ -- ignore
elseif noquotes and not reserved[k] and lpegmatch(propername,k) then
handle(format("%s %s=%q,",depth,k,v))
else
@@ -710,6 +714,8 @@ local function do_serialize(root,name,depth,level,indexed)
end
elseif tk == "boolean" then
handle(format("%s [%s]={},",depth,k and "true" or "false"))
+ elseif tk ~= "string" then
+ -- ignore
elseif noquotes and not reserved[k] and lpegmatch(propername,k) then
handle(format("%s %s={},",depth,k))
else
@@ -726,6 +732,8 @@ local function do_serialize(root,name,depth,level,indexed)
end
elseif tk == "boolean" then
handle(format("%s [%s]={ %s },",depth,k and "true" or "false",concat(st,", ")))
+ elseif tk ~= "string" then
+ -- ignore
elseif noquotes and not reserved[k] and lpegmatch(propername,k) then
handle(format("%s %s={ %s },",depth,k,concat(st,", ")))
else
@@ -746,6 +754,8 @@ local function do_serialize(root,name,depth,level,indexed)
end
elseif tk == "boolean" then
handle(format("%s [%s]=%s,",depth,tostring(k),v and "true" or "false"))
+ elseif tk ~= "string" then
+ -- ignore
elseif noquotes and not reserved[k] and lpegmatch(propername,k) then
handle(format("%s %s=%s,",depth,k,v and "true" or "false"))
else
@@ -763,6 +773,8 @@ local function do_serialize(root,name,depth,level,indexed)
end
elseif tk == "boolean" then
handle(format("%s [%s]=load(%q),",depth,k and "true" or "false",f))
+ elseif tk ~= "string" then
+ -- ignore
elseif noquotes and not reserved[k] and lpegmatch(propername,k) then
handle(format("%s %s=load(%q),",depth,k,f))
else
@@ -778,6 +790,8 @@ local function do_serialize(root,name,depth,level,indexed)
end
elseif tk == "boolean" then
handle(format("%s [%s]=%q,",depth,k and "true" or "false",tostring(v)))
+ elseif tk ~= "string" then
+ -- ignore
elseif noquotes and not reserved[k] and lpegmatch(propername,k) then
handle(format("%s %s=%q,",depth,k,tostring(v)))
else
@@ -1165,7 +1179,7 @@ function table.has_one_entry(t)
return t and next(t,next(t)) == nil
end
--- new
+-- new (rather basic, not indexed and nested)
function table.loweredkeys(t) -- maybe utf
local l = { }
diff --git a/lualibs-trac-inf.lua b/lualibs-trac-inf.lua
index f4c4e55..a1d7fb0 100644
--- a/lualibs-trac-inf.lua
+++ b/lualibs-trac-inf.lua
@@ -14,7 +14,7 @@ if not modules then modules = { } end modules ['trac-inf'] = {
local type, tonumber, select = type, tonumber, select
local format, lower, find = string.format, string.lower, string.find
local concat = table.concat
-local clock = os.gettimeofday or os.clock -- should go in environment
+local clock = os.gettimeofday or os.clock -- should go in environment
local setmetatableindex = table.setmetatableindex
local serialize = table.serialize
@@ -183,6 +183,7 @@ end
function statistics.runtime()
stoptiming(statistics)
+ stoptiming(statistics) -- somehow we can start the timer twice, but where
return statistics.formatruntime(elapsedtime(statistics))
end
diff --git a/lualibs-util-prs.lua b/lualibs-util-prs.lua
index 01138f1..650a7ea 100644
--- a/lualibs-util-prs.lua
+++ b/lualibs-util-prs.lua
@@ -36,6 +36,8 @@ local lbrace = P("{")
local rbrace = P("}")
local lparent = P("(")
local rparent = P(")")
+local lbracket = P("[")
+local rbracket = P("]")
local period = S(".")
local punctuation = S(".,:;")
local spacer = lpegpatterns.spacer
@@ -44,8 +46,9 @@ local newline = lpegpatterns.newline
local anything = lpegpatterns.anything
local endofstring = lpegpatterns.endofstring
-local nobrace = 1 - (lbrace + rbrace )
-local noparent = 1 - (lparent + rparent)
+local nobrace = 1 - (lbrace + rbrace )
+local noparent = 1 - (lparent + rparent)
+local nobracket = 1 - (lbracket + rbracket)
-- we could use a Cf Cg construct
@@ -56,11 +59,12 @@ lpegpatterns.balanced = P {
[2] = left * V(1) * right
}
-local nestedbraces = P { lbrace * (nobrace + V(1))^0 * rbrace }
-local nestedparents = P { lparent * (noparent + V(1))^0 * rparent }
-local spaces = space^0
-local argument = Cs((lbrace/"") * ((nobrace + nestedbraces)^0) * (rbrace/""))
-local content = (1-endofstring)^0
+local nestedbraces = P { lbrace * (nobrace + V(1))^0 * rbrace }
+local nestedparents = P { lparent * (noparent + V(1))^0 * rparent }
+local nestedbrackets = P { lbracket * (nobracket + V(1))^0 * rbracket }
+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
@@ -79,10 +83,6 @@ local pattern_b = spaces * comma^0 * spaces * (key * ((spaces * equal * spaces *
-- "a=1, b=2, c=3, d={a{b,c}d}, e=12345, f=xx{a{b,c}d}xx, g={}" : outer {} removes, leading spaces ignored
--- todo: rewrite to fold etc
---
--- parse = lpeg.Cf(lpeg.Carg(1) * lpeg.Cg(key * equal * value) * separator^0,rawset)^0 -- lpeg.match(parse,"...",1,hash)
-
local hash = { }
local function set(key,value)
@@ -193,6 +193,33 @@ function parsers.settings_to_array(str,strict)
end
end
+function parsers.settings_to_numbers(str)
+ if not str or str == "" then
+ return { }
+ end
+ if type(str) == "table" then
+ -- fall through
+ elseif find(str,",",1,true) then
+ str = lpegmatch(pattern,str)
+ else
+ return { tonumber(str) }
+ end
+ for i=1,#str do
+ str[i] = tonumber(str[i])
+ end
+ return str
+end
+
+local value = P(lbrace * C((nobrace + nestedbraces)^0) * rbrace)
+ + C((nestedbraces + nestedbrackets + nestedparents + (1-comma))^0)
+local pattern = spaces * Ct(value*(separator*value)^0)
+
+function parsers.settings_to_array_obey_fences(str)
+ return lpegmatch(pattern,str)
+end
+
+-- inspect(parsers.settings_to_array_obey_fences("url(http://a,b.c)"))
+
-- this one also strips end spaces before separators
--
-- "{123} , 456 " -> "123" "456"
diff --git a/lualibs-util-str.lua b/lualibs-util-str.lua
index 95534c8..a54a4aa 100644
--- a/lualibs-util-str.lua
+++ b/lualibs-util-str.lua
@@ -822,6 +822,10 @@ end
-- aA b cC d eE f gG hH iI jJ lL mM N o p qQ r sS tT uU wW xX z
+-- extensions : %!tag!
+
+-- can be made faster but not called that often
+
local builder = Cs { "start",
start = (
(
@@ -850,10 +854,10 @@ local builder = Cs { "start",
+ V("a") -- new
+ V("A") -- new
+ V("j") + V("J") -- stripped e E
- + V("m") + V("M") -- new
+ + V("m") + V("M") -- new (formatted number)
+ V("z") -- new
--
- -- + V("?") -- ignores probably messed up %
+ -- + V("?") -- ignored, probably messed up %
)
+ V("*")
)
diff --git a/lualibs-util-tab.lua b/lualibs-util-tab.lua
index a6239ad..d502058 100644
--- a/lualibs-util-tab.lua
+++ b/lualibs-util-tab.lua
@@ -812,7 +812,7 @@ local function serialize(root,name,specification)
-- The dummy access will initialize a table that has a delayed initialization
-- using a metatable. (maybe explicitly test for metatable)
if getmetatable(root) then -- todo: make this an option, maybe even per subtable
- local dummy = root._w_h_a_t_e_v_e_r_
+ local dummy = root._w_h_a_t_e_v_e_r_ -- needed
root._w_h_a_t_e_v_e_r_ = nil
end
-- Let's forget about empty tables.