+_M['or'] = function(v, ...)
+ local i
+ for i = 1, select('#', ...), 2 do
+ local f = select(i, ...)
+ local a = select(i+1, ...)
+ if type(f) ~= "function" then
+ if f == v then
+ return true
+ end
+ i = i - 1
+ elseif f(v, unpack(a)) then
+ return true
+ end
+ end
+ return false
+end
+
+_M['and'] = function(v, ...)
+ local i
+ for i = 1, select('#', ...), 2 do
+ local f = select(i, ...)
+ local a = select(i+1, ...)
+ if type(f) ~= "function" then
+ if f ~= v then
+ return false
+ end
+ i = i - 1
+ elseif not f(v, unpack(a)) then
+ return false
+ end
+ end
+ return true
+end
+
+function neg(v, ...)
+ return _M['or'](v:gsub("^%s*!%s*", ""), ...)
+end
+
+function list(v, subvalidator, subargs)
+ if type(subvalidator) ~= "function" then
+ return false
+ end
+ local token
+ for token in v:gmatch("%S+") do
+ if not subvalidator(token, unpack(subargs)) then
+ return false
+ end
+ end
+ return true
+end
+