Expand description
A CSS tokenizer, implementing CSS Syntax Module Level 3 §3 (Tokenizing and Parsing CSS) and §4 (Tokenization), written in 100% safe Rust and without dependencies.
This crate only turns a &str into a stream of tokens. It knows nothing
about grammars built on top of CSS tokens (media queries, selectors,
stylesheets).
use css_tokenize::{Token, tokenize};
let tokens = tokenize("a:hover");
assert!(matches!(tokens[0], Token::Ident(_)));Structs§
- Tokenizer
- A tokenizer over a preprocessed input stream, per spec §4.3.
Enums§
- Hash
Type - Type flag of a
Token::Hash(spec §4.3.1, the#branch). - Numeric
Type - Numeric type flag, as used by
Token::NumberandToken::Dimension(spec §4.3.12, “Consume a number”). - Token
- A single CSS token, per spec §4.3.1 (“Consume a token”) and the token types defined at the start of §4.3.
Functions§
- tokenize
- Tokenizes
inputinto aVec<Token>, ending with a singleToken::Eof. Convenience wrapper aroundTokenizerfor callers that don’t need streaming/lazy tokenization.