1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
//! MusKitty CSS Parser
//!
//! Implements the parsing stage of the CSS Syntax Module Level 3 (§5
//! "Parser Algorithms"). Extracted from `muskitty-css` as a standalone
//! crate for independent versioning and publication.
//!
//! Re-exports [`Token`] / [`Tokenizer`] / [`CssTokenizer`] from
//! `muskitty-css-tokenizer` so downstream crates (e.g.
//! `muskitty-selectors`) can depend on this single crate to access
//! the full CSS Syntax stack.
//!
//! # Architecture
//!
//! The parser follows the two-stage model described in CSS Syntax §3.1:
//! 1. **Tokenization** — handled by `muskitty-css-tokenizer` (re-exported
//! here for convenience).
//! 2. **Parsing** — consumes tokens and produces CSS objects:
//! stylesheets, rules, declarations, component values (§5, fully
//! implemented).
//!
//! # Top-level API
//!
//! - [`parse_stylesheet`] — full stylesheet parse (§5.4.3)
//! - [`parse_rule`] — single rule parse (§5.4.6)
//! - [`parse_declaration`] — single declaration parse (§5.4.7)
//! - [`parse_component_value`] — single component value (§5.4.8)
//! - [`parse_list_of_component_values`] — list of component values (§5.4.9)
//! - [`parse_comma_separated_list_of_component_values`] — comma-separated list (§5.4.10)
//! - [`parse_a_grammar`] / [`parse_a_comma_separated_list_with_grammar`] — generic grammar hooks (§5.4.1 / §5.4.2)
//! - [`tokenize`] — token stream only (§4.3)
//!
//! # References
//!
//! - CSS Syntax Module Level 3: <https://drafts.csswg.org/css-syntax-3/>
//! - Spec source (Markdown): `D:\CSSWG\css-syntax-3\Overview.md`
// Re-export from muskitty-css-tokenizer for downstream convenience.
// Downstream crates that depend only on `muskitty-css-parser` get the
// full tokenizer + parser stack through this single dependency.
pub use ;
// Re-export parser data structures and algorithms at crate root.
pub use ;
pub use ;
pub use ;
pub use TokenStream;
pub use ;
/// Tokenize a CSS input string into a vector of tokens.
///
/// Implements the tokenization stage of CSS Syntax §3.1: construct a
/// tokenizer over `input` (after §5.3 input preprocessing, which the
/// tokenizer applies internally), then drain all tokens up to and
/// including `<EOF-token>`.
///
/// Returns the token stream without the trailing `<EOF-token>`. Parse
/// errors are currently discarded; a future API will expose them.
///
/// # Examples
///
/// ```
/// use muskitty_css_parser::tokenize;
/// use muskitty_css_parser::Token;
///
/// let tokens = tokenize("color: red;");
/// assert!(matches!(tokens[0], Token::Ident(_)));
/// assert!(matches!(tokens[1], Token::Colon));
/// assert!(matches!(tokens[2], Token::Whitespace));
/// assert!(matches!(tokens[3], Token::Ident(_)));
/// assert!(matches!(tokens[4], Token::Semicolon));
/// ```
/// Parse a CSS string into a [`Stylesheet`] (§5.4.3).
///
/// Implements `parse a stylesheet` from CSS Syntax §5.4.3: tokenize
/// the input (with §5.3 preprocessing), then `consume a stylesheet's
/// contents` (§5.5.1) to produce the list of rules.
///
/// # Examples
///
/// ```
/// use muskitty_css_parser::parse_stylesheet;
///
/// let ss = parse_stylesheet("a { color: red; }");
/// assert_eq!(ss.rules.len(), 1);
/// ```
/// Parse a CSS string into a single [`Rule`] (§5.4.6).
///
/// Returns `None` for a syntax error (empty input or trailing garbage).
///
/// # Examples
///
/// ```
/// use muskitty_css_parser::parse_rule;
///
/// assert!(parse_rule("@media print {}").is_some());
/// assert!(parse_rule("").is_none());
/// ```
/// Parse a CSS string into a single [`Declaration`] (§5.4.7).
///
/// Returns `None` for a syntax error (malformed declaration).
///
/// # Examples
///
/// ```
/// use muskitty_css_parser::parse_declaration;
///
/// let decl = parse_declaration("color: red").unwrap();
/// assert_eq!(decl.name, "color");
/// ```
/// Parse a CSS string into a single [`ComponentValue`] (§5.4.8).
///
/// Returns `None` for a syntax error (empty input or trailing
/// garbage after the component value).
///
/// # Examples
///
/// ```
/// use muskitty_css_parser::parse_component_value;
/// use muskitty_css_parser::ComponentValue;
/// use muskitty_css_parser::Token;
///
/// let cv = parse_component_value("red").unwrap();
/// assert!(matches!(cv, ComponentValue::PreservedToken(Token::Ident(_))));
/// ```
/// Parse a CSS string into a list of [`ComponentValue`] (§5.4.9).
///
/// # Examples
///
/// ```
/// use muskitty_css_parser::parse_list_of_component_values;
///
/// // "a b c" → 5 component values: a, ws, b, ws, c.
/// let list = parse_list_of_component_values("a b c");
/// assert_eq!(list.len(), 5);
/// ```
/// Parse a CSS string into a comma-separated list of [`ComponentValue`]
/// (§5.4.10).
///
/// # Examples
///
/// ```
/// use muskitty_css_parser::parse_comma_separated_list_of_component_values;
///
/// // "a, b, c" → 3 groups. Per §5.4.10, the algorithm does not
/// // discard leading whitespace between commas, so groups after the
/// // first carry a leading whitespace token.
/// let groups = parse_comma_separated_list_of_component_values("a, b, c");
/// assert_eq!(groups.len(), 3);
/// ```