From: Mika Murtojarvi Date: Tue, 11 Feb 2014 11:10:15 +0000 (+0200) Subject: Implement parenthesis-handling fixes for Sass in Vaadin 7.1 (#12834) X-Git-Tag: 7.1.12~22 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b008768;p=vaadin-framework.git Implement parenthesis-handling fixes for Sass in Vaadin 7.1 (#12834) These are the same changes that were done for the master-branch in (#12833). Change-Id: I397028c7b0ba06567adaad9f0f0095157f7ae8f9 Merge: no --- diff --git a/theme-compiler/src/com/vaadin/sass/internal/parser/Parser.java b/theme-compiler/src/com/vaadin/sass/internal/parser/Parser.java index ab0f6161d7..bc25042a5c 100644 --- a/theme-compiler/src/com/vaadin/sass/internal/parser/Parser.java +++ b/theme-compiler/src/com/vaadin/sass/internal/parser/Parser.java @@ -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 { diff --git a/theme-compiler/src/com/vaadin/sass/internal/parser/Parser.jj b/theme-compiler/src/com/vaadin/sass/internal/parser/Parser.jj index 9e1b781a6a..44e06a33b1 100644 --- a/theme-compiler/src/com/vaadin/sass/internal/parser/Parser.jj +++ b/theme-compiler/src/com/vaadin/sass/internal/parser/Parser.jj @@ -1445,7 +1445,7 @@ boolean isPseudoElement = false; } } } - | ( n= ( )* d=skipStatementUntilRightParan() + | ( n= ( )* d=skipStatementUntilMatchingRightParan() { // 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 index 0000000000..4e177b1149 --- /dev/null +++ b/theme-compiler/tests/resources/w3ctests/scss/css3-modsel-67.0.scss @@ -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 }