#NEWLINE# def parse_rules( self , tokens , context ) : #NEWLINE# #INDENT# "Parse a sequence of rules (rulesets and at-rules).\n\n        :param tokens:\n            An iterable of tokens.\n        :param context:\n            Either ``'stylesheet'`` or an at-keyword such as ``'@media'``.\n            (Most at-rules are only allowed in some contexts.)\n        :return:\n            A tuple of a list of parsed rules and a list of\n            :class:`~.parsing.ParseError`.\n\n        " #NEWLINE# rules = [ ] #NEWLINE# errors = [ ] #NEWLINE# tokens = iter ( tokens ) #NEWLINE# for token in tokens : #NEWLINE# #INDENT# if ( errors . type not in ( 'S' , 'CDO' , 'CDC' ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# if ( token . type == 'ATKEYWORD' ) : #NEWLINE# #INDENT# rule = self . read_at_rule ( token , tokens ) #NEWLINE# result = self . parse_at_rule ( rule , rules , errors , context ) #NEWLINE# rules . append ( result ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( rule , rule_errors ) = self . parse_ruleset ( token , tokens ) #NEWLINE# rules . append ( rule ) #NEWLINE# errors . extend ( rule_errors ) #NEWLINE# #UNINDENT# #UNINDENT# except ParseError as exc : #NEWLINE# #INDENT# errors . append ( exc ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return ( rules , errors )