Re: [CSS 2.1] General at-blocks and error recovery

L. David Baron wrote:
> On Saturday 2008-03-08 10:54 +0100, Anne van Kesteren wrote:
>> On Sat, 08 Mar 2008 06:56:11 +0100, L. David Baron wrote:
>>> What Firefox is doing is the following:
>>>
>>> @media all {
>>>   /* ok, we're inside an @media rule, so we parse declaration blocks */
>>> @
>>>   /* well, this is the beginning of an invalid selector, so we have
>>>      to parse until we hit the end of the declaration block, that
>>>      is, until we hit an { and then the matching } */
>>> }
>>>   /* not a {, so keep looking for the { to start our declaration block */
>>>   /* ... same for all remaining tokens in the style sheet */
>>>
>>> I can't find anything that says what @media rules are supposed to 
>>> have in them, but this seems to match the spec, now that I think 
>>> about it.
>> I figured this was the reasoning. So is the reason this does not violate
>>
>>   http://www.w3.org/TR/CSS21/syndata.html#block
>>
>> that you're trying to form an at-rule token and therefore the matching { } 
>> pair is not actually a matching pair but the closing curly brace is part of 
>> a token?
>
> No, it's definitely not part of a token.  The tokenizer is quite 
> clear.

I didn't understand you both. Did Anne mean "at-rule production" instead of 
"at-rule token"?

> What's happening is that after the "@" we're parsing an invalid 
> selector.  When we're parsing an invalid selector, we recover after 
> we find a "{" and then a matching "}" (a declaration block).  When 
> we hit the "{", we're looking for a "{" so it doesn't actually match 
> anything.
>
> If you want Firefox to recover after "@media all { @ }" it will if 
> you write "{ } }".  The "{ }" is the declaration block it's looking 
> for, and the final "}" closes the @media rule.

This logic does not match the CSS 2.1 forward-compatible [core syntax][1]. 
The core syntax is *unaware* of the specific at-rule names. And when you 
introduce an at-rule, you cannot specify that "it contains selectors". 
Consider the [Gecko extension][2]:

     @-moz-document url(http://www.w3.org/) {
         /* Content model: CSS rules inside */
         @ /* error - how to recover? */
     }

Now Gecko will not recover on the final '}', because it assumes the selector 
inside, and other engines are unaware of that, and they would recover 
successfully at end of the block.

The core syntax should apply to the @media rule too - the browser that is 
unaware of @media should be able to parse it using the core syntax rules. 
The suitable grammar productions are:

stylesheet  : statement*;
statement   : at-rule;
at-rule     : ATKEYWORD S* any* block;
block       : '{' S* [ any | block | ATKEYWORD S* | ';' S* ]* '}' S*;
any         : [ IDENT | NUMBER | PERCENTAGE | DIMENSION | STRING
               | DELIM | URI | HASH | UNICODE-RANGE | INCLUDES
               | DASHMATCH | FUNCTION S* any* ')'
               | '(' S* any* ')' | '[' S* any* ']' ] S*;


[1]: http://www.w3.org/TR/2007/CR-CSS21-20070719/syndata.html#block
[2]: http://developer.mozilla.org/en/docs/CSS:@-moz-document

-- 
Andrei Polushin

Received on Sunday, 9 March 2008 17:12:04 UTC