Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HASH - IDENT multiple matches #15

Closed
mirceapiturca opened this issue Jan 10, 2013 · 5 comments
Closed

HASH - IDENT multiple matches #15

mirceapiturca opened this issue Jan 10, 2013 · 5 comments

Comments

@mirceapiturca
Copy link

Giving the following rule:

id {top:1px}

The tokenizer returns a HashToken for the "#id" selector. This does not seems to be the correct behavior. It should return an IDENT token since according to the http://www.w3.org/TR/css3-syntax/#tokenization :
"In case of multiple matches, the longest match determines the token."

Also a HashToken may be invalid in a selector because it can contain a num as the first character - Illegal in an ID selector.

I think that this should be returned:

id {top:1px} - IDENT

1id {top:1px} - HASH

Thank you.

@tabatkins
Copy link
Owner

I don't understand what you mean. The only possible tokens that can start with a # are DELIM and HASH. The HASH token, as it would consume three characters to the DELIM's one, wins.

I have no idea what you mean by claiming that the ident token would produce a longer match. IDENT tokens can't start with a #, so they seem irrelevant.

The correct sequence of tokens for "#id {top:1px}" is:

HASH(#id)
WS
{
IDENT(top)
:
DIMENSION(1,px)
}

@mirceapiturca
Copy link
Author

Thanks for the fast response. I do understand what you are saying and I am probably not explaining myself correctly.

According to : 6.5. ID selectors
http://www.w3.org/TR/selectors/#id-selectors

"An ID selector contains a "number sign" (U+0023, #) immediately followed by the ID value, which must be an CSS identifiers."

The sequence of tokens for "#id {top:1px}" is:
HASH(#id) WS...

The sequence of tokens for "#123id {top:1px}" is:
HASH(#123id) WS...

Both have the same HASH token in selectors but only one selector in valid as the other one starts with a number: #123id. So in order to validate an id selector you would need "#" IDENT.

I can not find the productions for ids, classes and elements are clearly specified like this at http://www.w3.org/TR/selectors/#w3cselgrammar:

element_name
: IDENT
;

class
: '.' IDENT
;

Thank you.

@tabatkins
Copy link
Owner

In order to validate an ID selector, you need different rules than what you use to parse an ID selector. "#123id" is a perfectly fine HASH token, but it's an invalid id selector. There's nothing wrong with that disconnect, as the two concepts live at different levels. It's similar to how a property name must be a valid property name from the list of known CSS properties, but the grammar only constrains it to being an "ident".

The sequence of tokens DELIM(#) IDENT can not occur in the CSS parser, because # followed by a character is just a HASH token.

Note that in the Selectors 3 grammar, the grammar for the simple_selector_sequence production just includes HASH directly, rather than having a separate "id" production.

@mirceapiturca
Copy link
Author

Ok, thanks for the explication. Indeed the simple_selector_sequence production just includes HASH and not DELIM.
Thank you.

@mirceapiturca
Copy link
Author

EDIT:
After realizing that a DELIM(#) IDENT sequence can not exist in the CSS parser and that the simple_selector_sequence production just includes HASH, I found this errata proposal from Kang-Hao (Kenny) Lu: http://lists.w3.org/Archives/Public/www-style/2012Jun/0400.html witch satisfy the id validation condition (constraint) of having an IDENT matching after "#"... even if its a HASH token.

| /*
| * There is a constraint on the ID selector that the part after
| * "#" should match an IDENT; e.g., "#abc" is OK, but "#1st" is not.
| */

Also filed here: https://www.w3.org/Bugs/Public/show_bug.cgi?id=17511

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants