diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2013-07-27 17:15:22 +0300 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2013-07-27 17:15:22 +0300 |
commit | 782021d65ee0f928f0d0b08b51068a32171e9801 (patch) | |
tree | 6d2e1aa7a41bfbf2fe433ff3b743d46d93e28cc1 | |
parent | 6a5a9a384842870f9a54ffeb3a828e57eafdec08 (diff) | |
download | meson-782021d65ee0f928f0d0b08b51068a32171e9801.zip meson-782021d65ee0f928f0d0b08b51068a32171e9801.tar.gz meson-782021d65ee0f928f0d0b08b51068a32171e9801.tar.bz2 |
Can do logical or.
-rw-r--r-- | interpreter.py | 17 | ||||
-rw-r--r-- | mparser.py | 6 | ||||
-rw-r--r-- | test cases/common/40 logic ops/meson.build | 22 |
3 files changed, 42 insertions, 3 deletions
diff --git a/interpreter.py b/interpreter.py index eb04fbb..aa7a0f9 100644 --- a/interpreter.py +++ b/interpreter.py @@ -843,6 +843,8 @@ class Interpreter(): return cur elif isinstance(cur, nodes.AndStatement): return self.evaluate_andstatement(cur) + elif isinstance(cur, nodes.OrStatement): + return self.evaluate_orstatement(cur) else: raise InvalidCode("Unknown statement.") @@ -1247,6 +1249,21 @@ class Interpreter(): raise InterpreterException('Second argument to "and" is not a boolean.') return r + def evaluate_orstatement(self, cur): + l = self.evaluate_statement(cur.left) + if isinstance(l, nodes.BoolStatement): + l = l.get_value() + if not isinstance(l, bool): + raise InterpreterException('First argument to "or" is not a boolean.') + if l: + return True + r = self.evaluate_statement(cur.right) + if isinstance(r, nodes.BoolStatement): + r = r.get_value() + if not isinstance(r, bool): + raise InterpreterException('Second argument to "or" is not a boolean.') + return r + def evaluate_arraystatement(self, cur): (arguments, kwargs) = self.reduce_arguments(cur.get_args()) if len(kwargs) > 0: @@ -71,7 +71,7 @@ precedence = ( ('nonassoc', 'EQUALS', 'NEQUALS'), ('left', 'OR'), ('left', 'AND'), -('nonassoc', 'COLON') +('nonassoc', 'COLON'), ('left', 'DOT'), ) @@ -196,6 +196,10 @@ def p_statement_and(t): 'statement : statement AND statement' t[0] = nodes.AndStatement(t[1], t[3]) +def p_statement_or(t): + 'statement : statement OR statement' + t[0] = nodes.OrStatement(t[1], t[3]) + def p_empty_else(t): 'elseblock : ' return None diff --git a/test cases/common/40 logic ops/meson.build b/test cases/common/40 logic ops/meson.build index a4466f4..8d2dc9f 100644 --- a/test cases/common/40 logic ops/meson.build +++ b/test cases/common/40 logic ops/meson.build @@ -27,13 +27,13 @@ else error('Not ok.') endif -if t and t +if true and t message('Ok.') else error('Not ok.') endif -if t and f +if t and false error('Not ok.') else message('Ok.') @@ -44,3 +44,21 @@ if f and t else message('Ok.') endif + +if f or false + error('Not ok.') +else + message('Ok.') +endif + +if true or f + message('Ok.') +else + error('Not ok.') +endif + +if t or true + message('Ok.') +else + error('Not ok.') +endif |