Comments (5)
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.
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.
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.
Ok, thanks for the explication. Indeed the simple_selector_sequence production just includes HASH and not DELIM.
Thank you.
from parse-css.
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)
- Parser Question HOT 2
- UMD broke example.html HOT 1
- DELIM parsing confusion? HOT 1
- Generating CSS source code from the rule tree. HOT 9
- Doesn't work anymore: parse-css / test.html
- Refactoring: consumeA<Function|...>(...) should be <Func|...>.consumeFrom(...) HOT 2
- parseACommaSeparatedListOfComponentValues is unused HOT 2
- parseerror is defined two times, with conflicting signatures HOT 2
- Typo causing exception at consumeAQualifiedRule HOT 1
- Update or remove package.json HOT 2
- Inquiry: Should unicode escapes be idents HOT 2
- Strings with different starting and ending quote should be treated as invalid HOT 1
- Throw parse errors instead of just logging them to console HOT 3
- Wrong end character in consumeTheRemnantsOfABadURL HOT 1
- parser or example.html issues with nesting at-rules HOT 3
- `escapeIdentCode` doesn't exist. HOT 2
- `HashToken.type` is incorrect when it is an `id` HOT 3
- Some token types where removed but not entirely cleaned up
- `escapeIdent` seems to be a bit too eager
- Duplicate test case HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from parse-css.