Skip to content

Commit 3253196

Browse files
committed
1 parent 2c66c2f commit 3253196

File tree

4 files changed

+102
-0
lines changed

4 files changed

+102
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,8 @@ TOKEN [IGNORE_CASE] :
775775
| <FUNCTIONHOSTCONTEXT : "host-context(" >
776776
| <FUNCTIONNTHCHILD : "nth-child(" >
777777
| <FUNCTIONNTHLASTCHILD : "nth-last-child(" >
778+
| <FUNCTIONNTHCOL : "nth-col(" >
779+
| <FUNCTIONNTHLASTCOL : "nth-last-col(" >
778780
| <FUNCTIONNTHOFTYPE : "nth-of-type(" >
779781
| <FUNCTIONNTHLASTOFTYPE : "nth-last-of-type(" >
780782
| <FUNCTIONNOT : "not(" >
@@ -2797,6 +2799,17 @@ CssANPlusB anpb = null;
27972799
getBeginColumn(), getEndLine(), getEndColumn(), e));
27982800
}
27992801
}
2802+
| ( ( n=<FUNCTIONNTHCOL> | n=<FUNCTIONNTHLASTCOL> ) ( <S> )*
2803+
( ( anpb=anplusb() ( <S> )* ) | error_str=skip_to_matching_paren() ) ) {
2804+
try {
2805+
exp.addValue(anpb);
2806+
s.setPseudoFun(ac, convertStringIndex(n.image, 0, n.image.length() -1, false).toLowerCase(), exp);
2807+
} catch(InvalidParamException e) {
2808+
removeThisRule();
2809+
ac.getFrame().addError(new CssError(getSourceFile(), getBeginLine(),
2810+
getBeginColumn(), getEndLine(), getEndColumn(), e));
2811+
}
2812+
}
28002813
| ( n=<FUNCTION> ( <S> )* param=expression() ) {
28012814
try {
28022815
s.setPseudoFun(ac, convertStringIndex(n.image, 0, n.image.length() -1, false).toLowerCase(),
@@ -3852,6 +3865,8 @@ String skip_to_matching_paren() {
38523865
case FUNCTIONSLOTTED:
38533866
case FUNCTIONNTHCHILD:
38543867
case FUNCTIONNTHLASTCHILD:
3868+
case FUNCTIONNTHCOL:
3869+
case FUNCTIONNTHLASTCOL:
38553870
case FUNCTIONNTHOFTYPE:
38563871
case FUNCTIONNTHLASTOFTYPE:
38573872
case FUNCTIONNOT:

org/w3c/css/selectors/PseudoFactory.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.w3c.css.selectors.pseudofunctions.PseudoFunctionLang;
1414
import org.w3c.css.selectors.pseudofunctions.PseudoFunctionNot;
1515
import org.w3c.css.selectors.pseudofunctions.PseudoFunctionNthChild;
16+
import org.w3c.css.selectors.pseudofunctions.PseudoFunctionNthCol;
1617
import org.w3c.css.selectors.pseudofunctions.PseudoFunctionNthLastChild;
1718
import org.w3c.css.selectors.pseudofunctions.PseudoFunctionNthLastOfType;
1819
import org.w3c.css.selectors.pseudofunctions.PseudoFunctionNthOfType;
@@ -280,6 +281,12 @@ public static PseudoFunctionSelector newPseudoFunction(String name,
280281
if (name.equals("lang")) {
281282
return new PseudoFunctionLang(name, exp, ac);
282283
}
284+
if (name.equals("nth-col")) {
285+
return new PseudoFunctionNthCol(name, exp, ac);
286+
}
287+
if (name.equals("nth-last-col")) {
288+
return new PseudoFunctionNthCol(name, exp, ac);
289+
}
283290
throw new InvalidParamException("pseudo",
284291
":" + name, ac);
285292
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// Author: Yves Lafon <ylafon@w3.org>
3+
//
4+
// (c) COPYRIGHT MIT, ERCIM, Keio, Beihang, 2021.
5+
// Please first read the full copyright statement in file COPYRIGHT.html
6+
package org.w3c.css.selectors.pseudofunctions;
7+
8+
import org.w3c.css.selectors.PseudoFunctionSelector;
9+
import org.w3c.css.util.ApplContext;
10+
import org.w3c.css.util.InvalidParamException;
11+
import org.w3c.css.values.CssANPlusB;
12+
import org.w3c.css.values.CssExpression;
13+
import org.w3c.css.values.CssTypes;
14+
import org.w3c.css.values.CssValue;
15+
16+
/**
17+
* PseudoFunctionNthCol
18+
*/
19+
public class PseudoFunctionNthCol extends PseudoFunctionSelector {
20+
21+
public PseudoFunctionNthCol(String name, CssExpression expression,
22+
ApplContext ac)
23+
throws InvalidParamException {
24+
CssANPlusB anpb = null;
25+
26+
setName(name);
27+
if (expression == null || expression.getCount() == 0) {
28+
throw new InvalidParamException("unrecognize", functionName(), ac);
29+
}
30+
CssValue val = expression.getValue();
31+
if (val.getType() != CssTypes.CSS_ANPLUSB) {
32+
throw new InvalidParamException("value", val.toString(), functionName(), ac);
33+
}
34+
anpb = (CssANPlusB) val;
35+
expression.next();
36+
setParam(anpb.toString());
37+
38+
}
39+
40+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// Author: Yves Lafon <ylafon@w3.org>
3+
//
4+
// (c) COPYRIGHT MIT, ERCIM, Keio, Beihang, 2021.
5+
// Please first read the full copyright statement in file COPYRIGHT.html
6+
package org.w3c.css.selectors.pseudofunctions;
7+
8+
import org.w3c.css.selectors.PseudoFunctionSelector;
9+
import org.w3c.css.util.ApplContext;
10+
import org.w3c.css.util.InvalidParamException;
11+
import org.w3c.css.values.CssANPlusB;
12+
import org.w3c.css.values.CssExpression;
13+
import org.w3c.css.values.CssTypes;
14+
import org.w3c.css.values.CssValue;
15+
16+
/**
17+
* PseudoFunctionNthLastCol
18+
*/
19+
public class PseudoFunctionNthLastCol extends PseudoFunctionSelector {
20+
21+
public PseudoFunctionNthLastCol(String name, CssExpression expression,
22+
ApplContext ac)
23+
throws InvalidParamException {
24+
CssANPlusB anpb = null;
25+
26+
setName(name);
27+
if (expression == null || expression.getCount() == 0) {
28+
throw new InvalidParamException("unrecognize", functionName(), ac);
29+
}
30+
CssValue val = expression.getValue();
31+
if (val.getType() != CssTypes.CSS_ANPLUSB) {
32+
throw new InvalidParamException("value", val.toString(), functionName(), ac);
33+
}
34+
anpb = (CssANPlusB) val;
35+
expression.next();
36+
setParam(anpb.toString());
37+
38+
}
39+
40+
}

0 commit comments

Comments
 (0)