'Parse a sequence of rules (rulesets and at-rules).
:param tokens:
An iterable of tokens.
:param context:
Either ``\'stylesheet\'`` or an at-keyword such as ``\'@media\'``.
(Most at-rules are only allowed in some contexts.)
:return:
A tuple of a list of parsed rules and a list of
:class:`~.parsing.ParseError`.'

def parse_rules(self, tokens, context):

    rules = []
    errors = []
    tokens = iter(tokens)
    for token in tokens:
        if (token.type not in (u'S', u'CDO', u'CDC')):
            try:
                if (token.type == u'ATKEYWORD'):
                    rule = self.read_at_rule(token, tokens)
                    result = self.parse_at_rule(rule, rules, errors, context)
                    rules.append(result)
                else:
                    (rule, rule_errors) = self.parse_ruleset(token, tokens)
                    rules.append(rule)
                    errors.extend(rule_errors)
            except ParseError as exc:
                errors.append(exc)
    return (rules, errors)
