tailwind_ast/utils/
mod.rs1use nom::{
2 bytes::complete::tag,
3 character::complete::{char, digit1},
4 combinator::{map_res, opt, recognize},
5 sequence::tuple,
6 IResult,
7};
8use std::str::FromStr;
9#[cfg(test)]
10mod tests;
11
12pub fn parse_integer<T>(input: &str) -> IResult<&str, T>
14where
15 T: FromStr,
16{
17 map_res(recognize(digit1), str::parse)(input)
18}
19pub fn parse_i_px_maybe<T>(input: &str) -> IResult<&str, T>
21where
22 T: FromStr,
23{
24 let (rest, (i, _)) = tuple((parse_integer, opt(tag("px"))))(input)?;
25 Ok((rest, i))
26}
27
28pub fn parse_f32(input: &str) -> IResult<&str, f32> {
30 let float1 = tuple((digit1, opt(tuple((tag("."), digit1)))));
31 map_res(recognize(float1), str::parse)(input)
32}
33pub fn parse_f_percent(input: &str) -> IResult<&str, f32> {
35 let (rest, (f, _)) = tuple((parse_f32, char('%')))(input)?;
36 Ok((rest, f))
37}
38
39pub fn parse_fraction(input: &str) -> IResult<&str, (usize, usize)> {
41 let (rest, (a, _, b)) = tuple((parse_integer, tag("/"), parse_integer))(input)?;
42 Ok((rest, (a, b)))
43}
44
45#[inline]
47pub fn parse_fraction_maybe(input: &str) -> IResult<&str, (usize, Option<usize>)> {
48 let (rest, (a, b)) = tuple((parse_integer, opt(tuple((tag("/"), parse_integer)))))(input)?;
49 Ok((rest, (a, b.map(|s| s.1))))
50}
51
52pub fn parser_color_hex() {}
54
55