media-query-parse
A pure-Rust implementation of the CSS Media Queries grammar — parses a media query or media condition string and reports whether it is syntactically valid, without evaluating it against any actual device/viewport state.
Generic and standalone — not tied to HTML, a specific host language, or any particular consumer. This crate only parses the grammar; it does not decide whether a query matches anything.
Status
Feature-complete: tokenizer (CSS Syntax Level 3) and the full Media
Queries Level 4 grammar, including the <mf-range> comparison syntax
((400px <= width <= 700px)). Verified against 29 external
web-platform-tests conformance cases. Public API is documented
(#![deny(missing_docs)]) and marked #[non_exhaustive] where the
grammar may grow.
Intended crates.io name: media-query-parse. Not yet published.
Usage
use ;
// A single, syntactically valid media query.
assert!;
// An invalid media query reports a `ParseError` instead of panicking:
// `only` requires a following `<media-type>`, which is missing here.
assert!;
// `parse_media_query_list` splits a comma-separated list and parses
// each entry independently, returning one `Result` per entry.
let results = parse_media_query_list;
assert!;
assert!;
License
MIT — see LICENSE.