W3C home > Mailing lists > Public > www-style@w3.org > April 2014

[css-values] The last grammar combinator - 1+ in order

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Thu, 17 Apr 2014 17:27:37 -0700
Message-ID: <CAAWBYDBz5F0f7pV8R_NtJ7e2TtvkZ9nMy5=3yj6qmR2sOp_EmA@mail.gmail.com>
To: www-style list <www-style@w3.org>
We're currently missing a grammar combinator in CSS's property grammar syntax.

We can express "exactly one" as "a | b", and we can express 5 of the 6
possibilities in {0+, 1+, all}×{in order, any order}* .  The one thing
we're missing is "1+, in order", which we can't write without
duplication and honestly confusing grammar.

For example, the syntax for background-position-x takes a side keyword
and/or a length/percentage.  You can specify either or both, but can't
specify none.  Today, that requires writing something like:

[left | right] |
[left | right]? [<length> | <percentage>]

I don't know about you, but I don't see that as saying "a keyword
and/or a length/percentage".  It's hard to read, and means we're
duplicating terms in the grammar, making it larger and even harder to
read, or else requiring indirection through an intermediate grammar
production.

This sort of pattern appears all over CSS.  For example, the <picture>
spec defines the author-conformance grammar of its sizes='' attribute
using CSS.  It needs one or more "MQ + size" values, and/or a final
bare size, and currently has to do the duplication and non-obvious
structure as above.

The image() function is yet another example:
<http://dev.w3.org/csswg/css-images/#image-notation>. You specify urls
and/or a fallback color, and I have to duplicate some of the grammar
terms to make that happen.

I propose the combinator be named ??, and its precedence be set
between juxtaposition and &&.  The reason for this name is one of the
other two syntaxes in the "in order" branch uses the question mark
(the other is juxtaposition, which uses no syntax).

I recognize that we don't generally want to add more ASCII grawlix to
things like our property grammars, but this is the last missing piece
in completing the set of useful combinators.  Anything else would have
much harder time justifying itself, as it's not filling a hole but
forging something new, so we shouldn't fear this opens the door to
even more hard-to-read stuff.

Thoughts?

~TJ

* Syntaxes:
0+, any order: a? || b?
1+, any order: a || b
all, any order: a && b
0+, in order: a? b?
1+, in order: _____
all, in order: a b
Received on Friday, 18 April 2014 00:28:31 UTC

This archive was generated by hypermail 2.3.1 : Friday, 18 April 2014 00:28:32 UTC