css_parse/macros/
parse.rs

1/// A macro for easily calling the Parser and entirely parsing a string.
2///
3/// # Example
4///
5/// ```
6/// use css_parse::*;
7/// use bumpalo::Bump;
8/// let bump = Bump::default();
9/// parse!(in bump "foo"); // ComponentValues
10///
11/// parse!(in bump "foo" as T![Ident]);
12///
13/// let features = Feature::SingleLineComments;
14/// parse!(in bump with features "//foo");
15///
16/// // Or pass a reference to a str
17/// let source = "//foo";
18/// let features = Feature::SingleLineComments;
19/// parse!(in bump with features &source);
20/// ```
21#[macro_export]
22macro_rules! parse {
23	(in $bump: ident $(with $features: ident)? &$source_text: ident as $ty: ty) => {
24		{
25			let mut p = $crate::Parser::new(&$bump, $source_text)$(.with_features($features))?;
26			p.parse_entirely::<$ty>()
27		}
28	};
29	(in $bump: ident $(with $features: ident)? $str: literal as $ty: ty) => {
30		{
31			let source_text = $str;
32			parse!(in $bump $(with $features)? &source_text as $ty)
33		}
34	};
35	(in $bump: ident $(with $features: ident)? $str: literal) => {
36		{
37			use $crate::ComponentValues;
38			parse!(in $bump $(with $features)? $str as ComponentValues)
39		}
40	};
41	(in $bump: ident $(with $features: ident)? &$str: ident) => {
42		{
43			use $crate::ComponentValues;
44			parse!(in $bump $(with $features)? &$str as ComponentValues)
45		}
46	};
47}