diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2016-01-25 22:12:40 +0200 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2016-01-25 22:12:40 +0200 |
commit | 4cd671e69edb84134af642272d0b1117242cd64d (patch) | |
tree | 8a59a2898736caa6ffe2d675911ff84084e2cf5e | |
parent | 755d22afbdef35cdc0fdea4faf37c0417d03ea0d (diff) | |
download | meson-4cd671e69edb84134af642272d0b1117242cd64d.zip meson-4cd671e69edb84134af642272d0b1117242cd64d.tar.gz meson-4cd671e69edb84134af642272d0b1117242cd64d.tar.bz2 |
More comparison operators. Closes #363.
-rw-r--r-- | mesonbuild/interpreter.py | 12 | ||||
-rw-r--r-- | mesonbuild/mparser.py | 21 | ||||
-rw-r--r-- | test cases/common/68 number arithmetic/meson.build | 12 |
3 files changed, 38 insertions, 7 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 0a321a2..0c7926b 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -1,4 +1,4 @@ -# Copyright 2012-2015 The Meson development team +# Copyright 2012-2016 The Meson development team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -2181,8 +2181,16 @@ class Interpreter(): return val1 == val2 elif node.ctype == '!=': return val1 != val2 + elif node.ctype == '<': + return val1 < val2 + elif node.ctype == '<=': + return val1 <= val2 + elif node.ctype == '>': + return val1 > val2 + elif node.ctype == '>=': + return val1 >= val2 else: - raise InvalidCode('You broke me.') + raise InvalidCode('You broke my compare eval.') def evaluate_andstatement(self, cur): l = self.evaluate_statement(cur.left) diff --git a/mesonbuild/mparser.py b/mesonbuild/mparser.py index 1d569d5..090684c 100644 --- a/mesonbuild/mparser.py +++ b/mesonbuild/mparser.py @@ -1,4 +1,4 @@ -# Copyright 2014-2015 The Meson development team +# Copyright 2014-2016 The Meson development team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -63,6 +63,10 @@ class Lexer: ('equal', re.compile(r'==')), ('nequal', re.compile(r'\!=')), ('assign', re.compile(r'=')), + ('le', re.compile(r'<=')), + ('lt', re.compile(r'<')), + ('ge', re.compile(r'>=')), + ('gt', re.compile(r'>')), ] def lex(self, code): @@ -313,6 +317,14 @@ class ArgumentNode(): def __len__(self): return self.num_args() # Fixme +comparison_map = {'equal': '==', + 'nequal': '!=', + 'lt': '<', + 'le': '<=', + 'gt': '>', + 'ge': '>=' + } + # Recursive descent parser for Meson's definition language. # Very basic apart from the fact that we have many precedence # levels so there are not enough words to describe them all. @@ -387,10 +399,9 @@ class Parser: def e4(self): left = self.e5() - if self.accept('equal'): - return ComparisonNode(left.lineno, left.colno, '==', left, self.e5()) - if self.accept('nequal'): - return ComparisonNode(left.lineno, left.colno, '!=', left, self.e5()) + for nodename, operator_type in comparison_map.items(): + if self.accept(nodename): + return ComparisonNode(left.lineno, left.colno, operator_type, left, self.e5()) return left def e5(self): diff --git a/test cases/common/68 number arithmetic/meson.build b/test cases/common/68 number arithmetic/meson.build index 894c065..3872a11 100644 --- a/test cases/common/68 number arithmetic/meson.build +++ b/test cases/common/68 number arithmetic/meson.build @@ -20,3 +20,15 @@ endif if (5 / 3) * 3 != 3 error('Integer division is broken') endif + +assert(3 < 4, 'Lt broken') +assert(not(4 < 3), 'Lt broken') +assert(3 <= 4, 'Lte broken') +assert(not(4 <= 3), 'Lte broken') +assert(3 <= 3, 'Lte broken') + +assert(4 > 3, 'Gt broken') +assert(not(3 > 4), 'Gt broken') +assert(4 >= 3, 'Gte broken') +assert(not(3 >= 4), 'Gte broken') +assert(3 >= 3, 'Gte broken') |