parserino.css.selector

CSS selectors: syntax tree and parser.

The parser follows Selectors Level 4, for a static document: user-action and time pseudo-classes (:hover, :visited, ...) and pseudo-elements (::before) are valid but never match. It works at runtime and at compile time.

Namespace prefixes are predefined: html, svg, math, xlink, xml, xmlns.

Types 10

enumCombinator : ubyte

How a compound selector is related to the previous one

Descendant`a b`
Child`a > b`
NextSibling`a + b`
SubsequentSibling`a ~ b`
enumSimpleKind : ubyte

Kinds of simple selectors

Universal`*`
Type`div`
Id`#x`
Class`.x`
Attribute`[x]`, `[x=y]`, ...
PseudoClass`:first-child`, ...
Not`:not(list)`
Is`:is(list)`, `:where(list)`
Has`:has(relative list)`
NthChild`:nth-child(an+b [of list])`
NthLastChild`:nth-last-child(an+b [of list])`
NthOfType`:nth-of-type(an+b)`
NthLastOfType`:nth-last-of-type(an+b)`
Contains`:lexbor-contains(text [i])`, kept for compatibility with parserino 0.2.x (which used the lexbor selectors)
Lang`:lang(en, "fr-CH")`
Dir`:dir(ltr)`, `:dir(rtl)`: `name` is the direction (lowercase)
Neverstates of a live document (`:hover`), pseudo-elements (`::before`)
enumNsMatch : ubyte

Namespace of a type or attribute selector (svg|rect, [xlink|href]): the other members are the predefined prefixes

Any`*|x`, or no prefix for type selectors
None`|x`, or no prefix for attribute selectors
Html
Svg
Math
Xlink
Xml
Xmlns
enumAttrMatch : ubyte

Operator of an attribute selector

Exists`[x]`
Equal`[x=y]`
Includes`[x~=y]`
Dash`[x|=y]`
Prefix`[x^=y]`
Suffix`[x$=y]`
Substring`[x*=y]`
enumAttrCase : ubyte

Case sensitivity of the value of an attribute selector

Autocase-insensitive only for some html attributes (type, lang, ...)
Insensitive`[x=y i]`
Sensitive`[x=y s]`
enumPseudoClass : ubyte

Pseudo-classes without arguments that can match (:first-child is FirstChild)

AnyLink
Blank
Checked
Disabled
Empty
Enabled
FirstChild
FirstOfType
LastChild
LastOfType
Link
OnlyChild
OnlyOfType
Optional
PlaceholderShown
ReadOnly
ReadWrite
Required
Root
Scope
structSimple

A simple selector

Fields
AttrMatch match
AttrCase attrCase
PseudoClass pseudo
bool insensitive
const(char)[] name
const(char)[] rawName
uint knownId
const(char)[] value
long a
long b
const(SelectorList) * list
const(const(char)[])[] ranges
structCompound

A sequence of simple selectors (div.a[x])

Fields
Combinator combinator
const(Simple)[] simples
structComplex

A chain of compounds (div > p a), left to right

Fields
const(Compound)[] compounds

A comma separated list of complex selectors

Fields
const(Complex)[] items
Methods
bool looksForward() const @nogc nothrow pureDoes any selector need the following siblings or the children of the element? (`:last-child`, `:has()`, `:empty`, ...)
bool needsDocument() const @nogc nothrow pureDoes any selector depend on the whole document? (`:lang()` on the `<meta>` default language, `:dir()` on the text of the ancestors with `dir=auto`)

Functions 1

fnconst(SelectorList) * parseSelector(const(char)[] input, ref Arena arena) @nogc nothrow pure @safe @trustedParse a selector list. It returns `null` on syntax errors or if out of memory. All the memory comes from `arena`.