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

Re: [css3-values] calc(), whitespace, and DIMENSION tokens

From: Bert Bos <bert@w3.org>
Date: Mon, 17 Mar 2008 18:05:33 +0100
To: www-style@w3.org
Message-Id: <200803171805.33270.bert@w3.org>

On Wednesday 12 March 2008 13:41, Andrei Polushin wrote:
> 2008/3/12, fantasai wrote:
> >  I'll note that
> >    3cm-2cm
> >  will be parsed as a single DIMENSION token

I seem to remember that we discussed this during some meeting and 
concluded that white space (or a comment) would indeed be needed 
between a dimension and the following minus sign and that we would just 
have to warn users about that...

> >  and 
> >    3cm -2cm
> >  will be parsed as two DIMENSION tokens. Is that what we want? Is
> > whitespace required around minus and plus signs to treat them like
> > operators or is tokenization different inside calc() like it is
> > inside :nth-child()?
>
> I propose changing the grammar around the {ident} as follows:
>
>   nmstart   [_a-z]|{nonascii}|{escape}
>   nmchar    [_a-z0-9-]|{nonascii}|{escape}
>
>   alpha     [a-z]|{nonascii}|{escape}
>   alnum     [_a-z0-9]|{nonascii}|{escape}
>
>   restrict  {alpha}{alnum}*
>   simple    {nmstart}{nmchar}*
>   prefixed  [_-]{restrict}[-]{simple}
>   ident     {simple}|{prefixed}
>   unit      {restrict}|{prefixed}
>
>   %%
>
>   {num}{unit}   {return DIMENSION;}
>
> That is, the unit name cannot contain '-', unless that unit name
> starts with either '-' or '_', as described by
> http://www.w3.org/TR/2007/CR-CSS21-20070719/syndata.html#vendor-keywo
>rds

That will indeed make "3n-1" parse as DIMEN(3n) + DELIM(-) + NUMBER(1), 
but parsers still have to check that the DIMEN is a whole number with 
an "n" or "N"; and "n-1" remains an IDENT. (Of course, "n-1" won't 
occur very often in practice. :-) )

So I think there is no benefit for nth-child.

It also doesn't remove the need for a space after 'mod' in 'calc(10% 
mod-2em)', although it avoids many other possible user errors: 
calc(10em-2px).

But it's a change to the core grammar, a very dangerous thing to do:

1) Are there any vendor extensions that we don't know about and that do 
not have a dash after the vendor prefix? CSS 2.1 currently says they 
*should* have a dash, but Andrei's patch makes that into a *must*.

2) Are there any languages that use the CSS syntax and that use units 
with a dash? CSS itself doesn't have such units, but we shouldn't break 
something that relies on our promise to not change the syntax.

3) Is CSS itself never going to add units with a dash?



Bert
-- 
  Bert Bos                                ( W 3 C ) http://www.w3.org/
  http://www.w3.org/people/bos                               W3C/ERCIM
  bert@w3.org                             2004 Rt des Lucioles / BP 93
  +33 (0)4 92 38 76 92            06902 Sophia Antipolis Cedex, France
Received on Monday, 17 March 2008 17:06:11 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 27 April 2009 13:55:02 GMT