]> source.dussan.org Git - vaadin-framework.git/commitdiff
Implement parenthesis-handling fixes for Sass in Vaadin 7.1 (#12834)
authorMika Murtojarvi <mika@vaadin.com>
Tue, 11 Feb 2014 11:10:15 +0000 (13:10 +0200)
committerVaadin Code Review <review@vaadin.com>
Thu, 13 Feb 2014 07:58:42 +0000 (07:58 +0000)
These are the same changes that were done for the master-branch in
(#12833).

Change-Id: I397028c7b0ba06567adaad9f0f0095157f7ae8f9
Merge: no

theme-compiler/src/com/vaadin/sass/internal/parser/Parser.java
theme-compiler/src/com/vaadin/sass/internal/parser/Parser.jj
theme-compiler/tests/resources/w3ctests/scss/css3-modsel-67.0.scss [new file with mode: 0644]

index ab0f6161d79370436fc6fabadf6a04c02d5d3744..bc25042a5c9e19a8bc696f3a30895d1a59cf6d0b 100644 (file)
@@ -2667,7 +2667,7 @@ boolean isPseudoElement = false;
         }
         jj_consume_token(S);
       }
-      d = skipStatementUntilRightParan();
+      d = skipStatementUntilMatchingRightParan();
       jj_consume_token(RPARAN);
                   // accept anything between function and a right parenthesis
                   String f = convertIdent(n.image);
@@ -6202,9 +6202,35 @@ LexicalUnitImpl result = null;
     return skipStatementUntil(lBrace);
   }
 
-  String skipStatementUntilRightParan() throws ParseException {
-    int[] rParan = {RPARAN};
-    return skipStatementUntil(rParan);
+  String skipStatementUntilMatchingRightParan() throws ParseException {
+    int[] leftTokens = {LPARAN, FUNCTION}; // a FUNCTION also contains "("
+    int[] rightTokens = {RPARAN};
+    StringBuffer s = new StringBuffer();
+    int difference = 1;
+    Token tok;
+    while(difference != 0){
+        tok = getToken(1);
+        if(tok.kind == EOF) {
+            return null;
+        }
+        for(int sym : leftTokens){
+            if(tok.kind == sym){
+                difference++;
+            }
+        }
+        for(int sym : rightTokens){
+            if(tok.kind == sym){
+                difference--;
+            }
+        }
+        if(difference != 0){
+            if (tok.image != null) {
+                s.append(tok.image);
+            }
+            getNextToken();
+        }
+    }
+    return s.toString().trim();
   }
 
   String skipStatementUntil(int[] symbols) throws ParseException {
index 9e1b781a6a45ceb1b63bb918b985763fdc2ea04d..44e06a33b12cf14bf8433aa8c5c119e7f4a22f41 100644 (file)
@@ -1445,7 +1445,7 @@ boolean isPseudoElement = false;
                }
            }
        }
-         | ( n=<FUNCTION> ( <S> )* d=skipStatementUntilRightParan() <RPARAN>
+         | ( n=<FUNCTION> ( <S> )* d=skipStatementUntilMatchingRightParan() <RPARAN>
                  {
                  // accept anything between function and a right parenthesis
                  String f = convertIdent(n.image);
@@ -2842,9 +2842,35 @@ String skipStatementUntilLeftBrace(){
 }
 
 JAVACODE
-String skipStatementUntilRightParan(){
-    int[] rParan = {RPARAN};
-    return skipStatementUntil(rParan);
+String skipStatementUntilMatchingRightParan(){
+    int[] leftTokens = {LPARAN, FUNCTION}; // a FUNCTION also contains "("
+    int[] rightTokens = {RPARAN};
+    StringBuffer s = new StringBuffer();
+    int difference = 1;
+    Token tok;
+    while(difference != 0){
+        tok = getToken(1);
+        if(tok.kind == EOF) {
+            return null;
+        }
+        for(int sym : leftTokens){
+            if(tok.kind == sym){
+                difference++;
+            }
+        }
+        for(int sym : rightTokens){
+            if(tok.kind == sym){
+                difference--;
+            }
+        }
+        if(difference != 0){
+            if (tok.image != null) {
+                s.append(tok.image);
+            }
+            getNextToken();
+        }
+    }
+    return s.toString().trim();
 }
 
 JAVACODE
diff --git a/theme-compiler/tests/resources/w3ctests/scss/css3-modsel-67.0.scss b/theme-compiler/tests/resources/w3ctests/scss/css3-modsel-67.0.scss
new file mode 100644 (file)
index 0000000..4e177b1
--- /dev/null
@@ -0,0 +1,3 @@
+/* Source: http://www.w3.org/Style/CSS/Test/CSS3/Selectors/current/html/tests/css3-modsel-67.html */
+div.stub * { background-color : red  }
+div.stub *:not(:lang(fr)) { background-color : green }