Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
87 changes: 62 additions & 25 deletions org/w3c/css/parser/CssSelectors.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
import org.w3c.css.atrules.css.AtRuleFontFace;
import org.w3c.css.atrules.css.AtRulePage;
import org.w3c.css.properties.css.CssProperty;
import org.w3c.css.selectors.AdjacentSiblingSelector;
import org.w3c.css.selectors.AttributeSelector;
import org.w3c.css.selectors.ChildSelector;
import org.w3c.css.selectors.DescendantSelector;
import org.w3c.css.selectors.GeneralSiblingSelector;
import org.w3c.css.selectors.PseudoClassSelector;
import org.w3c.css.selectors.PseudoElementSelector;
import org.w3c.css.selectors.PseudoFactory;
Expand Down Expand Up @@ -57,12 +53,12 @@ public final class CssSelectors extends SelectorsList
*/
String element;

char connector = DESCENDANT;
String connector = DESCENDANT_COMBINATOR;

/**
* The next context.
*/
protected CssSelectors next;
protected CssSelectors next = null;

// true if the element is a block-level element
private boolean isBlock;
Expand All @@ -75,7 +71,7 @@ public final class CssSelectors extends SelectorsList
//private int hashGeneral;

// The CssStyle to use
private static Class style;
private static Class<?> style;

// see isEmpty and addProperty
private boolean Init;
Expand All @@ -97,7 +93,7 @@ public CssSelectors(ApplContext ac) {
this.ac = ac;
}

private CssSelectors(Class style) {
private CssSelectors(Class<?> style) {
super();
CssSelectors.style = style;
try {
Expand Down Expand Up @@ -134,7 +130,7 @@ public CssSelectors(ApplContext ac, CssSelectors next) {
*
* @param style0 the style
*/
public void setStyle(Class style0) {
public void setStyle(Class<?> style0) {
Util.verbose("Style is : " + style0);
style = style0;
}
Expand Down Expand Up @@ -243,7 +239,7 @@ public void addPseudoElement(String pseudo) throws InvalidParamException {
throw new InvalidParamException("pseudo", "::" + pseudo, ac);
}

public void setPseudoFun(String pseudo, String param)
public void setPseudoFun(ApplContext ac, String pseudo, String param)
throws InvalidParamException {

CssVersion version = ac.getCssVersion();
Expand All @@ -259,33 +255,57 @@ public void setPseudoFun(String pseudo, String param)
}
}

public void setPseudoFun(ApplContext ac, String pseudo, ArrayList<CssSelectors> selector_list)
throws InvalidParamException {

CssVersion version = ac.getCssVersion();
String[] ps = PseudoFactory.getPseudoFunction(version);
if (ps != null) {
for (String s : ps) {
if (pseudo.equals(s)) {
addPseudoFunction(PseudoFactory.newPseudoFunction(pseudo, selector_list, ac));
return;
}
}
throw new InvalidParamException("pseudo", ":" + pseudo, ac);
}
}


public void addType(TypeSelector type) throws InvalidParamException {
super.addType(type);
element = type.getName();
hashElement = element.hashCode();
}

public void addDescendant(DescendantSelector descendant)
public void addDescendantCombinator()
throws InvalidParamException {
super.addDescendant(descendant);
connector = DESCENDANT;
super.addDescendantCombinator();
connector = DESCENDANT_COMBINATOR;
}

public void addChild(ChildSelector child) throws InvalidParamException {
super.addChild(child);
connector = CHILD;
public void addChildCombinator()
throws InvalidParamException {
super.addChildCombinator();
connector = CHILD_COMBINATOR;
}

public void addAdjacentSibling(AdjacentSiblingSelector adjacent)
public void addNextSiblingCombinator()
throws InvalidParamException {
super.addAdjacentSibling(adjacent);
connector = ADJACENT_SIBLING;
super.addNextSiblingCombinator();
connector = NEXT_SIBLING_COMBINATOR;
}

public void addGeneralSibling(GeneralSiblingSelector sibling)
public void addSubsequentSiblingCombinator()
throws InvalidParamException {
super.addGeneralSibling(sibling);
connector = GENERAL_SIBLING;
super.addSubsequentSiblingCombinator();
connector = SUBSEQUENT_SIBLING_COMBINATOR;
}

public void addColumnCombinator()
throws InvalidParamException {
super.addColumnCombinator();
connector = COLUMN_COMBINATOR;
}


Expand Down Expand Up @@ -381,8 +401,8 @@ marking as final (ie: no more modifications) triggers more
*/

/*
* Mark as final, ie: no more modification to the structure.
*/
* Mark as final, ie: no more modification to the structure.
*/
public void markAsFinal() {
// if something has been changed, reset to force recomputing
if (!isFinal) {
Expand Down Expand Up @@ -585,7 +605,7 @@ private boolean canMatch(CssSelectors selector) {
Util.verbose("canMatch for attributes :" + result);

if ((hashElement != selector.hashElement) && hashElement != 0) {
if ((connector == DESCENDANT) && (selector.next != null)) {
if ((connector.equals(DESCENDANT_COMBINATOR)) && (selector.next != null)) {
// here we are in this case :
// H1 and HTML BODY H1 EM
// H1 can't match EM but EM have next
Expand Down Expand Up @@ -618,4 +638,21 @@ public void findConflicts(ApplContext ac, Warnings warnings,
CssStyle style = getStyle();
style.findConflicts(ac, warnings, this, allSelectors);
}

public static String toArrayString(ArrayList<CssSelectors> selectors) {
if (selectors == null) {
return "";
}
StringBuilder sb = new StringBuilder();
boolean first = true;
for (CssSelectors s : selectors) {
if (!first) {
sb.append(", ");
} else {
first = false;
}
sb.append(s);
}
return sb.toString();
}
}
27 changes: 11 additions & 16 deletions org/w3c/css/parser/CssSelectorsConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,15 @@ public interface CssSelectorsConstant {
*/
public static final int ATTRIBUTE_LENGTH = 10;

/**
* descendant connector
*/
public static final char DESCENDANT = ' ';
/**
* child connector
*/
public static final char CHILD = '>';
/**
* adjacent sibling connector
*/
public static final char ADJACENT_SIBLING = '+';
/**
* general sibling connector
*/
public static final char GENERAL_SIBLING = '~';
// See https://www.w3.org/TR/2018/WD-selectors-4-20181121/#combinators

public static final String DESCENDANT_COMBINATOR = " ";

public static final String CHILD_COMBINATOR = ">";

public static final String NEXT_SIBLING_COMBINATOR = "+";

public static final String SUBSEQUENT_SIBLING_COMBINATOR = "~";

public static final String COLUMN_COMBINATOR = "||";
}
Loading