media-query-parse 0.1.0

A pure-Rust parser for the CSS Media Queries grammar
Documentation
  • Coverage
  • 100%
    130 out of 130 items documented1 out of 24 items with examples
  • Size
  • Source code size: 99.36 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.75 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • casoon/media-query-parse
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • casoon

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 media_query_parse::{parse_media_query, parse_media_query_list};

// A single, syntactically valid media query.
assert!(parse_media_query("screen and (min-width: 400px)").is_ok());

// An invalid media query reports a `ParseError` instead of panicking:
// `only` requires a following `<media-type>`, which is missing here.
assert!(parse_media_query("only").is_err());

// `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("screen, only");
assert!(results[0].is_ok());
assert!(results[1].is_err());

License

MIT — see LICENSE.