RE: [CSS2.1] Any hope of fixing HASH #{name} to disallow numeric identifiers?

So it is the overload of HASH as a token for use in selectors and in the specification of colors (and potentially other unknown dimensions as the spec points out). Per the below line, it might be nice to point out why the token HASH is used in all of the grammar following through from HASH -> "#"{nmchar} and following all the way through simple_selector -> ... HASH ... It makes more sense to deconstruct the HASH token into two separate tokens where Token_Hash is equal "#" and you simply paste this token onto the desired end part like ident or name.

I realize this is a day late and a dollar short, but if any guidance can be given at the spec level it prevents a lot of odd conversations of having to explain the complexities to people and why ID selectors can't contain numbers (I can't explain how many bug reports I get on either side of this fence).

---
5.9 ID Selectors

A CSS ID selector contains a "#" immediately followed by the ID value, which must be an identifier.
---

-----Original Message-----
From: L. David Baron [mailto:dbaron@dbaron.org]
Sent: Friday, January 18, 2008 5:37 PM
To: Justin Rogers
Cc: www-style@w3.org
Subject: Re: [CSS2.1] Any hope of fixing HASH #{name} to disallow numeric identifiers?

On Friday 2008-01-18 17:11 -0800, Justin Rogers wrote:
> While going through the W3 CSS validator something along the lines of:
>
> #4 { color: green; }
>
> Doesn't pass with a cryptic error message about CSS1 and CSS2
> rules for identifiers, but has no mention of CSS2.1. The CSS2.1
> "sample" grammar allows for {name} to be {nmchar}+, which
> specifically allows digits. A failure when parsing means error
> recovery as opposed to a rule that might never match (for
> instance, if #4 is an allowed selector, but is a disallowed id in
> the document language is much different from #4 being a syntax
> error). If we truly support only support {ident} then we should
> change this stuff over so it is obvious the errant use of a
> numeric value will cause.
>
> It is quite obvious that browsers support {ident} here and not
> {name}. FireFox will throw out the rules for {name} and won't even
> show them in the OM. They'll allow rules such as:

There are plenty of constraints in the spec that are parse-time
errors but aren't expressed in the grammar.  If the validator's
message is confusing or incorrect, that may well be a bug in the
validator (which is definitely *not* a reference implementation).

The token in the formal syntax (both the one in Chapter 4 and the
one in Appendix G) needs to allow initial numbers for color values
(where they are allowed), but they're not allowed in ID selectors.

The current state of the spec *should* be that #4 as an ID selector
is a syntax error, but it's not the formal grammar that says so but
rather the prose in the selectors chapter (combined with the
statement in 4.1.7 that "When a user agent can't parse the selector
(i.e., it is not valid CSS 2.1), it must ignore the declaration
block as well.").

-David

--
L. David Baron                                 http://dbaron.org/
Mozilla Corporation                       http://www.mozilla.com/

Received on Saturday, 19 January 2008 02:04:54 UTC