예제 #1
0
    def testSemantic(self):
        tokens = lex('"abcd"**3')
        expr = ExponentExpression.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.exponentexpression import ExponentExpression
        pos = tokens.getPosition()
        operation = None

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

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

                expr = MultiplyExpression(expr, rhs, peek)
            else:
                return expr
예제 #3
0
 def testParseExp(self):
     tokens = lex("2 ** 2")
     result = ExponentExpression.parse(tokens)
     self.failUnless(isinstance(result, ExponentExpression), repr(result))