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

Re: [css4-values] Make comma auto-optional in grammars?

From: L. David Baron <dbaron@dbaron.org>
Date: Tue, 18 Dec 2012 16:53:02 -0500
To: "Tab Atkins Jr." <jackalmage@gmail.com>
Cc: www-style list <www-style@w3.org>
Message-ID: <20121218215302.GA3359@crum.dbaron.org>
On Tuesday 2012-12-18 11:29 -0800, Tab Atkins Jr. wrote:
> This is something that's been bugging me for a while.
> 
> Most of the time, CSS just uses whitespace as a separator between
> values.  This works great, because if a term is omitted, the implied
> whitespace on either side just collapses into a single whitespace
> block, so you don't have to worry about "too much" whitespace being
> left around when a term is omitted.
> 
> Sometimes, though, we use a comma to separate terms, and it doesn't
> have this behavior.  If a term is completely omitted, you have to
> carefully construct the grammar to force an associated comma to also
> be omitted.  This distorts a bunch of grammars, forcing a lot of extra
> wrappers and duplication of terms, making them harder to read than
> they should be.  One of the major purposes of our grammar is to be a
> relatively easily-understandable description of the allowed values, so
> this is a failure.
> 
> Could we perhaps define the use of the comma in grammars to have this
> behavior automatically?  Here's some before/after examples of how this
> would help.

Our specs should be understandable by a broader audience than just
people who have been involved in the working group for half a
decade.  I really don't want to introduce magic into our grammar
notation.  I'm a bit uncomfortable adding new syntax to it, but at
least syntax that someone doesn't recognize should lead them to
investigate what it means; if there's no syntax at all, most people
won't realize the rule exists.

> radial-gradient():
>  [ [ <shape> || <size> ] [ at <position> ]? , |
>     at <position>,
>   ]?
>   <color-stop-list>
> ==>
> [ <shape> || <size> ]? [ at <position> ]? <color-stop-list>

There are no commas in the second grammar at all, so I don't think
this example is right.

> 
> image():
> <image-tags>? [ <image-src> , ]* [ <image-src> | <color> ]
> ==>
> <image-tags>? <image-src># , <color>?

The first of these allows zero occurrences of <image-src>, but the
second requires at least one.  So, again, it seems like you're
changing something substantive here.

> image-set():
> [ <image-set-decl>, ]* [ <image-set-decl> | <color>]
> ==>
> <image-set-decl># , <color>?

Ditto.

> Specifically, the rule would be that, a comma must be omitted if,
> ignoring whitespace and comments, it would be the first or last token
> in the function/property value, or if the immediately preceding token
> is also a comma.  Informally, commas must separate terms, so omit them
> if they don't.

This isn't formal enough for me to understand exactly what you're
proposing (especially given the examples).  However, I'm pretty sure
I'm not going to like it anyway because of the reasons above.

-David

-- 
𝄞   L. David Baron                         http://dbaron.org/   𝄂
𝄢   Mozilla                           http://www.mozilla.org/   𝄂
Received on Wednesday, 19 December 2012 02:37:45 GMT

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