diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 0a321a275..0c7926b83 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 1d569d5cd..090684c82 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 894c065ad..3872a11de 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')