Wrap error throwing functions in pcalls and make doc look cleaner for tiny.filter.

This commit is contained in:
bakpakin 2016-03-05 16:35:06 -05:00
parent 4148855233
commit 93a19d93c8

View File

@ -101,7 +101,7 @@ do
return ("%q"):format(text):gsub('\n', 'n'):gsub("[\128-\255]", getchr) return ("%q"):format(text):gsub('\n', 'n'):gsub("[\128-\255]", getchr)
end end
function filterJoin(prefix, seperator, ...) local function filterJoinRaw(prefix, seperator, ...)
local accum = {} local accum = {}
local build = {} local build = {}
for i = 1, select('#', ...) do for i = 1, select('#', ...) do
@ -125,6 +125,11 @@ do
return loader(...) return loader(...)
end end
function filterJoin(...)
local state, value = pcall(filterJoinRaw, ...)
if state then return value else return nil, value end
end
local function buildPart(str) local function buildPart(str)
local accum = {} local accum = {}
local subParts = {} local subParts = {}
@ -181,17 +186,21 @@ function tiny.rejectAny(...)
return filterJoin('not', ' or ', ...) return filterJoin('not', ' or ', ...)
end end
--- Makes a Filter from a string. Syntax is as follows. --- Makes a Filter from a string. Syntax of `pattern` is as follows.
-- --
-- * Tokens are alphanumeric strings including underscores. -- * Tokens are alphanumeric strings including underscores.
-- * Tokens can be separated by |, &, or surrounded by parentheses. -- * Tokens can be separated by |, &, or surrounded by parentheses.
-- * Tokens can be prefixed with ! are operated on with a boolean not. -- * Tokens can be prefixed with !, and are then operated on with a boolean 'not'.
-- --
-- Examples are best: -- Examples are best:
-- 'a|b|c' - Matches entities with an 'a' component OR a 'b' component or a 'c' component. -- 'a|b|c' - Matches entities with an 'a' component OR a 'b' component or a 'c' component.
-- 'a&!b&c' - Matches entities with an 'a' component AND NOT a 'b' component AND a 'c' component. -- 'a&!b&c' - Matches entities with an 'a' component AND NOT a 'b' component AND a 'c' component.
-- 'a|(b&c&d)|e - Matches 'a' OR ('b' AND 'c' AND 'd') OR 'e' -- 'a|(b&c&d)|e - Matches 'a' OR ('b' AND 'c' AND 'd') OR 'e'
tiny.filter = filterBuildString -- @param pattern
function tiny.filter(pattern)
local state, value = pcall(filterBuildString, pattern)
if state then return value else return nil, value end
end
--- System functions. --- System functions.
-- A System is a wrapper around function callbacks for manipulating Entities. -- A System is a wrapper around function callbacks for manipulating Entities.