summaryrefslogtreecommitdiff
path: root/lualibs-util-prs.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2013-11-04 15:19:10 +0100
committerPhilipp Gesang <phg42.2a@gmail.com>2013-11-04 15:19:10 +0100
commit44ba990b30247a129dbb8b12e8c8154e37b5eb33 (patch)
tree1f45f18d03a9fda356ed8cb8c4acc590880f0305 /lualibs-util-prs.lua
parent6934dad6de7ea5a8a4d0523d30437eca9843263b (diff)
downloadlualibs-44ba990b30247a129dbb8b12e8c8154e37b5eb33.tar.gz
sync with Context as of 2013-11-04v2.1
Diffstat (limited to 'lualibs-util-prs.lua')
-rw-r--r--lualibs-util-prs.lua36
1 files changed, 34 insertions, 2 deletions
diff --git a/lualibs-util-prs.lua b/lualibs-util-prs.lua
index 7a8c3ce..29a57e0 100644
--- a/lualibs-util-prs.lua
+++ b/lualibs-util-prs.lua
@@ -40,8 +40,8 @@ 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)
-- we could use a Cf Cg construct
@@ -189,6 +189,38 @@ function parsers.settings_to_array(str,strict)
end
end
+-- this one also strips end spaces before separators
+--
+-- "{123} , 456 " -> "123" "456"
+
+local separator = space^0 * comma * space^0
+local value = P(lbrace * C((nobrace + nestedbraces)^0) * rbrace)
+ + C((nestedbraces + (1-(space^0*(comma+P(-1)))))^0)
+local withvalue = Carg(1) * value / function(f,s) return f(s) end
+local pattern_a = spaces * Ct(value*(separator*value)^0)
+local pattern_b = spaces * withvalue * (separator*withvalue)^0
+
+function parsers.stripped_settings_to_array(str)
+ if not str or str == "" then
+ return { }
+ else
+ return lpegmatch(pattern_a,str)
+ end
+end
+
+function parsers.process_stripped_settings(str,action)
+ if not str or str == "" then
+ return { }
+ else
+ return lpegmatch(pattern_b,str,1,action)
+ end
+end
+
+-- parsers.process_stripped_settings("{123} , 456 ",function(s) print("["..s.."]") end)
+-- parsers.process_stripped_settings("123 , 456 ",function(s) print("["..s.."]") end)
+
+--
+
local function set(t,v)
t[#t+1] = v
end