Skip to content

Commit fbb0462

Browse files
committed
support for env(), see w3c#328, waiting on spec link
1 parent f05c3e4 commit fbb0462

File tree

3 files changed

+538
-3
lines changed

3 files changed

+538
-3
lines changed

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ import org.w3c.css.values.CssCheckableValue;
7070
import org.w3c.css.values.CssClamp;
7171
import org.w3c.css.values.CssColor;
7272
import org.w3c.css.values.CssComparator;
73+
import org.w3c.css.values.CssEnv;
7374
import org.w3c.css.values.CssExpression;
7475
import org.w3c.css.values.CssFlexibleLength;
7576
import org.w3c.css.values.CssFrequency;
@@ -431,6 +432,10 @@ public abstract class CssParser {
431432
if (v.getType() == CssTypes.CSS_VARIABLE) {
432433
expr.markCssVariable();
433434
}
435+
} else if ( token == FUNCTIONENV ) {
436+
if (v.getType() == CssTypes.CSS_ENV) {
437+
expr.markCssVariable();
438+
}
434439
} else if ( token == FUNCTIONCALC ) {
435440
CssCalc c = (CssCalc) v;
436441
if (c.hasCssVariable()) {
@@ -773,7 +778,8 @@ TOKEN [IGNORE_CASE] :
773778
| <FUNCTIONMAX : "max(" >
774779
| <FUNCTIONCLAMP : "clamp(" >
775780
| <FUNCTIONATTR : "attr(" >
776-
| <FUNCTIONVAR : "var(" >
781+
| <FUNCTIONVAR : "var(" >
782+
| <FUNCTIONENV : "env(" >
777783
}
778784

779785
<DEFAULT>
@@ -2948,6 +2954,7 @@ void term(CssExpression exp) :
29482954
| func=mathclamp() { setValue(func, exp, operator, null, FUNCTION); }
29492955
| func=attr() { setValue(func, exp, operator, null, FUNCTION); }
29502956
| func=functionvar() { setValue(func, exp, operator, null, FUNCTIONVAR); }
2957+
| func=functionenv() { setValue(func, exp, operator, null, FUNCTIONENV); }
29512958
| func=function() { setValue(func, exp, operator, null, FUNCTION); }
29522959
| n=<STRING> { setValue(new CssString(), exp, operator, n, STRING); }
29532960
| n=<DIV> { setValue(new CssSwitch(), exp, operator, n, DIV); }
@@ -3362,6 +3369,38 @@ CssExpression exp = null;
33623369
}
33633370
}
33643371

3372+
CssCheckableValue functionenv() :
3373+
{ Token n;
3374+
CssExpression exp = null;
3375+
CssExpression e;
3376+
CssEnv env = null;
3377+
String skipped = null;
3378+
}
3379+
{
3380+
<FUNCTIONENV> ( <S> )* n=<IDENT> ( <S> )* {
3381+
env = new CssEnv(ac, convertIdent(n.image));
3382+
e = new CssExpression();
3383+
}
3384+
( term(e) )*
3385+
( <COMMA> ( <S> )* try {
3386+
exp = expr()
3387+
} catch (ParseException pe) {
3388+
skipped = skip_to_matching_paren();
3389+
// FIXME do something meaningful with that string
3390+
exp = null;
3391+
}
3392+
)? <RPAREN>
3393+
{
3394+
env.setNumberExp(e);
3395+
if (exp != null) {
3396+
env.setDeclaration(exp);
3397+
} else if (skipped != null) {
3398+
// do something fancy here
3399+
}
3400+
return env;
3401+
}
3402+
}
3403+
33653404
CssCheckableValue functionvar() :
33663405
{ Token n;
33673406
CssExpression exp = null;
@@ -3633,6 +3672,7 @@ String skip_to_matching_paren() {
36333672
case FUNCTIONCLAMP:
36343673
case FUNCTIONATTR:
36353674
case FUNCTIONVAR:
3675+
case FUNCTIONENV:
36363676
s.append(tok.image);
36373677
nesting++;
36383678
getNextToken();

0 commit comments

Comments
 (0)