Пример #1
0
    def parse(tokens):
        if tokens.peek() is not token.BEGIN_BLOCK:
            return None

        attributes = []
        decls = []

        tokens.expect(token.BEGIN_BLOCK)
        while tokens.peek() is not token.END_BLOCK:
            decl = None

            attr = Attribute.parse(tokens)
            if attr is not None:
                attributes.append(attr)
            else:
                decl = (
                    FunctionDecl.parse(tokens) or
                    VarDecl.parse(tokens) or
                    PassStatement.parse(tokens)
                )

                if decl is None:
                    raise error.SyntaxError(tokens.peek().position, 'Expected end block, variable or class declaration, or pass statement.  Got %r' % tokens.peek())

                if not isinstance(decl, PassStatement):
                    decls.append(decl)

            while tokens.peek() is token.END_OF_STATEMENT:
                tokens.getNext()

        tokens.expect(token.END_BLOCK)

        return ClassBody(decls, attributes)
Пример #2
0
    def testParseAttributeNoParameters(self):
        source = '[Thingie]'
        tok = lexer.lex(source)

        result = Attribute.parse(tok)

        self.assertTrue(isinstance(result, Attribute))
        self.assertTrue(isinstance(result.className, Identifier))
        self.assertEqual(result.className.name, 'Thingie')
        self.assertEqual(result.params, [])