Git Product home page Git Product logo

Comments (5)

tabatkins avatar tabatkins commented on June 30, 2024

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)
}

from parse-css.

mirceapiturca avatar mirceapiturca commented on June 30, 2024

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.

from parse-css.

tabatkins avatar tabatkins commented on June 30, 2024

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.

from parse-css.

mirceapiturca avatar mirceapiturca commented on June 30, 2024

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

from parse-css.

mirceapiturca avatar mirceapiturca commented on June 30, 2024

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

from parse-css.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.