Skip to content

Commit 922b16c

Browse files
authored
Merge pull request w3c#351 from w3c/units-4
updates per css-values-4
2 parents 19fa57a + e7c4a8c commit 922b16c

File tree

11 files changed

+4941
-4930
lines changed

11 files changed

+4941
-4930
lines changed

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

Lines changed: 1352 additions & 1055 deletions
Large diffs are not rendered by default.

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

Lines changed: 93 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ import org.w3c.css.values.CssAttr;
6565
import org.w3c.css.values.CssBracket;
6666
import org.w3c.css.values.CssCalc;
6767
import org.w3c.css.values.CssCheckableValue;
68-
import org.w3c.css.values.CssClamp;
6968
import org.w3c.css.values.CssColor;
7069
import org.w3c.css.values.CssComparator;
7170
import org.w3c.css.values.CssExpression;
@@ -76,8 +75,7 @@ import org.w3c.css.values.CssHashIdent;
7675
import org.w3c.css.values.CssIdent;
7776
import org.w3c.css.values.CssImage;
7877
import org.w3c.css.values.CssLength;
79-
import org.w3c.css.values.CssMax;
80-
import org.w3c.css.values.CssMin;
78+
import org.w3c.css.values.CssMathFunction;
8179
import org.w3c.css.values.CssNumber;
8280
import org.w3c.css.values.CssOperator;
8381
import org.w3c.css.values.CssPercentage;
@@ -647,20 +645,18 @@ TOKEN [IGNORE_CASE] :
647645
<DEFAULT>
648646
TOKEN [IGNORE_CASE] :
649647
{
650-
< RELFONTLENGTH : <NUM> "em"
651-
| <NUM> "ex"
652-
| <NUM> "cap"
653-
| <NUM> "ch"
654-
| <NUM> "ic"
655-
| <NUM> "lh"
656-
| <NUM> "rlh"
657-
| <NUM> "rem" >
658-
| <RELVIEWLENGTH : <NUM> "vw"
659-
| <NUM> "vh"
660-
| <NUM> "vi"
661-
| <NUM> "vb"
662-
| <NUM> "vmin"
663-
| <NUM> "vmax" >
648+
< RELFONTLENGTH : <NUM> ( "r" )? "em"
649+
| <NUM> ( "r" )? "ex"
650+
| <NUM> ( "r" )? "cap"
651+
| <NUM> ( "r" )? "ch"
652+
| <NUM> ( "r" )? "ic"
653+
| <NUM> ( "r" )? "lh" >
654+
| <RELVIEWLENGTH : <NUM> ( "s" | "l" | "d" )? "vw"
655+
| <NUM> ( "s" | "l" | "d" )? "vh"
656+
| <NUM> ( "s" | "l" | "d" )? "vi"
657+
| <NUM> ( "s" | "l" | "d" )? "vb"
658+
| <NUM> ( "s" | "l" | "d" )? "vmin"
659+
| <NUM> ( "s" | "l" | "d" )? "vmax" >
664660
| <ABSOLUTLENGTH : <NUM> "cm"
665661
| <NUM> "mm"
666662
| <NUM> "q"
@@ -778,8 +774,10 @@ TOKEN [IGNORE_CASE] :
778774
| <FUNCTIONNTHLASTOFTYPE : "nth-last-of-type(" >
779775
| <FUNCTIONNOT : "not(" >
780776
| <FUNCTIONCALC : "calc(" | "-moz-calc(" | "-webkit-calc(" >
781-
| <FUNCTIONMIN : "min(" >
782-
| <FUNCTIONMAX : "max(" >
777+
| <FUNCTIONMATHN : "min(" | "max(" | "hypot(" >
778+
| <FUNCTIONMATH1 : "sin(" | "cos(" | "tan(" | "asin(" | "acos(" | "atan(" | "sqrt(" | "exp(" | "abs(" | "sign(" >
779+
| <FUNCTIONMATH2 : "mod(" | "rem(" | "atan2(" | "pow(" | "log(" >
780+
| <FUNCTIONROUND : "round(" >
783781
| <FUNCTIONCLAMP : "clamp(" >
784782
| <FUNCTIONATTR : "attr(" >
785783
| <FUNCTIONVAR : "var(" >
@@ -3171,8 +3169,7 @@ void term(CssExpression exp) :
31713169
)
31723170
)
31733171
| ( func=mathcalc() { setValue(func, exp, operator, null, FUNCTIONCALC); }
3174-
| func=mathmax() { setValue(func, exp, operator, null, FUNCTION); }
3175-
| func=mathmin() { setValue(func, exp, operator, null, FUNCTION); }
3172+
| func=mathfunction() { setValue(func, exp, operator, null, FUNCTION); }
31763173
| func=mathclamp() { setValue(func, exp, operator, null, FUNCTION); }
31773174
| func=attr() { setValue(func, exp, operator, null, FUNCTION); }
31783175
| func=functionvar() { setValue(func, exp, operator, null, FUNCTIONVAR); }
@@ -3265,8 +3262,7 @@ void mediaterm(CssExpression exp) :
32653262
}
32663263
| ( func=function() { setValue(func, exp, operator, null, FUNCTION); }
32673264
| func=mathcalc() { setValue(func, exp, operator, null, FUNCTIONCALC); }
3268-
| func=mathmax() { setValue(func, exp, operator, null, FUNCTION); }
3269-
| func=mathmin() { setValue(func, exp, operator, null, FUNCTION); }
3265+
| func=mathfunction() { setValue(func, exp, operator, null, FUNCTION); }
32703266
| func=mathclamp() { setValue(func, exp, operator, null, FUNCTION); }
32713267
) ) ( <S> )* )
32723268
| (( n=<STRING> { setValue(new CssString(), exp, operator, n, STRING); }
@@ -3305,60 +3301,103 @@ void mediaterm(CssExpression exp) :
33053301
) ( <S> )* )
33063302
}
33073303

