Skip to content

Commit

Permalink
fix: allow numbers in the modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
arlyon committed Dec 5, 2022
1 parent 0c2780f commit 8e20a03
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
9 changes: 2 additions & 7 deletions crates/tailwind-parse/src/expression.rs
Expand Up @@ -2,7 +2,7 @@ use nom::{
bytes::complete::take_while1,
character::{
complete::{char, space0},
is_alphabetic,
is_alphabetic, is_alphanumeric,
},
combinator::{opt, verify},
multi::many0,
Expand Down Expand Up @@ -37,12 +37,7 @@ pub enum ExpressionConversionError<'a> {

impl<'a> Expression<'a> {
pub fn parse(s: NomSpan<'a>) -> IResult<NomSpan<'a>, Self, nom::error::Error<NomSpan<'a>>> {
let single_mod = {
let single_mod = take_while1(|c| is_alphabetic(c as u8) || c == '-');
let start_letter =
|s: &NomSpan<'a>| is_alphabetic(s.chars().next().expect("not empty") as u8);
verify(single_mod, start_letter)
};
let single_mod = take_while1(|c| is_alphanumeric(c as u8) || c == '-');

let mods = many0(terminated(single_mod, char(':')));
let negative = opt(char('-')).map(|o| o.is_some());
Expand Down
2 changes: 1 addition & 1 deletion crates/tailwind-parse/src/lib.rs
Expand Up @@ -98,6 +98,7 @@ mod test {
}

#[test_case("text-lg p-4" ; "basic")]
#[test_case("2xl:text-right" ; "2xl modifier")]
#[test_case("border-b-4 p-4" ; "with subcommand")]
#[test_case(" p-4 border-4" ; "when a statement has irregular gaps")]
#[test_case("dash-modifier:p-4" ; "when a modifier has a dash in it")]
Expand Down Expand Up @@ -150,7 +151,6 @@ mod test {

#[should_panic]
#[test_case("-mod:sub" ; "when the minus is in the wrong place")]
#[test_case("m0d:p-4" ; "when modifier has a number")]
#[test_case("()" ; "rejects empty group")]
fn parse_failure_tests(s: &str) {
let (rest, d) = Directive::parse(LocatedSpan::new_extra(s, DUMMY_SP)).unwrap();
Expand Down

0 comments on commit 8e20a03

Please sign in to comment.