Open flavorjones opened 2 years ago
I've looked at Crass a bit yesterday and today, but it's not returning a fine-enough-grained AST for selectors; we'd have to use the tokens and implement some sort of parser to make it work.
Looking at syntax_tree-css, it's incomplete but is definitely a well-formed AST for selectors. I've started kicking the tires and making basic improvements to see how far I can take it.
PRs against syntax_tree-css to get it to where we can integrate it:
PRs against nokogiri with this goal in mind:
More PRs against Nokogiri (broke up #3218 as too-big):
I've got a branch where the hand-written parser work is progressing, in case anybody wants to follow along: https://github.com/sparklemotion/nokogiri/tree/2560-start-custom-css-parser
The CSS selector parser we have is complex, and selector parsing is really a separable concern from Nokogiri proper. It would be nice if we were able to use an existing parser.
(Side note: the generation of XPath from the CSS is a Nokogiri concern, though, since the generated xpath query is often tightly coupled to the version of libxml or the C extension. Perhaps we can spin this off as a separate gem/concern at some point, but it would need to be pluggable to do nokogiri-specific xpath things and I don't feel like that's worth the effort right now.)
Some things to look at that generate ASTs for CSS:
I'd also like to fix some outstanding bugs in the current implementation:
3238
652
628
707
though, note that the behavior changes to fix these bugs probably justify a 2.0 major release, because it's going to break existing apps.
And then I think we can also introduce some new features:
2036
1889
3207