Re: [css3-mediaqueries] Parsing: @media all and(color) { ... }

On Tue, Dec 18, 2012 at 1:32 PM, Shawn Ligocki <sligocki@google.com> wrote:
> Should the following statement be parsable?
>
> @media all and(color) { ... }
>
> and equivalent to:
>
> @media all and (color) { ... }
>
> Where ... are valid rulesets. Notice the lack of space between "and" and
> "(color)".
>
> Production rules on http://www.w3.org/TR/css3-mediaqueries/ seems to imply
> that the whitespaces are optional:
>
> media_query
>  : [ONLY | NOT]? S* media_type S* [ AND S* expression ]*
>  | expression [ AND S* expression ]*
>  ;
>
> But Webkit and https://github.com/tabatkins/css-parser don't seem to parse
> it that way. I'm guessing this is because of the lexer will parses
> "and(color)" as a FUNCTION and thus render this as an invalid CSS media
> query. https://github.com/tabatkins/css-parser seems to confirm this:
>
> AT(media) WS IDENT(all) WS FUNCTION(and) IDENT(color) )
>
>
> Is this correct? That this statement should be treated as malformed and thus
> ignored (rendered as "@media not all { ... }")?

Correct.  The grammar is written in terms of a token stream, which
means that by the time it sees your first rule, it's already been
reduced to AT-RULE(media) WS IDENT(all) WS FUNCTION(and) IDENT(color)
CLOSE-PAREN, which doesn't match the grammar.

It is *possible* to omit whitespace, as the grammar implies can be
done, by using comments.  @media/**/all/**/and/**/(color) has no
whitespace between the tokens, but still separates out the tokens
appropriately and thus is valid according to the MQ grammar.
(Comments are implicitly allowed between any two tokens, and so are
omitted from grammars for readability.)

~TJ

Received on Tuesday, 18 December 2012 21:56:01 UTC