Skip to content
This repository has been archived by the owner on Sep 18, 2019. It is now read-only.

Parse errorunknown at-rule in stylesheet context: @keyframes #9

Open
jdufresne opened this issue Jan 28, 2015 · 2 comments
Open

Parse errorunknown at-rule in stylesheet context: @keyframes #9

jdufresne opened this issue Jan 28, 2015 · 2 comments

Comments

@jdufresne
Copy link

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',)]
@SimonSapin
Copy link
Member

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…

@SimonSapin
Copy link
Member

Look at that! I gave basically the same answer last year in #6.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants