The following css will cause a parse error:
#stageList li:not(.memberStage) { display: none; }
The error is:
com.steadystate.css.dom.DOMExceptionImpl: Syntax error (Error in pseudo class or element. (Invalid token ".". Was expecting one of: <S>, ")".)) at com.steadystate.css.dom.CSSStyleSheetImpl.insertRule(CSSStyleSheetImpl.java:215)
Anonymous
Hi Ed,
looks like you have to use the CSS3 parser.
Have a look at http://cssparser.sourceforge.net/gettingStarted.html for the way to setup the different parsers.
Here is how I initialize the parser;
I've copied the full source below:
Strange, this works great here (without any errors/warings)
~~~~~~~~~~~~~~~~
final String css = "#stageList li:not(.memberStage) { display: none; }";
final CSSStyleSheet sheet = parse(css, 0, 0, 0);
final CSSRuleList rules = sheet.getCssRules();
Ok, can reproduce your issue, hopefully there is a quick fix.
The problem is (again) the star generated in front of a class condition.
When you like to set your parsed style back into a new object you style looks like
#stageList li:not(*.memberStage) { display: none; }
an then the star in front of the class selector .memberStage confuses the compiler.
Not that easy to fix. Because of my vacation a fix will be available at the end of october. Maybe you have to do some regex magic as workaround.
Last edit: RBRi 2015-10-05
Please try the lastest snapshot
Please try with the latest snapshot.
fixed in 0.9.18
Reopening due to regression.
In 0.9.23, the original expression fails again. More cases that fail: X:not(.foo); X:not(bar.foo); ...
There are many unit test for various not cases (com.steadystate.css.parser.SACParserCSS3Test.not()) Please make sure you are using the CSS3Parser because this not stuff is a css3 feature.
e.g. CSSOMParser parser = new CSSOMParser(new SACParserCSS3());
@Herwig: any update on this?
No, sorry. When trying the CSS3 parser model, I ran into the next issue right away (don't remember, what it was, sorry). I needed to move on with my project and wrote my own parser for the use case I had.
If you want to make this library useful for modern CSS, I'd suggest creating a test suite from real-world CSS files, that people might want to parse (and emit in a modified form). E.g. in https://www.muicss.com/, you won't have to look very far, to find breaking cases.
Have added miu.css to our real world example suite works without any error/or warning. There are still many places where we have to fix cssparser but keep in mind this is an opens source project maintained in my spare time. If you are able to write your own parser why not providing some patches to make this more useful.
Thanks for your feedback, will close this issue.
If you will ever try cssparser again and you are facing issues please open a new one.