StylesheetParser.Selector.Parser (StylesheetParser v0.1.0)

Copy Markdown View Source

Selectors Level 4, over component values, as StylesheetParser.parse_component_values/1 returns them: an attribute selector is a [] StylesheetParser.SimpleBlock, and a functional pseudo-class or pseudo-element is a StylesheetParser.Function, its arguments its component values, except for the pseudo-classes whose arguments parse here, a StylesheetParser.PseudoClass: :is(), :where(), :not() and the :nth-*() ones. & is the nesting selector of CSS Nesting.

Each parser returns what it parsed, or nil, and the component values after it. A selector list parses whole when nothing is after it:

iex> {:ok, values} = StylesheetParser.parse_component_values("nav > a:hover, .button")
iex> {selectors, []} = StylesheetParser.Selector.Parser.selector_list(values)
iex> Enum.map(selectors, &to_string/1)
["nav > a:hover", ".button"]

iex> {:ok, values} = StylesheetParser.parse_component_values("a, #1st")
iex> {[%StylesheetParser.SimpleSelector{value: "a"}], rest} =
...>   StylesheetParser.Selector.Parser.selector_list(values)
iex> rest
[comma: ",", whitespace: " ", hash: "#1st"]

A nested rule's selectors may be relative, as > a:

iex> {:ok, values} = StylesheetParser.parse_component_values("> a, + b")
iex> {selectors, []} = StylesheetParser.Selector.Parser.relative_selector_list(values)
iex> Enum.map(selectors, &to_string/1)
["> a", "+ b"]

Summary

Functions

The An+B microsyntax, {a, b}, as 2n+1 and odd are {2, 1}. It isn't a token of its own: 2n+1 is a dimension and a number, n-1 an ident, 2n - 1 a dimension, a - and a number.

The <declaration-value> production matches any sequence of one or more tokens, so long as the sequence does not contain <bad-string-token>, <bad-url-token>, unmatched <)-token>, <]-token>, or <}-token>, or top-level <semicolon-token> tokens or <delim-token> tokens with a value of "!". It represents the entirety of what a valid declaration can have as its value.

Functions

an_b(tokens)

The An+B microsyntax, {a, b}, as 2n+1 and odd are {2, 1}. It isn't a token of its own: 2n+1 is a dimension and a number, n-1 an ident, 2n - 1 a dimension, a - and a number.

attr_matcher(tokens)

attr_modifier(tokens)

attribute_selector(all)

<attribute-selector> = '[' <wq-name> ']' |
              '[' <wq-name> <attr-matcher> [ <string-token> | <ident-token> ] <attr-modifier>? ']'

class_selector(tokens)

combinator(tokens)

complex_selector(tokens)

<complex-selector> = <compound-selector> [ <combinator>? <compound-selector> ]*

compound_selector(tokens)

<compound-selector> = [ <type-selector>? <subclass-selector>*
                        [ <pseudo-element-selector> <pseudo-class-selector>* ]* ]!

compound_selector_list(tokens)

<compound-selector-list> = <compound-selector>#

declaration_value(tokens)

The <declaration-value> production matches any sequence of one or more tokens, so long as the sequence does not contain <bad-string-token>, <bad-url-token>, unmatched <)-token>, <]-token>, or <}-token>, or top-level <semicolon-token> tokens or <delim-token> tokens with a value of "!". It represents the entirety of what a valid declaration can have as its value.

id_selector(all)

nesting_selector(tokens)

ns_prefix(tokens)

pseudo_class_selector(all)

pseudo_element_selector(tokens)

relative_selector(tokens)

<relative-selector> = <combinator>? <complex-selector>

A complex selector, its first compound selector after its combinator, as > a is %ComplexSelector{value: [[{:child_combinator, ">"}, a]]}.

relative_selector_list(tokens)

<relative-selector-list> = <relative-selector>#

selector_list(tokens)

<selector-list> = <complex-selector-list>
<complex-selector-list> = <complex-selector>#

simple_selector(tokens)

<simple-selector> = <type-selector> | <subclass-selector>

simple_selector_list(tokens)

<simple-selector-list> = <simple-selector>#

subclass_selector(tokens)

<subclass-selector> = <id-selector> | <class-selector> |
                      <attribute-selector> | <pseudo-class-selector>

and the & nesting selector.

type_selector(tokens)

wq_name(tokens)