W3C home > Mailing lists > Public > www-style@w3.org > March 2015

Re: [mediaqueries] Editorial: <media-condition> grammar requires unbounded look-ahead

From: Florian Rivoal <florian@rivoal.net>
Date: Mon, 23 Mar 2015 21:06:43 +0100
Cc: www-style list <www-style@w3.org>
Message-Id: <6E3A9DA4-DB54-4846-B0BC-3952D31949CF@rivoal.net>
To: Simon Sapin <simon.sapin@exyr.org>

> On 23 Mar 2015, at 17:19, Simon Sapin <simon.sapin@exyr.org> wrote:
> 
> The grammar currently is:
> 
>> <media-condition> = <media-not> | <media-and> | <media-or> | <media-in-parens>
>> <media-not> = not <media-in-parens>
>> <media-and> = <media-in-parens> [ and <media-in-parens> ]+
>> <media-or> = <media-in-parens> [ or <media-in-parens> ]+
> 
> When parsing <media-condition>, deciding which of the alternatives should be taken may require looking ahead by an unbounded amount.
> 
> To avoid this, it could be rewritten as:
> 
> <media-condition> = <media-not>
>                  | <media-in-parens> [ <media-and>* | <media-or>* ]
> <media-not> = not <media-in-parens>
> <media-and> = and <media-in-parens>
> <media-or> = or <media-in-parens>
> 
> 
> Unfortunately that makes more awkward the definitions that follow
> 
>> Each of the major terms of <media-condition> is associated with a
>> boolean result, as follows:

In an implementation, I agree with you that what you suggest is better. However, in terms of language they accept, the two are equivalent and the current approach makes the spec easier to write as you note. Besides, the intermediate non terminals are not exposed or reused anywhere.

Since implementations can do the right thing and implement the more efficient and equivalent grammar you suggest, is there any downside in leaving the spec as it is, for readability reasons?

 - Florian
Received on Monday, 23 March 2015 20:07:08 UTC

This archive was generated by hypermail 2.3.1 : Monday, 2 May 2016 14:39:30 UTC