From cc07a77f59a0024698b8261f866010c8b72481fe Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 21 Jan 2016 17:20:34 +0800 Subject: impl filter for interpreter --- xmake/core/base/interpreter.lua | 55 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 4 deletions(-) (limited to 'xmake/core/base/interpreter.lua') diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index cac14895c..b77979377 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -239,8 +239,53 @@ function interpreter._clear(self) self._PRIVATE._MTIMES = {} end +-- filter values +function interpreter._filter(self, values, filter) + + -- check + assert(self and values and filter) + + -- done + local results = {} + for _, value in ipairs(utils.wrap(values)) do + + -- only filter string value + if type(value) == "string" then + + -- replace the builtin variables + value = value:gsub("%$%((.-)%)", function (variable) + + -- check + assert(variable) + + -- is upper? + local isupper = false + local c = string.char(variable:byte()) + if c >= 'A' and c <= 'Z' then isupper = true end + + -- filter it + local result = filter(variable:lower()) + + -- convert to upper? + if isupper and result and type(result) == "string" then + result = result:upper() + end + + -- ok? + return result + end) + end + + -- append value + table.insert(results, value) + end + + -- ok? + return results +end + -- make results -function interpreter._make(self, scope_kind, remove_repeat) +function interpreter._make(self, scope_kind, remove_repeat, filter) -- check assert(self and self._PRIVATE and scope_kind) @@ -297,7 +342,9 @@ function interpreter._make(self, scope_kind, remove_repeat) end -- filter values - -- TODO + if filter and type(filter) == "function" then + values = self:_filter(values, filter) + end -- unwrap it if be only one values = utils.unwrap(values) @@ -342,7 +389,7 @@ function interpreter.init(rootdir) end -- load results -function interpreter.load(self, file, scope_kind, remove_repeat) +function interpreter.load(self, file, scope_kind, remove_repeat, filter) -- check assert(self and self._PUBLIC and self._PRIVATE and file and scope_kind) @@ -372,7 +419,7 @@ function interpreter.load(self, file, scope_kind, remove_repeat) end -- make results - return self:_make(scope_kind, remove_repeat) + return self:_make(scope_kind, remove_repeat, filter) end -- get mtimes -- cgit v1.3.1