1mod display;
2mod from_str;
3mod methods;
4mod parse;
5#[cfg(test)]
6mod tests;
7use nom::{
8 branch::alt,
9 bytes::complete::{tag, take_till1},
10 character::complete::{alphanumeric1, char, multispace1},
11 combinator::opt,
12 error::Error,
13 multi::{many0, separated_list0},
14 sequence::{delimited, tuple},
15 Err, IResult,
16};
17use std::{
18 fmt::{Display, Formatter},
19 ops::{Add, AddAssign},
20};
21
22pub fn parse_tailwind(input: &str) -> Result<Vec<AstStyle>, Err<Error<&str>>> {
24 let rest = many0(tuple((multispace1, AstGroupItem::parse)));
25 let (head, groups) = match tuple((AstGroupItem::parse, rest))(input.trim()) {
26 Ok(o) => o.1,
27 Err(e) => return Err(e),
28 };
29 let mut out = vec![];
30 head.expand(&mut out);
31 for (_, g) in groups {
32 g.expand(&mut out)
33 }
34 Ok(out)
35}
36
37#[derive(Clone, Debug, PartialEq)]
39pub struct AstGroup<'a> {
40 pub important: bool,
42 pub head: AstStyle<'a>,
44 pub children: Vec<AstGroupItem<'a>>,
46}
47
48#[derive(Clone, Debug, PartialEq)]
50pub enum AstGroupItem<'a> {
51 Grouped(AstGroup<'a>),
53 Styled(AstStyle<'a>),
55}
56
57#[derive(Clone, Debug, PartialEq)]
59pub struct AstStyle<'a> {
60 pub important: bool,
62 pub negative: bool,
64 pub variants: Vec<ASTVariant<'a>>,
66 pub elements: Vec<&'a str>,
68 pub arbitrary: Option<&'a str>,
70}
71
72#[derive(Clone, Debug, PartialEq)]
74pub struct AstArbitrary<'a> {
75 pub arbitrary: &'a str,
77}
78
79#[derive(Clone, Debug, PartialEq, Default)]
81pub struct AstElements<'a> {
82 pub elements: Vec<&'a str>,
84}
85
86#[derive(Copy, Clone, Debug, PartialEq)]
88pub struct AstReference {}
89
90#[derive(Copy, Clone, Debug, PartialEq)]
92pub struct AstImportant {}
93
94#[derive(Clone, Debug, PartialEq)]
96pub struct ASTVariant<'a> {
97 pub not: bool,
99 pub pseudo: bool,
101 pub names: Vec<&'a str>,
103}