From 6c6dee39fd92191a3cb5f36e975a0c3996dc48d5 Mon Sep 17 00:00:00 2001 From: "Michael[tm] Smith" Date: Sat, 16 Dec 2017 09:34:58 +0900 Subject: [PATCH] Treat starts-with-dash at rules as vendor-prefixed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change makes the checker handle at-rules such as @-ms-viewport and @-webkit-keyframes as vendor extensions — which means, if the checker is run with the option to treat vendor extension as warnings, the messages for those cases are now emitted as warnings instead of as errors. --- org/w3c/css/parser/analyzer/CssParser.java | 118 ++++++++++++--------- org/w3c/css/parser/analyzer/CssParser.jj | 21 +++- org/w3c/css/util/Messages.properties.en | 1 + 3 files changed, 83 insertions(+), 57 deletions(-) diff --git a/org/w3c/css/parser/analyzer/CssParser.java b/org/w3c/css/parser/analyzer/CssParser.java index c88f9d08e..a5b090a04 100644 --- a/org/w3c/css/parser/analyzer/CssParser.java +++ b/org/w3c/css/parser/analyzer/CssParser.java @@ -2295,13 +2295,25 @@ final public void ignoreStatement() throws ParseException { */ final public void atRuleDeclaration() throws ParseException {Token n; n = jj_consume_token(ATKEYWORD); -//ac.getFrame().addWarning("at-rule", token.toString()); - ac.getFrame().addError( - new CssError(new InvalidParamException("at-rule", - token, ac))); +if (n.toString().charAt(1) == '-') { + if (ac.getTreatVendorExtensionsAsWarnings()) { + ac.getFrame() // + .addWarning("at-rule", // + n.toString()); + } else { + addAtRuleError(); + } + } else { + addAtRuleError(); + } skipStatement(); } + void addAtRuleError() throws ParseException {// + ac.getFrame().addError(new CssError(new InvalidParamException( // + "at-rule", token, ac))); + } + /** * @exception ParseException exception during the parse */ @@ -5295,55 +5307,6 @@ private boolean jj_2_5(int xla) finally { jj_save(4, xla); } } - private boolean jj_3R_126() - { - if (jj_scan_token(S)) return true; - return false; - } - - private boolean jj_3R_122() - { - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_126()) { jj_scanpos = xsp; break; } - } - if (jj_scan_token(MINUS)) return true; - return false; - } - - private boolean jj_3_5() - { - if (jj_3R_125()) return true; - if (jj_scan_token(LPARAN)) return true; - return false; - } - - private boolean jj_3R_130() - { - if (jj_3R_138()) return true; - if (jj_3R_129()) return true; - return false; - } - - private boolean jj_3R_182() - { - if (jj_3R_127()) return true; - return false; - } - - private boolean jj_3_2() - { - if (jj_scan_token(NUMBER)) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_scan_token(21)) { jj_scanpos = xsp; break; } - } - if (jj_scan_token(DIV)) return true; - return false; - } - private boolean jj_3R_125() { if (jj_3R_129()) return true; @@ -5912,6 +5875,55 @@ private boolean jj_3R_138() return false; } + private boolean jj_3R_126() + { + if (jj_scan_token(S)) return true; + return false; + } + + private boolean jj_3R_122() + { + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_126()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(MINUS)) return true; + return false; + } + + private boolean jj_3_5() + { + if (jj_3R_125()) return true; + if (jj_scan_token(LPARAN)) return true; + return false; + } + + private boolean jj_3R_130() + { + if (jj_3R_138()) return true; + if (jj_3R_129()) return true; + return false; + } + + private boolean jj_3R_182() + { + if (jj_3R_127()) return true; + return false; + } + + private boolean jj_3_2() + { + if (jj_scan_token(NUMBER)) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_scan_token(21)) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(DIV)) return true; + return false; + } + /** Generated Token Manager. */ public CssParserTokenManager token_source; SimpleCharStream jj_input_stream; diff --git a/org/w3c/css/parser/analyzer/CssParser.jj b/org/w3c/css/parser/analyzer/CssParser.jj index 851c2ffd0..2f4606c2b 100644 --- a/org/w3c/css/parser/analyzer/CssParser.jj +++ b/org/w3c/css/parser/analyzer/CssParser.jj @@ -1500,14 +1500,27 @@ void atRuleDeclaration() : { n= { - //ac.getFrame().addWarning("at-rule", token.toString()); - ac.getFrame().addError( - new CssError(new InvalidParamException("at-rule", - token, ac))); + if (n.toString().charAt(1) == '-') { + if (ac.getTreatVendorExtensionsAsWarnings()) { + ac.getFrame() // + .addWarning("at-rule", // + n.toString()); + } else { + addAtRuleError(); + } + } else { + addAtRuleError(); + } skipStatement(); } } +JAVACODE +void addAtRuleError() { // + ac.getFrame().addError(new CssError(new InvalidParamException( // + "at-rule", token, ac))); +} + /** * @exception ParseException exception during the parse */ diff --git a/org/w3c/css/util/Messages.properties.en b/org/w3c/css/util/Messages.properties.en index 62a5a7a4e..077920785 100644 --- a/org/w3c/css/util/Messages.properties.en +++ b/org/w3c/css/util/Messages.properties.en @@ -186,6 +186,7 @@ warning.relative: Using relative units gives more robust stylesheets in property # used by org.w3c.css.css.StyleSheetParser and org.w3c.css.css.StyleSheetXMLParser error.at-rule: Unrecognized at-rule %s +warning.at-rule: Unrecognized at-rule %s # used by all properties and values error.operator: %s is an incorrect operator