Skip to main content

Module parser

Module parser 

Source
Expand description

CSS selector parser. CSS selector parser.

Parses a CSS selector string into an ast::SelectorList using a hand-rolled recursive-descent parser. Supports:

  • Type selectors: div, p, span
  • Class selectors: .class
  • ID selectors: #id
  • Universal selector: *
  • Attribute selectors: [attr], [attr=val], [attr~=val], [attr^=val], [attr$=val], [attr*=val]
  • Pseudo-classes: :first-child, :last-child, :nth-child(an+b), :not(sel)
  • Compound selectors: div.class#id[attr]
  • Combinators: A B (descendant), A > B (child), A + B (adjacent), A ~ B (general sibling)
  • Comma-separated selector lists: div, span

Functionsยง

parse_selector
Parse a CSS selector string into a SelectorList.
parse_single_selector
Parse a single CSS selector (no commas).