Skip to content

Commit 1e859ff

Browse files
authored
Merge pull request #485 from w3c/env
env() support
2 parents a930558 + 0505088 commit 1e859ff

File tree

9 files changed

+1629
-841
lines changed

9 files changed

+1629
-841
lines changed

org/w3c/css/parser/analyzer/CssParser.java

Lines changed: 998 additions & 778 deletions
Large diffs are not rendered by default.

org/w3c/css/parser/analyzer/CssParser.jj

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import org.w3c.css.values.CssCalc;
6767
import org.w3c.css.values.CssCheckableValue;
6868
import org.w3c.css.values.CssColor;
6969
import org.w3c.css.values.CssComparator;
70+
import org.w3c.css.values.CssEnv;
7071
import org.w3c.css.values.CssExpression;
7172
import org.w3c.css.values.CssFlexibleLength;
7273
import org.w3c.css.values.CssFrequency;
@@ -429,6 +430,10 @@ public abstract class CssParser {
429430
if (v.getType() == CssTypes.CSS_VARIABLE) {
430431
expr.markCssVariable();
431432
}
433+
} else if ( token == FUNCTIONENV ) {
434+
if (v.getType() == CssTypes.CSS_ENV) {
435+
expr.markCssVariable();
436+
}
432437
} else if ( token == FUNCTIONCALC ) {
433438
CssCalc c = (CssCalc) v;
434439
if (c.hasCssVariable()) {
@@ -781,6 +786,7 @@ TOKEN [IGNORE_CASE] :
781786
| <FUNCTIONCLAMP : "clamp(" >
782787
| <FUNCTIONATTR : "attr(" >
783788
| <FUNCTIONVAR : "var(" >
789+
| <FUNCTIONENV : "env(" >
784790
}
785791

786792
<DEFAULT>
@@ -3191,6 +3197,7 @@ void term(CssExpression exp) :
31913197
| func=mathclamp() { setValue(func, exp, operator, null, FUNCTION); }
31923198
| func=attr() { setValue(func, exp, operator, null, FUNCTION); }
31933199
| func=functionvar() { setValue(func, exp, operator, null, FUNCTIONVAR); }
3200+
| func=functionenv() { setValue(func, exp, operator, null, FUNCTIONENV); }
31943201
| func=function() { setValue(func, exp, operator, null, FUNCTION); }
31953202
| n=<STRING> { setValue(new CssString(), exp, operator, n, STRING); }
31963203
| n=<DIV> { setValue(new CssSwitch(), exp, operator, n, DIV); }
@@ -3510,6 +3517,11 @@ CssCheckableValue mathproduct() :
35103517
c.markCssVariable();
35113518
}
35123519
}
3520+
| v2=functionenv() {
3521+
if (v2.getType() == CssTypes.CSS_ENV) {
3522+
c.markCssVariable();
3523+
}
3524+
}
35133525
)
35143526
)
35153527
) {
@@ -3621,6 +3633,7 @@ char operator = ' ';
36213633
| v=mathclamp()
36223634
| v=attr()
36233635
| v=functionvar()
3636+
| v=functionenv()
36243637
) {
36253638
return v;
36263639
}
@@ -3646,6 +3659,38 @@ CssExpression exp = null;
36463659
}
36473660
}
36483661

