Expand description
Recursive-descent parser for the Media Queries Level 4 grammar,
built on top of the crate::tokenizer::Tokenizer from phase 02.
One function per grammar production (see the doc comment on each
function below for the production it implements), mirroring the
structure of the grammar in plan/03-grammar.md §“Grammatik-
Produktionen”.
Parsing approach — no tokenizer backtracking. <media-in-parens>
has three alternatives behind the same opening ( (or function
token). Instead of backtracking the main token stream, the content
of a parenthesized block is first consumed as one atomic token
block (analogous to “Consume a simple block”, CSS Syntax Level
3 §5.4.8: all tokens up to the mirror closing token,
respecting nested brackets), then <media-condition> and
<media-feature> are tried in turn against that isolated token
slice. If both fail, the block is kept verbatim as
<general-enclosed> (see ast::GeneralEnclosed) — lookahead stays
confined to the bracket content instead of needing true backtracking
on the main stream.
Error handling. Two distinct failure kinds exist per spec §3.2:
a syntax error a parser can’t even parse as a block (e.g. unbalanced
parentheses) is a real error, represented by ParseError /
Result. A single <media-query> list entry that is syntactically
well-formed as a block but doesn’t match the grammar (e.g. an
unknown media feature) is, per spec, a browser-matching concern (UAs
replace it with not all) — this crate has no “matches” concept
(see CLAUDE.md), so parse_media_query_list surfaces the actual
per-entry Result instead of silently rewriting it.
Enums§
- Parse
Error - A real syntax error, distinct from a
<media-query>that is syntactically well-formed but doesn’t match the grammar (see the module doc comment). One variant per failure cause.
Functions§
- parse_
media_ query - Parses
inputas a single<media-query>. - parse_
media_ query_ list - Parses
inputas a<media-query-list>: a comma-separated list of component values (spec §3), with each entry parsed independently as a<media-query>. Returns oneResultper entry rather than a singleMediaQueryList/error, since a single invalid entry must not invalidate the rest of the list (see the module doc comment).