tinycss
tinycss copied to clipboard
Parse errorunknown at-rule in stylesheet context: @keyframes
See https://developer.mozilla.org/en-US/docs/Web/CSS/@keyframes for a description of this CSS feature.
test.css:
@keyframes identifier {
0% { top: 0; left: 0; }
30% { top: 50px; }
68%, 72% { left: 50px; }
100% { top: 100px; left: 100%; }
}
test.py
import tinycss
parser = tinycss.make_parser('page3')
ss = parser.parse_stylesheet_file('test.css')
print(ss.errors)
$ python3 test.py
[ParseError('Parse error at 1:1, unknown at-rule in stylesheet context: @keyframes',)]
tinycss unfortunately needs to be modified for every new kind of rule you might want to add. (There is an extension mechanism, but it’s not great.)
I recommend using tinycss2 instead, which was designed to fix this: you get an AtRule object that you can parse yourself. Something like:
for rule in parse_stylesheet(...):
if rule.type == 'at-rule' and rule.lower_at_keyword == 'keyframes':
name = parse_one_component_value(rule.prelude)
if name.type != 'ident':
continue
name = name.lower_value
for keyframe in parse_rule_list(rule.content):
if keyframe.type != 'qualified-rule'
continue
# You get the idea…
Look at that! I gave basically the same answer last year in #6.