Example #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)
    def parse(tokens):
        position = tokens.peek().position

        tokens.expect(token.BEGIN_BLOCK)

        decls = []

        while tokens.peek() is not token.END_BLOCK:
            decl = (
                FunctionPrototype.parse(tokens) or
                PassStatement.parse(tokens)
            )

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

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

            if isinstance(decl, PassStatement): continue # Don't store pass statements.  They're not useful.

            decls.append(decl)

        tokens.expect(token.END_BLOCK)

        return InterfaceBody(decls)
Example #3
0
    def parse(tokens):
        if tokens.peek() is not token.BEGIN_BLOCK:
            return None

        decls = []

        tokens.expect(token.BEGIN_BLOCK)
        while tokens.peek() is not token.END_BLOCK:
            decl = (
                AssignStatement.parse(tokens) or
                Identifier.parse(tokens) or
                PassStatement.parse(tokens)
            )

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

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

            if isinstance(decl, PassStatement): continue # Don't store pass statements.  They're not useful.

            decls.append(decl)

        tokens.expect(token.END_BLOCK)

        return EnumBody(decls)