aboutsummaryrefslogtreecommitdiff
path: root/interpreter.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2014-09-18 18:49:36 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2014-09-18 19:04:29 +0300
commit9e7009bf23e2fce52829e195c4c9c29c3f2286fe (patch)
treef6e6013bb5c09b7b5dad97c34d1c64308d1403a3 /interpreter.py
parenta8a696c55f1bf5ab292c8f3a1440af883952c0bb (diff)
downloadmeson-9e7009bf23e2fce52829e195c4c9c29c3f2286fe.zip
meson-9e7009bf23e2fce52829e195c4c9c29c3f2286fe.tar.gz
meson-9e7009bf23e2fce52829e195c4c9c29c3f2286fe.tar.bz2
Added array methods.
Diffstat (limited to 'interpreter.py')
-rw-r--r--interpreter.py30
1 files changed, 27 insertions, 3 deletions
diff --git a/interpreter.py b/interpreter.py
index 2893b8d..2d89804 100644
--- a/interpreter.py
+++ b/interpreter.py
@@ -738,9 +738,10 @@ class Interpreter():
try:
self.evaluate_statement(cur)
except Exception as e:
- e.lineno = cur.lineno
- e.colno = cur.colno
- e.file = os.path.join(self.subdir, 'meson.build')
+ if not(hasattr(e, 'lineno')):
+ e.lineno = cur.lineno
+ e.colno = cur.colno
+ e.file = os.path.join(self.subdir, 'meson.build')
raise e
i += 1 # In THE FUTURE jump over blocks and stuff.
@@ -1438,11 +1439,34 @@ class Interpreter():
obj = obj.get_value()
if isinstance(obj, str):
return self.string_method_call(obj, method_name, args)
+ if isinstance(obj, list):
+ return self.array_method_call(obj, method_name, self.reduce_arguments(args)[0])
if not isinstance(obj, InterpreterObject):
raise InvalidArguments('Variable "%s" is not callable.' % object_name)
(args, kwargs) = self.reduce_arguments(args)
return obj.method_call(method_name, args, kwargs)
+ def array_method_call(self, obj, method_name, args):
+ if method_name == 'contains':
+ return self.check_contains(obj, args)
+ raise InterpreterException('Arrays do not have a method called "%s".' % method_name)
+
+ def check_contains(self, obj, args):
+ if len(args) != 1:
+ raise InterpreterException('Contains method takes exactly one argument.')
+ item = args[0]
+ for element in obj:
+ if isinstance(element, list):
+ found = self.check_contains(element, args)
+ if found:
+ return True
+ try:
+ if element == item:
+ return True
+ except Exception:
+ pass
+ return False
+
def evaluate_if(self, node):
assert(isinstance(node, mparser.IfClauseNode))
for i in node.ifs: