Beispiel #1
0
    def testSemantic(self):
        tokens = lex('"abcd"+3')
        expr = AddExpression.parse(tokens)

        from nine.scope import Scope
        scope = Scope(parent=None)

        from nine import error
        self.failUnlessRaises(error.TypeError,
            lambda: expr.semantic(scope)
        )
    def parse(tokens):
        from ast.addexpression import AddExpression
        pos = tokens.getPosition()
        operation = None

        expr = AddExpression.parse(tokens)
        if expr is None:
            return None

        while True:
            peek = tokens.peek()
            if peek in lexer.ShiftOperators:
                tokens.getNext()
                rhs = AddExpression.parse(tokens)
                if rhs is None:
                    raise SyntaxError, 'Expected expression, got %r' % tokens.peek()

                expr = ShiftExpression(expr, rhs, peek)
            else:
                return expr
Beispiel #3
0
 def testParseSub(self):
     tokens = lex("12 - 3")
     result = AddExpression.parse(tokens)
     self.failUnless(isinstance(result, AddExpression), repr(result))