def parse(tokens): expr = RelationalExpression.parse(tokens) if expr is None: return None while True: peek = tokens.peek() if peek == 'and' or peek == 'or': tokens.getNext() rhs = RelationalExpression.parse(tokens) if rhs is None: raise error.SyntaxError, 'Expected expression, got %r' % tokens.peek() expr = LogicalExpression(expr, rhs, peek) return expr
def testGreaterThanEqualTo(self): tokens = lex('1 >= 2') r = RelationalExpression.parse(tokens) self.failUnless(isinstance(r,RelationalExpression), r)
def testNotEqualTo(self): tokens = lex('1 != 2') r = RelationalExpression.parse(tokens) self.failUnless(isinstance(r,RelationalExpression), r)
def testLessThan(self): tokens = lex('1 < 2') r = RelationalExpression.parse(tokens) self.failUnless(isinstance(r,RelationalExpression), r)