3308-
CssCheckableValue mathmin() :
3304+
CssCheckableValue mathfunction() :
3305+
{
3306+
CssCheckableValue v;
3307+
}
3308+
{
3309+
( v=mathfunction1() | v=mathfunction2() | v=mathfunctionn() | v=mathfunctionround() ) {
3310+
return v;
3311+
}
3312+
}
3313+
3314+
3315+
CssCheckableValue mathfunctionn() :
33093316
{
33103317
CssCheckableValue v;
3311-
CssMin c;
3318+
CssMathFunction c;
33123319
Token n;
33133320
}
33143321
{
3315-
( n=<FUNCTIONMIN> ( <S> )* v=mathsum() {
3316-
if (v.getRawType() != CssTypes.CSS_MIN) {
3317-
c = new CssMin(v);
3318-
} else {
3319-
c = (CssMin) v;
3320-
}
3322+
( n=<FUNCTIONMATHN> ( <S> )* v=mathsum() {
3323+
c = new CssMathFunction(ac, n.image, v);
33213324
}
33223325
( <S> )* ( <COMMA> ( <S> )* v=mathsum() {
3323-
c.addValue(v);
3326+
c.addValue(v);
33243327
} ( <S> )* )* <RPAREN> ) {
33253328
c.validate();
33263329
return c;
33273330
}
33283331
}
33293332

3330-
CssCheckableValue mathmax() :
3333+
CssCheckableValue mathfunctionround() :
33313334
{
33323335
CssCheckableValue v;
3333-
CssMax c;
3336+
CssMathFunction c;
33343337
Token n;
33353338
}
33363339
{
3337-
( n=<FUNCTIONMAX> ( <S> )* v=mathsum() {
3338-
if (v.getRawType() != CssTypes.CSS_MAX) {
3339-
c = new CssMax(v);
3340-
} else {
3341-
c = (CssMax) v;
3342-
}
3340+
( n=<FUNCTIONROUND> { c = new CssMathFunction(ac, n.image); }
3341+
( <S> )* ( LOOKAHEAD(2) n=<IDENT> { c.addValue(CssIdent.getIdent(convertIdent(n.image))); }
3342+
| v=mathsum() { c.addValue(v); } )
3343+
( <S> )* ( <COMMA> ( <S> )* v=mathsum() {
3344+
c.addValue(v);
3345+
} ( <S> )* )* <RPAREN> ) {
3346+
c.validate();
3347+
return c;
3348+
}
3349+
}
3350+
3351+
3352+
CssCheckableValue mathfunction1() :
3353+
{
3354+
CssCheckableValue v;
3355+
CssMathFunction c;
3356+
Token n;
3357+
}
3358+
{
3359+
( n=<FUNCTIONMATH1> ( <S> )* v=mathsum() {
3360+
c = new CssMathFunction(ac, n.image, v);
33433361
}
3344-
( <S> )* ( <COMMA> ( <S> )* v=mathsum() {
3345-
c.addValue(v);
3346-
} ( <S> )* )* <RPAREN> ) {
3347-
c.validate();
3362+
( <S> )* <RPAREN> ) {
3363+
c.validate();
3364+
return c;
3365+
}
3366+
}
3367+
3368+
CssCheckableValue mathfunction2() :
3369+
{
3370+
CssCheckableValue v;
3371+
CssMathFunction c;
3372+
Token n;
3373+
}
3374+
{
3375+
( n=<FUNCTIONMATH2> ( <S> )* v=mathsum() {
3376+
c = new CssMathFunction(ac, n.image, v);
3377+
}
3378+
( <S> )* ( <COMMA> ( <S> )* v=mathsum() {
3379+
c.addValue(v);
3380+
} ( <S> )* )? <RPAREN> ) {
3381+
c.validate();
33483382
return c;
33493383
}
33503384
}
33513385

3386+
3387+
33523388
CssCheckableValue mathclamp() :
33533389
{
33543390
CssCheckableValue v1, v2, v3;
3355-
CssClamp c;
3356-
Token n;
3391+
CssMathFunction c;
3392+
Token n;
33573393
}
33583394
{
33593395
( n=<FUNCTIONCLAMP> ( <S> )* v1=mathsum() ( <S> )* <COMMA> ( <S> )* v2=mathsum() ( <S> )*
33603396
<COMMA> ( <S> )* v3=mathsum() ( <S> )* <RPAREN> ) {
3361-
c = new CssClamp(ac, v1, v2, v3);
3397+
c = new CssMathFunction(ac, n.image);
3398+
c.addValue(v1);
3399+
c.addValue(v2);
3400+
c.addValue(v3);
33623401
c.validate();
33633402
return c;
33643403
}
@@ -3479,7 +3518,7 @@ CssCheckableValue calcnumbervalue() :
34793518
}
34803519
{
34813520
(
3482-
( ( operator=unaryOperator() )? n=<NUMBER> { v = new CssNumber(); v.set(addOperator(operator, n.image), ac); } ) |
3521+
( ( operator=unaryOperator() )? ( n=<NUMBER> | n=<IDENT> ) { v = new CssNumber(); v.set(addOperator(operator, n.image), ac); } ) |
34833522
( <LPAREN> ( <S> )* v=calcnumbersum() ( <S> )* <RPAREN> { try { ((CssCalc) v).setParenthesis(); } catch (Exception ex) { ex.printStackTrace();}} )
34843523
) {
34853524
return v;
@@ -3548,7 +3587,7 @@ CssCheckableValue v = null;
35483587
char operator = ' ';
35493588
}
35503589
{
3551-
( ( operator=unaryOperator() )? ( n=<NUMBER> { v = new CssNumber(); v.set(addOperator(operator, n.image), ac); }
3590+
( ( operator=unaryOperator() )? ( ( n=<NUMBER> | n=<IDENT> ) { v = new CssNumber(); v.set(addOperator(operator, n.image), ac); }
35523591
| n=<PERCENTAGE> { v = new CssPercentage(); v.set(addOperator(operator, n.image), ac); }
35533592
| n=<RELFONTLENGTH> { v = new CssLength(); v.set(addOperator(operator, n.image), ac); }
35543593
| n=<RELVIEWLENGTH> { v = new CssLength(); v.set(addOperator(operator, n.image), ac); }
@@ -3560,8 +3599,7 @@ char operator = ' ';
35603599
)
35613600
| ( <LPAREN> ( <S> )* v=mathsum() ( <S> )* <RPAREN> ) { ((CssCalc) v).setParenthesis(); }
35623601
| v=mathcalc()
3563-
| v=mathmax()
3564-
| v=mathmin()
3602+
| v=mathfunction()
35653603
| v=mathclamp()
35663604
| v=attr()
35673605
| v=functionvar()
@@ -3869,9 +3907,11 @@ String skip_to_matching_paren() {
38693907
case FUNCTIONNTHLASTOFTYPE:
38703908
case FUNCTIONNOT:
38713909
case FUNCTIONCALC:
3872-
case FUNCTIONMIN:
3873-
case FUNCTIONMAX:
3910+
case FUNCTIONMATHN:
3911+
case FUNCTIONMATH1:
3912+
case FUNCTIONMATH2:
38743913
case FUNCTIONCLAMP:
3914+
case FUNCTIONROUND:
38753915
case FUNCTIONATTR:
38763916
case FUNCTIONVAR:
38773917
s.append(tok.image);

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -281,21 +281,25 @@ public interface CssParserConstants {
281281
/** RegularExpression Id. */
282282
int FUNCTIONCALC = 135;
283283
/** RegularExpression Id. */
284-
int FUNCTIONMIN = 136;
284+
int FUNCTIONMATHN = 136;
285285
/** RegularExpression Id. */
286-
int FUNCTIONMAX = 137;
286+
int FUNCTIONMATH1 = 137;
287287
/** RegularExpression Id. */
288-
int FUNCTIONCLAMP = 138;
288+
int FUNCTIONMATH2 = 138;
289289
/** RegularExpression Id. */
290-
int FUNCTIONATTR = 139;
290+
int FUNCTIONROUND = 139;
291291
/** RegularExpression Id. */
292-
int FUNCTIONVAR = 140;
292+
int FUNCTIONCLAMP = 140;
293293
/** RegularExpression Id. */
294-
int FUNCTION = 141;
294+
int FUNCTIONATTR = 141;
295295
/** RegularExpression Id. */
296-
int HTMLSTARTTAG = 142;
296+
int FUNCTIONVAR = 142;
297297
/** RegularExpression Id. */
298-
int HTMLENDTAG = 143;
298+
int FUNCTION = 143;
299+
/** RegularExpression Id. */
300+
int HTMLSTARTTAG = 144;
301+
/** RegularExpression Id. */
302+
int HTMLENDTAG = 145;
299303

300304
/** Lexical state. */
301305
int DEFAULT = 0;
@@ -438,8 +442,10 @@ public interface CssParserConstants {
438442
"\"nth-last-of-type(\"",
439443
"\"not(\"",
440444
"<FUNCTIONCALC>",
441-
"\"min(\"",
442-
"\"max(\"",
445+
"<FUNCTIONMATHN>",
446+
"<FUNCTIONMATH1>",
447+
"<FUNCTIONMATH2>",
448+
"\"round(\"",
443449
"\"clamp(\"",
444450
"\"attr(\"",
445451
"\"var(\"",

0 commit comments

Comments
 (0)