W3C home > Mailing lists > Public > www-style@w3.org > December 2012

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

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Tue, 18 Dec 2012 13:55:14 -0800
Message-ID: <CAAWBYDAGLYWKC3RCDmgYccA_mkerL9i5w0HOOm9DcXh60r4KTQ@mail.gmail.com>
To: Shawn Ligocki <sligocki@google.com>
Cc: www-style list <www-style@w3.org>
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 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 17:21:03 GMT