[css-values] Adding a <length-percentage> production

At TPAC, in the unofficial Houdini meetup on Thursday, we realized
that our property grammars were kinda ambiguous, and that was
troublesome for the Custom Properties API.  In particular, when you
see a grammar like "<length> | <percentage>", it's not clear whether
the <percentage> is a distinct type, or a length-equivalent type.
This is an important distinction, because the latter allows `calc(5px
+ 10%)`, but the former does not.  CSS has examples of both: most
instances are the latter, but 'word-spacing' is the former, and
'background-position' is *technically* the former, but we hack things
around to make it work like the latter anyway.  CSS currently resolves
the ambiguity with prose (the "Percentages" line in the

The solution we hit on in the meeting was to define a new grammar
non-terminal, <length-percentage>, that indicates the
"length-equivalent" percentage case.  This also simplifies grammars -
I've always been slightly, vaguely annoyed at the clumsiness that "[
<length> | <percentage> ]" introduces into my grammars, and this
simplifies things a bit.

We'll need similar non-terminals for the other base types: frequence,
angle, time, and number.  I don't think we need a non-terminal for the
length-percentage-number triplet that line-height uses - that "number"
case probably should really have been a new unit that was a
used-value-time 'em'.

So, I plan to add these to V&U. Specs can gradually adopt it - the
current grammars are non-ambiguous due to the accompanying prose.
This is just an attempt to slightly simplify CSS, and make sure that
Houdini and CSS grow together.

Thoughts?

~TJ

Received on Thursday, 10 December 2015 19:06:24 UTC