Skip to content

Commit cead630

Browse files
committed
support for env(), see #328, waiting on spec link
1 parent a930558 commit cead630

File tree

3 files changed

+535
-0
lines changed

3 files changed

+535
-0
lines changed

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

Lines changed: 40 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); }
@@ -3646,6 +3653,38 @@ CssExpression exp = null;
36463653
}
36473654
}
36483655

3656+
CssCheckableValue functionenv() :
3657+
{ Token n;
3658+
CssExpression exp = null;
3659+
CssExpression e;
3660+
CssEnv env = null;
3661+
String skipped = null;
3662+
}
3663+
{
3664+
<FUNCTIONENV> ( <S> )* n=<IDENT> ( <S> )* {
3665+
env = new CssEnv(ac, convertIdent(n.image));
3666+
e = new CssExpression();
3667+
}
3668+
( term(e) )*
3669+
( <COMMA> ( <S> )* try {
3670+
exp = expr()
3671+
} catch (ParseException pe) {
3672+
skipped = skip_to_matching_paren();
3673+
// FIXME do something meaningful with that string
3674+
exp = null;
3675+
}
3676+
)? <RPAREN>
3677+
{
3678+
env.setNumberExp(e);
3679+
if (exp != null) {
3680+
env.setDeclaration(exp);
3681+
} else if (skipped != null) {
3682+
// do something fancy here
3683+
}
3684+
return env;
3685+
}
3686+
}
3687+
36493688
CssCheckableValue functionvar() :
36503689
{ Token n;
36513690
CssExpression exp = null;
@@ -3946,6 +3985,7 @@ String skip_to_matching_paren() {
39463985
case FUNCTIONROUND:
39473986
case FUNCTIONATTR:
39483987
case FUNCTIONVAR:
3988+
case FUNCTIONENV:
39493989
s.append(tok.image);
39503990
nesting++;
39513991
getNextToken();

0 commit comments

Comments
 (0)