3662+
CssCheckableValue functionenv() :
3663+
{ Token n;
3664+
CssExpression exp = null;
3665+
CssExpression e;
3666+
CssEnv env = null;
3667+
String skipped = null;
3668+
}
3669+
{
3670+
<FUNCTIONENV> ( <S> )* n=<IDENT> ( <S> )* {
3671+
env = new CssEnv(ac, convertIdent(n.image));
3672+
e = new CssExpression();
3673+
}
3674+
( term(e) )*
3675+
( <COMMA> ( <S> )* try {
3676+
exp = expr()
3677+
} catch (ParseException pe) {
3678+
skipped = skip_to_matching_paren();
3679+
// FIXME do something meaningful with that string
3680+
exp = null;
3681+
}
3682+
)? <RPAREN>
3683+
{
3684+
env.setNumberExp(e);
3685+
if (exp != null) {
3686+
env.setDeclaration(exp);
3687+
} else if (skipped != null) {
3688+
// do something fancy here
3689+
}
3690+
return env;
3691+
}
3692+
}
3693+
36493694
CssCheckableValue functionvar() :
36503695
{ Token n;
36513696
CssExpression exp = null;
@@ -3946,6 +3991,7 @@ String skip_to_matching_paren() {
39463991
case FUNCTIONROUND:
39473992
case FUNCTIONATTR:
39483993
case FUNCTIONVAR:
3994+
case FUNCTIONENV:
39493995
s.append(tok.image);
39503996
nesting++;
39513997
getNextToken();

org/w3c/css/parser/analyzer/CssParserConstants.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,13 @@ public interface CssParserConstants {
295295
/** RegularExpression Id. */
296296
int FUNCTIONVAR = 142;
297297
/** RegularExpression Id. */
298-
int FUNCTION = 143;
298+
int FUNCTIONENV = 143;
299299
/** RegularExpression Id. */
300-
int HTMLSTARTTAG = 144;
300+
int FUNCTION = 144;
301301
/** RegularExpression Id. */
302-
int HTMLENDTAG = 145;
302+
int HTMLSTARTTAG = 145;
303+
/** RegularExpression Id. */
304+
int HTMLENDTAG = 146;
303305

304306
/** Lexical state. */
305307
int DEFAULT = 0;
@@ -449,6 +451,7 @@ public interface CssParserConstants {
449451
"\"clamp(\"",
450452
"\"attr(\"",
451453
"\"var(\"",
454+
"\"env(\"",
452455
"<FUNCTION>",
453456
"<HTMLSTARTTAG>",
454457
"<HTMLENDTAG>",

org/w3c/css/parser/analyzer/CssParserTokenManager.java

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.w3c.css.values.CssCheckableValue;
4848
import org.w3c.css.values.CssColor;
4949
import org.w3c.css.values.CssComparator;
50+
import org.w3c.css.values.CssEnv;
5051
import org.w3c.css.values.CssExpression;
5152
import org.w3c.css.values.CssFlexibleLength;
5253
import org.w3c.css.values.CssFrequency;
@@ -79,6 +80,7 @@
7980
import java.util.ArrayList;
8081

8182
/** Token Manager. */
83+
@SuppressWarnings ("unused")
8284
public class CssParserTokenManager implements CssParserConstants {
8385

8486
/** Debug output. */
@@ -95,16 +97,16 @@ private int jjMoveStringLiteralDfa0_0(){
9597
switch(curChar)
9698
{
9799
case 33:
98-
jjmatchedKind = 146;
100+
jjmatchedKind = 147;
99101
return jjMoveNfa_0(7, 0);
100102
case 36:
101-
jjmatchedKind = 147;
103+
jjmatchedKind = 148;
102104
return jjMoveStringLiteralDfa1_0(0x1000000000000L, 0x0L, 0x0L);
103105
case 37:
104-
jjmatchedKind = 148;
106+
jjmatchedKind = 149;
105107
return jjMoveNfa_0(7, 0);
106108
case 38:
107-
jjmatchedKind = 149;
109+
jjmatchedKind = 150;
108110
return jjMoveNfa_0(7, 0);
109111
case 40:
110112
jjmatchedKind = 58;
@@ -131,13 +133,13 @@ private int jjMoveStringLiteralDfa0_0(){
131133
jjmatchedKind = 51;
132134
return jjMoveNfa_0(7, 0);
133135
case 60:
134-
jjmatchedKind = 152;
135-
return jjMoveStringLiteralDfa1_0(0x800000L, 0x0L, 0x4000000L);
136+
jjmatchedKind = 153;
137+
return jjMoveStringLiteralDfa1_0(0x800000L, 0x0L, 0x8000000L);
136138
case 61:
137139
jjmatchedKind = 50;
138140
return jjMoveNfa_0(7, 0);
139141
case 63:
140-
jjmatchedKind = 151;
142+
jjmatchedKind = 152;
141143
return jjMoveNfa_0(7, 0);
142144
case 64:
143145
return jjMoveStringLiteralDfa1_0(0x0L, 0x1fffffff8000L, 0x0L);
@@ -150,7 +152,7 @@ private int jjMoveStringLiteralDfa0_0(){
150152
case 94:
151153
return jjMoveStringLiteralDfa1_0(0x800000000000L, 0x0L, 0x0L);
152154
case 96:
153-
jjmatchedKind = 150;
155+
jjmatchedKind = 151;
154156
return jjMoveNfa_0(7, 0);
155157
case 65:
156158
case 97:
@@ -161,6 +163,9 @@ private int jjMoveStringLiteralDfa0_0(){
161163
case 68:
162164
case 100:
163165
return jjMoveStringLiteralDfa1_0(0x0L, 0x200000000000000L, 0x0L);
166+
case 69:
167+
case 101:
168+
return jjMoveStringLiteralDfa1_0(0x0L, 0x0L, 0x8000L);
164169
case 72:
165170
case 104:
166171
return jjMoveStringLiteralDfa1_0(0x0L, 0xd000000000000000L, 0x0L);
@@ -189,7 +194,7 @@ private int jjMoveStringLiteralDfa0_0(){
189194
case 119:
190195
return jjMoveStringLiteralDfa1_0(0x0L, 0x800000000000000L, 0x0L);
191196
case 124:
192-
jjmatchedKind = 153;
197+
jjmatchedKind = 154;
193198
return jjMoveStringLiteralDfa1_0(0x4000000L, 0x0L, 0x0L);
194199
case 125:
195200
jjmatchedKind = 46;
@@ -244,9 +249,9 @@ else if ((active0 & 0x2000000000000L) != 0L)
244249
jjmatchedKind = 49;
245250
jjmatchedPos = 1;
246251
}
247-
else if ((active2 & 0x4000000L) != 0L)
252+
else if ((active2 & 0x8000000L) != 0L)
248253
{
249-
jjmatchedKind = 154;
254+
jjmatchedKind = 155;
250255
jjmatchedPos = 1;
251256
}
252257
break;
@@ -279,7 +284,7 @@ else if ((active2 & 0x4000000L) != 0L)
279284
return jjMoveStringLiteralDfa2_0(active0, 0L, active1, 0x800000000L, active2, 0L);
280285
case 78:
281286
case 110:
282-
return jjMoveStringLiteralDfa2_0(active0, 0x2800000000L, active1, 0x400000000L, active2, 0L);
287+
return jjMoveStringLiteralDfa2_0(active0, 0x2800000000L, active1, 0x400000000L, active2, 0x8000L);
283288
case 79:
284289
case 111:
285290
return jjMoveStringLiteralDfa2_0(active0, 0x4000000000L, active1, 0xc000000000000000L, active2, 0x840L);
@@ -382,6 +387,9 @@ private int jjMoveStringLiteralDfa2_0(long old0, long active0, long old1, long a
382387
case 85:
383388
case 117:
384389
return jjMoveStringLiteralDfa3_0(active0, 0L, active1, 0x80000000000L, active2, 0x800L);
390+
case 86:
391+
case 118:
392+
return jjMoveStringLiteralDfa3_0(active0, 0L, active1, 0L, active2, 0x8000L);
385393
default :
386394
break;
387395
}
@@ -417,6 +425,11 @@ else if ((active2 & 0x4000L) != 0L)
417425
jjmatchedKind = 142;
418426
jjmatchedPos = 3;
419427
}
428+
else if ((active2 & 0x8000L) != 0L)
429+
{
430+
jjmatchedKind = 143;
431+
jjmatchedPos = 3;
432+
}
420433
break;
421434
case 45:
422435
if ((active0 & 0x800000L) != 0L)
@@ -1747,8 +1760,8 @@ else if (curChar == 62)
17471760
jjstateSet[jjnewStateCnt++] = 90;
17481761
break;
17491762
case 98:
1750-
if (curChar == 62 && kind > 144)
1751-
kind = 144;
1763+
if (curChar == 62 && kind > 145)
1764+
kind = 145;
17521765
break;
17531766
case 100:
17541767
if ((0xfc00ffffffffcbffL & l) != 0L)
@@ -2148,8 +2161,8 @@ else if (curChar == 62)
21482161
jjstateSet[jjnewStateCnt++] = 209;
21492162
break;
21502163
case 217:
2151-
if (curChar == 62 && kind > 145)
2152-
kind = 145;
2164+
if (curChar == 62 && kind > 146)
2165+
kind = 146;
21532166
break;
21542167
case 219:
21552168
if ((0xfc00ffffffffcbffL & l) != 0L)
@@ -3069,8 +3082,8 @@ else if (curChar == 62)
30693082
{ jjCheckNAddStates(1259, 1261); }
30703083
break;
30713084
case 452:
3072-
if (curChar == 40 && kind > 143)
3073-
kind = 143;
3085+
if (curChar == 40 && kind > 144)
3086+
kind = 144;
30743087
break;
30753088
case 454:
30763089
if ((0xfc00ffffffffcbffL & l) != 0L)
@@ -7986,7 +7999,8 @@ else if (jjmatchedPos == strPos && jjmatchedKind > strKind)
79867999
null, null, null, null, null, null, null, null, null, null, null, null, null, null,
79878000
null, null, null, null, null, null, null, null, null, null, null, null, null, null,
79888001
null, null, null, null, null, null, null, null, null, null, null, null, null, null,
7989-
null, null, "\41", "\44", "\45", "\46", "\140", "\77", "\74", "\174", "\74\75", };
8002+
null, null, null, "\41", "\44", "\45", "\46", "\140", "\77", "\74", "\174",
8003+
"\74\75", };
79908004
protected Token jjFillToken()
79918005
{
79928006
final Token t;
@@ -8373,10 +8387,10 @@ public void SwitchTo(int lexState)
83738387
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
83748388
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
83758389
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
8376-
-1, -1, -1, -1, -1,
8390+
-1, -1, -1, -1, -1, -1,
83778391
};
83788392
static final long[] jjtoToken = {
8379-
0xffffffffffe00001L, 0xff803fffffffffffL, 0x7ffffffL,
8393+
0xffffffffffe00001L, 0xff803fffffffffffL, 0xfffffffL,
83808394
};
83818395
static final long[] jjtoSkip = {
83828396
0x2L, 0x0L, 0x0L,

org/w3c/css/parser/analyzer/ParseException.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public ParseException(String message) {
6565
/**
6666
* This is the last token that has been consumed successfully. If
6767
* this object has been created due to a parse error, the token
68-
* followng this token will (therefore) be the first error token.
68+
* following this token will (therefore) be the first error token.
6969
*/
7070
public Token currentToken;
7171

@@ -94,7 +94,7 @@ private static String initialise(Token currentToken,
9494
int[][] expectedTokenSequences,
9595
String[] tokenImage) {
9696

97-
StringBuffer expected = new StringBuffer();
97+
StringBuilder expected = new StringBuilder();
9898
int maxSize = 0;
9999
for (int i = 0; i < expectedTokenSequences.length; i++) {
100100
if (maxSize < expectedTokenSequences[i].length) {
@@ -108,36 +108,38 @@ private static String initialise(Token currentToken,
108108
}
109109
expected.append(EOL).append(" ");
110110
}
111-
String retval = "Encountered \"";
111+
StringBuilder retval = new StringBuilder("Encountered \"");
112112
Token tok = currentToken.next;
113113
for (int i = 0; i < maxSize; i++) {
114-
if (i != 0) retval += " ";
114+
if (i != 0) retval.append(" ");
115115
if (tok.kind == 0) {
116-
retval += tokenImage[0];
116+
retval.append(tokenImage[0]);
117117
break;
118118
}
119-
retval += " " + tokenImage[tok.kind];
120-
retval += " \"";
121-
retval += add_escapes(tok.image);
122-
retval += " \"";
119+
retval.append(' ').append(tokenImage[tok.kind]);
120+
retval.append(" \"");
121+
retval.append(add_escapes(tok.image));
122+
retval.append(" \"");
123123
tok = tok.next;
124124
}
125-
retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
126-
retval += "." + EOL;
127-
128-
125+
if (currentToken.next != null) {
126+
retval.append("\" at line ").append(currentToken.next.beginLine).append(", column ").append(currentToken.next.beginColumn);
127+
}
128+
retval.append('.').append(EOL);
129+
130+
129131
if (expectedTokenSequences.length == 0) {
130132
// Nothing to add here
131133
} else {
132134
if (expectedTokenSequences.length == 1) {
133-
retval += "Was expecting:" + EOL + " ";
135+
retval.append("Was expecting:").append(EOL).append(" ");
134136
} else {
135-
retval += "Was expecting one of:" + EOL + " ";
137+
retval.append("Was expecting one of:").append(EOL).append(" ");
136138
}
137-
retval += expected.toString();
139+
retval.append(expected.toString());
138140
}
139-
140-
return retval;
141+
142+
return retval.toString();
141143
}
142144

143145

@@ -147,7 +149,7 @@ private static String initialise(Token currentToken,
147149
* string literal.
148150
*/
149151
static String add_escapes(String str) {
150-
StringBuffer retval = new StringBuffer();
152+
StringBuilder retval = new StringBuilder();
151153
char ch;
152154
for (int i = 0; i < str.length(); i++) {
153155
switch (str.charAt(i))
@@ -190,4 +192,4 @@ static String add_escapes(String str) {
190192
}
191193

192194
}
193-
/* JavaCC - OriginalChecksum=7d68a6a068da3c9ac8d23a9a0983a253 (do not edit this line) */
195+
/* JavaCC - OriginalChecksum=0131ff0db19134fe366be6509cf664b5 (do not edit this line) */

0 commit comments

Comments
 (0)