summaryrefslogtreecommitdiff
path: root/xmake/core/base/interpreter.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2016-01-21 17:20:34 +0800
committerruki <[email protected]>2016-02-15 19:10:25 +0800
commitcc07a77f59a0024698b8261f866010c8b72481fe (patch)
tree6aa804828b6eca61aeb9c27cb4cc5ddcd3dfff6d /xmake/core/base/interpreter.lua
parent1242c86015675ef739347efd3af67c91c4067867 (diff)
impl filter for interpreter
Diffstat (limited to 'xmake/core/base/interpreter.lua')
-rw-r--r--xmake/core/base/interpreter.lua55
1 files changed, 51 insertions, 4 deletions
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