summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2013-05-23 21:37:05 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2013-05-23 21:37:05 +0100
commit022da29a4be6caadbb55a8f5e481778e566b5ffb (patch)
tree43e6b55bb94c0435d5c49f88358c6967c9bc1f45 /lib
parentca95775ad1bf14088333b86677525cecb62f0aef (diff)
downloadgitano-022da29a4be6caadbb55a8f5e481778e566b5ffb.tar.gz
LACE: Alter simple match compiler ready for more
This alters the simple match compiler to support a definition format along the lines of: define some_name ref pattern ^refs/heads/ The accepted middle entries being exact, pattern, !exact and !pattern
Diffstat (limited to 'lib')
-rw-r--r--lib/gitano/lace.lua38
1 files changed, 27 insertions, 11 deletions
diff --git a/lib/gitano/lace.lua b/lib/gitano/lace.lua
index 517c476..4927e1c 100644
--- a/lib/gitano/lace.lua
+++ b/lib/gitano/lace.lua
@@ -46,16 +46,13 @@ end
local matchers = {}
-local function _do_simple_match(ctx, key, value)
+local function _do_simple_match(ctx, key, matchtype, value)
value = util.process_expansion(ctx, value)
- local sigil, value = value:match("^(.)(.*)$")
- local inv = false
- if sigil == "!" then
- inv = true
- elseif sigil ~= "=" then
- value = sigil .. value
+ local inv = matchtype:sub(1,1) == "!"
+ if inv then
+ matchtype = matchtype:sub(2)
end
- local pat = value:match("^%~(.+)$")
+ local pat = (matchtype == "pattern") and value
local kk = ctx[key] or ""
local function check(v)
if pat then
@@ -94,13 +91,32 @@ local function _do_simple_match(ctx, key, value)
end
end
-local function _simple_match(ctx, key, value, guard)
+local function _simple_match(ctx, key, matchtype, value, guard)
if guard ~= nil then
- return lace.compiler.error("Unexpected additional argument", {3})
+ return lace.compiler.error("Unexpected additional argument", {4})
+ end
+ if value == nil then
+ matchtype, value = "", matchtype
+ local sigil, _value = value:match("^(.)(.*)$")
+ if sigil == "!" then
+ inv = true
+ matchtype = "!"
+ value = _value
+ end
+ sigil, _value = value:match("^(.)(.*)$")
+ if sigil == "=" then
+ matchtype = matchtype .. "exact"
+ value = _value
+ elseif sigil == "~" then
+ matchtype = matchtype .. "pattern"
+ value = _value
+ else
+ matchtype = matchtype .. "exact"
+ end
end
return {
fn = _do_simple_match,
- args = { key, util.prep_expansion(value) }
+ args = { key, matchtype, util.prep_expansion(value) }
}
end