Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9ca5fd7
redo attribute selector parsing to include wq-name and modifier.
ylafon Sep 27, 2021
9973904
regen
ylafon Sep 27, 2021
f6ed3ac
redo attribute selector parsing to include wq-name and modifier.
ylafon Sep 27, 2021
f7d14b8
regen
ylafon Sep 27, 2021
4b2d2aa
Merge branch 'selectors-4' of github.com:w3c/css-validator into selec…
ylafon Sep 27, 2021
9538721
redo attribute selector parsing to include wq-name and modifier.
ylafon Sep 27, 2021
761629c
regen
ylafon Sep 27, 2021
1ee5cd3
production renaming
ylafon Sep 28, 2021
0dd523e
regen
ylafon Sep 28, 2021
e9bb082
Merge branch 'selectors-4' of github.com:w3c/css-validator into selec…
ylafon Sep 28, 2021
751f1e1
Merge branch 'selectors-4' of github.com:w3c/css-validator into selec…
ylafon Sep 28, 2021
779d09e
Merge branch 'selectors-4' of github.com:w3c/css-validator into selec…
ylafon Sep 28, 2021
0ff3daa
regen
ylafon Sep 29, 2021
fb4c8a3
lang() pseudo function value check (wildcard ranges are not checked, …
ylafon Sep 29, 2021
3041782
combinator must be a string (as column combinator is not a single cha…
ylafon Sep 29, 2021
dbf50db
regen
ylafon Sep 29, 2021
833b61f
moved combinators for clarity
ylafon Sep 29, 2021
bc50295
support for pseudofunction requiring a selector list as an argument
ylafon Sep 29, 2021
6640eec
regen
ylafon Sep 29, 2021
133212f
making :not() more generic, note that the behaviour of selectors-3 ch…
ylafon Sep 29, 2021
951cdce
added applcontext for further checks
ylafon Sep 29, 2021
5d9c43d
regen
ylafon Sep 29, 2021
327615c
support for :has() and relative selectors
ylafon Sep 29, 2021
93a2e9a
regen
ylafon Sep 29, 2021
8649d88
complex selector parsing per https://www.w3.org/TR/2018/WD-selectors-…
ylafon Sep 30, 2021
2d477c2
regen
ylafon Sep 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
support for :has() and relative selectors
  • Loading branch information
ylafon committed Sep 29, 2021
commit 327615c79303971aadd1afa08bda58bc186a6e99
2 changes: 1 addition & 1 deletion org/w3c/css/parser/CssSelectors.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public final class CssSelectors extends SelectorsList
/**
* The next context.
*/
protected CssSelectors next;
protected CssSelectors next = null;

// true if the element is a block-level element
private boolean isBlock;
Expand Down
55 changes: 54 additions & 1 deletion org/w3c/css/parser/analyzer/CssParser.jj
Original file line number Diff line number Diff line change
Expand Up @@ -1981,6 +1981,27 @@ ArrayList<CssSelectors> selector_list() :
}
}

ArrayList<CssSelectors> relative_selector_list() :
{
CssSelectors selector;
ArrayList<CssSelectors> context_set = new ArrayList<CssSelectors>();
}
{
selector=relative_selector() {
if (selector != null) {
context_set.add(selector);
}
}
( <COMMA> selector=relative_selector() {
if (selector != null) {
context_set.add(selector);
}
} )*
{
return context_set;
}
}

/**
* @exception ParseException exception during the parse
*/
Expand Down Expand Up @@ -2136,6 +2157,38 @@ ArrayList<CssProperty> attributeDeclarations() :
}
}

CssSelectors relative_selector() :
{
String comb;
CssSelectors current;
}
{
comb=combinator() {
current = new CssSelectors(ac);
switch(comb) {
case "+":
current.addNextSiblingCombinator();
break;
case ">":
current.addChildCombinator();
break;
case "~":
current.addSubsequentSiblingCombinator();
break;
case "||":
current.addColumnCombinator();
break;
default:
current.addDescendantCombinator();
}
}
// FIXME should be complex_selector
current=simple_selector(current)
{
return current;
}

}
/**
* @exception ParseException exception during the parse
*/
Expand Down Expand Up @@ -2619,7 +2672,7 @@ String error_str = null;
getBeginColumn(), getEndLine(), getEndColumn(), e));
}
}
| ( n=<FUNCTIONHAS> ( <S> )* selector_list=selector_list() /* FIXME should be relative list */ ) {
| ( n=<FUNCTIONHAS> selector_list=relative_selector_list() ) {
try {
s.setPseudoFun(ac, convertStringIndex(n.image, 0, n.image.length() -1, false).toLowerCase(), selector_list);
} catch(InvalidParamException e) {
Expand Down
4 changes: 4 additions & 0 deletions org/w3c/css/selectors/PseudoFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package org.w3c.css.selectors;

import org.w3c.css.parser.CssSelectors;
import org.w3c.css.selectors.pseudofunctions.PseudoFunctionHas;
import org.w3c.css.selectors.pseudofunctions.PseudoFunctionIs;
import org.w3c.css.selectors.pseudofunctions.PseudoFunctionLang;
import org.w3c.css.selectors.pseudofunctions.PseudoFunctionNot;
Expand Down Expand Up @@ -246,6 +247,9 @@ public static PseudoFunctionSelector newPseudoFunction(String name,
if (name.equals("where")) {
return new PseudoFunctionWhere(name, value);
}
if (name.equals("has")) {
return new PseudoFunctionHas(name, value);
}
throw new InvalidParamException("pseudo",
":" + name, ac);
}
Expand Down
27 changes: 27 additions & 0 deletions org/w3c/css/selectors/pseudofunctions/PseudoFunctionHas.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Author: Yves Lafon <ylafon@w3.org>
//
// (c) COPYRIGHT MIT, ERCIM, Keio, Beihang, 2021.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.selectors.pseudofunctions;

import org.w3c.css.parser.CssSelectors;
import org.w3c.css.selectors.PseudoFunctionSelector;

import java.util.ArrayList;

/**
* PseudoFunctionHas
*/
public class PseudoFunctionHas extends PseudoFunctionSelector {

public PseudoFunctionHas(String name, String value) {
setName(name);
setParam(value);
}

public PseudoFunctionHas(String name, ArrayList<CssSelectors> selector_list) {
this(name, CssSelectors.toArrayString(selector_list));
}

}