diff options
author | Philipp Gesang <phg@phi-gamma.net> | 2016-04-08 19:13:51 +0200 |
---|---|---|
committer | Philipp Gesang <phg@phi-gamma.net> | 2016-04-08 19:13:51 +0200 |
commit | f3495d7db72f854d8f7560a6ff11fa9012003062 (patch) | |
tree | 38b9ad5b0d15ccd5c8288be2221defc091eada64 /lualibs-util-prs.lua | |
parent | 233c885a37efeabaab00c68f1dd4262705a0ac9e (diff) | |
parent | 935306412b57f436fcb5307a14941ded3eb3168d (diff) | |
download | lualibs-f3495d7db72f854d8f7560a6ff11fa9012003062.tar.gz |
Merge pull request #29 from phi-gamma/master
version 2.4
Diffstat (limited to 'lualibs-util-prs.lua')
-rw-r--r-- | lualibs-util-prs.lua | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lualibs-util-prs.lua b/lualibs-util-prs.lua index a3c1c6f..01138f1 100644 --- a/lualibs-util-prs.lua +++ b/lualibs-util-prs.lua @@ -24,6 +24,8 @@ local sortedhash = table.sortedhash local sortedkeys = table.sortedkeys local tohash = table.tohash +local hashes = { } +utilities.parsers.hashes = hashes -- we share some patterns local digit = R("09") @@ -315,10 +317,17 @@ end local pattern = Cf(Ct("") * Cg(C((1-S(", "))^1) * S(", ")^0 * Cc(true))^1,rawset) -function utilities.parsers.settings_to_set(str,t) +function utilities.parsers.settings_to_set(str) return str and lpegmatch(pattern,str) or { } end +hashes.settings_to_set = table.setmetatableindex(function(t,k) -- experiment, not public + local v = k and lpegmatch(pattern,k) or { } + t[k] = v + return v +end) + +getmetatable(hashes.settings_to_set).__mode = "kv" -- could be an option (maybe sharing makes sense) function parsers.simple_hash_to_string(h, separator) local t, tn = { }, 0 |