closure-stylesheets icon indicating copy to clipboard operation
closure-stylesheets copied to clipboard

Parsing Execption when combining multiple media queries features

Open mxab opened this issue 9 years ago • 8 comments

The following media query produces a parsing exception

@media screen and (color),(max-width: 60em) {
  .stuff {
    background-color: red;
  }
}
com.google.common.css.compiler.ast.GssParserException: Parse error in /../../style.css at line 1 column 26:
@media screen and (color), (max-width: 60em) {
                         ^

Caused by: com.google.common.css.compiler.ast.ParseException: Encountered " "," ", "" at line 1, column 26.
Was expecting one of:

As far as I know it should be valid css. I'm using 20140426

mxab avatar Jun 19 '15 20:06 mxab

Can you reproduce this with the latest version from GitHub?

iflan avatar Jun 25 '15 09:06 iflan

yes I do

mxab avatar Jun 25 '15 15:06 mxab

Our @media parsing is a bit fragile. I'm not going to have time to look at this in the near future, so if you can narrow down the problem, that would help. Otherwise, I'll get to this in about three weeks.

iflan avatar Jun 26 '15 06:06 iflan

Ok will do, for starters here is the stacktrace

Caused by: com.google.common.css.compiler.ast.GssParserException: Parse error in /path/to/style.css at line 1 column 26:
@media screen and (color), (max-width: 60em) {
                         ^

    at com.google.common.css.compiler.ast.GssParserCC.parse(GssParserCC.java:227)
    at com.google.common.css.compiler.ast.GssParserCC.parse(GssParserCC.java:247)
    at com.google.common.css.compiler.ast.AbstractGssParser.parseInternal(AbstractGssParser.java:56)
    at com.google.common.css.compiler.ast.GssParser.parse(GssParser.java:46)
    at com.google.common.css.compiler.ast.GssParser.parse(GssParser.java:42)
    at com.google.common.css.compiler.commandline.DefaultCommandLineCompiler.parseAndPrint(DefaultCommandLineCompiler.java:120)
    at com.google.common.css.compiler.commandline.DefaultCommandLineCompiler.compile(DefaultCommandLineCompiler.java:110)
    at com.google.common.css.compiler.commandline.DefaultCommandLineCompiler$compile.call(Unknown Source)
    at io.silksmith.css.gss.GSSTask.compile(GSSTask.groovy:104)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
    ... 56 more
Caused by: com.google.common.css.compiler.ast.ParseException: Encountered " "," ", "" at line 1, column 26.
Was expecting one of:
    ";" ...
    "{" ...
    <AND> ...
    <OR> ...
    <S> ...

    at com.google.common.css.compiler.ast.GssParserCC.generateParseException(GssParserCC.java:5062)
    at com.google.common.css.compiler.ast.GssParserCC.at_rule(GssParserCC.java:2964)
    at com.google.common.css.compiler.ast.GssParserCC.block(GssParserCC.java:3630)
    at com.google.common.css.compiler.ast.GssParserCC.start(GssParserCC.java:3723)
    at com.google.common.css.compiler.ast.GssParserCC.parse(GssParserCC.java:222)
    ... 65 more

Don't get confused by the gradle part in the callstack as I'm calling it from there

mxab avatar Jun 26 '15 06:06 mxab

I stumbled upon this problem when I wanted to rename the bootstrap css the @media screen and (color),(max-width: 60em) was simplified sample.

https://github.com/twbs/bootstrap/blob/master/dist/css/bootstrap.css#L6307

mxab avatar Jun 26 '15 06:06 mxab

Thanks for the pointers. I'll take a look as this is clearly a bug.

iflan avatar Oct 05 '15 08:10 iflan

I know this is an old thread, but I confirmed this bug still exists in some html validators, for example https://validator.w3.org/ . It doesn't like the comma-separated terms. The workaround I found is, remove the commas and create separate statements, for the example given by mxab above, use:

@media screen and (color) { .stuff {   background-color: red; } }
@media screen and (max-width: 60em) { .stuff {   background-color: red; } }

Hope this helps somebody.

codewavedave avatar Jun 24 '19 15:06 codewavedave

com.google.common.css.compiler.ast.GssParserException: Parse error in bootstrap-grid.css at line 8 column 24: width: device-width;

buckelieg avatar Jul 24 '20 14:07 buckelieg