[CSS21] Grammar Errors

Hello,
I'm implementing a CSS parser, and I've noticed some errors in the
grammar that don't appear to be documented in the CSS 2.1
errata. They are to do with the hexcolor definitions.

In section 4.3.6 Colors
The format of an RGB value in hexadecimal notation is a '#'
immediately followed by either three or six hexadecimal characters.


In Appendix G. Grammar of CSS 2.1

/*
 * There is a constraint on the color that it must
 * have either 3 or 6 hex-digits (i.e., [0-9a-fA-F])
 * after the "#"; e.g., "#000" is OK, but "#abcd" is not.
 */
hexcolor
 : HASH S*
 ;

"#"{name}               {return HASH;}
name            {nmchar}+
nmchar          [_a-z0-9-]|{nonascii}|{escape}


Now there are quite a few errors in the Appendix.

1. The grammar is case insensitive, so the comment shows a redundant A-F.
2. nmchar is not defined as [0-9a-f], it's much less restrictive
allowing a whole host of non-hex characters to be present.
3. the definition for {name} appears to allow 1 or more hex digits
(not the 3 or 6 specified elsewhere)
4. similar to comment 3, the other groups {nonascii}, {escape} will
also have invalid lengths

So in summary, the grammar for hexcolor needs to be completely
separated from the grammar for HASH as there is no sensible reuse
possible here.


I can also point out that the grammar could be made more consistent if
the trailing whitespace on 'hexcolor' and 'function' was moved into
the term block as follows:-

term
 : unary_operator?
   [ NUMBER S* | PERCENTAGE S* | LENGTH S* | EMS S* | EXS S* | ANGLE S* |
     TIME S* | FREQ S* ]
 | STRING S* | IDENT S* | URI S* | hexcolor S* | function S*
function
 : FUNCTION S* expr ')'
hexcolor
 : HASH



Best Regards,
Mark.

Received on Monday, 30 August 2010 06:31:21 UTC