Skip to main content

Crate css_tokenize

Crate css_tokenize 

Source
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§

HashType
Type flag of a Token::Hash (spec §4.3.1, the # branch).
NumericType
Numeric type flag, as used by Token::Number and Token::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 input into a Vec<Token>, ending with a single Token::Eof. Convenience wrapper around Tokenizer for callers that don’t need streaming/lazy tokenization.