Example #1
0
    def _parse_class(self):
        """
        The parser for a text class. Process the tokens, which follow a
        class definition.

        :return: Return a Scope representation of the tokens.
        :rtype: Class
        """
        first_pos = self._gen.current.start_pos
        cname = next(self._gen)
        if cname.type != tokenize.NAME:
            debug.warning("class: syntax err, token is not a name@%s (%s: %s)",
                          cname.start_pos[0], tokenize.tok_name[cname.type],
                          cname.string)
            return None

        cname = pr.Name(self.module, [(cname.string, cname.start_pos)],
                        cname.start_pos, cname.end_pos)

        super = []
        _next = next(self._gen)
        if _next.string == '(':
            super = self._parse_parentheses()
            _next = next(self._gen)

        if _next.string != ':':
            debug.warning("class syntax: %s@%s", cname, _next.start_pos[0])
            return None

        return pr.Class(self.module, cname, super, first_pos)
Example #2
0
    def _parse_class(self):
        """
        The parser for a text class. Process the tokens, which follow a
        class definition.

        :return: Return a Scope representation of the tokens.
        :rtype: Class
        """
        first_pos = self.start_pos
        token_type, cname = self.next()
        if token_type != tokenize.NAME:
            debug.warning(
                "class: syntax err, token is not a name@%s (%s: %s)" %
                (self.start_pos[0], tokenize.tok_name[token_type], cname))
            return None

        cname = pr.Name(self.module, [(cname, self.start_pos)], self.start_pos,
                        self.end_pos)

        super = []
        token_type, _next = self.next()
        if _next == '(':
            super = self._parse_parentheses()
            token_type, _next = self.next()

        if _next != ':':
            debug.warning("class syntax: %s@%s" % (cname, self.start_pos[0]))
            return None

        # because of 2 line class initializations
        scope = pr.Class(self.module, cname, super, first_pos)
        if self.user_scope and scope != self.user_scope \
                and self.user_position > first_pos:
            self.user_scope = scope
        return scope