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

2008/3/12, fantasai wrote:
>  I'll note that
>    3cm-2cm
>  will be parsed as a single DIMENSION token 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-keywords

In addition, such grammar treats the '-' before the {ident} as a MINUS
SIGN, unless the {ident} itself contains '-' (see the example with
"-max()" below).

Tokenization examples:

    :nth-child(3n-1)

        => OK: ':' FUNCTION(nth-child) DIMENSION(3n) '-' NUMBER(1) ')'

    3cm-2cm

        => OK:  DIMENSION(3cm) '-' DIMENSION(2cm)

    3-x-parsec-2-x-angstrom
        /* -x-parsec and -x-angstrom are vendor-specific unit names */

        => BAD: DIMENSION(3-x-parsec-2-x-angstrom)

    3-x-parsec -2-x-angstrom

        => OK: DIMENSION(3-x-parsec) '-' DIMENSION(2-x-angstrom)

    calc(3em-max(1em,9px))

        => OK: FUNCTION(calc) DIMENSION(3em) '-'
               FUNCTION(max)  DIMENSION(1em) ','
                              DIMENSION(9px) ')' ')'

Note that tokenization is *context-free*, it can be used in equally
incontext of 'calc', or in context of 'nth-child', or out of them.

The patch for the scanner grammar is attached.

--
Andrei Polushin

Received on Wednesday, 12 March 2008 12:41:33 UTC