Skip to content

Commit

Permalink
aoc/src/lib.rs: add lowercase_char and _str; export satisfy
Browse files Browse the repository at this point in the history
  • Loading branch information
lpenz committed Dec 21, 2023
1 parent 56770f5 commit 41f7933
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions aoc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub mod parser {
pub use nom::bytes::complete::tag;
pub use nom::character::complete as character;
pub use nom::character::complete::newline;
pub use nom::character::complete::satisfy;
pub use nom::combinator;
pub use nom::multi;
pub use nom::Finish;
Expand All @@ -40,6 +41,15 @@ pub mod parser {
pub fn space(input: &str) -> IResult<&str, &str> {
tag(" ")(input)
}

pub fn lowercase_char(input: &str) -> IResult<&str, char> {
satisfy(|c| c.is_ascii_lowercase())(input)
}

pub fn lowercase_str(input: &str) -> IResult<&str, String> {
let (input, cs) = multi::many1(lowercase_char)(input)?;
Ok((input, cs.into_iter().collect()))
}
}

pub trait OptionExt<T> {
Expand Down

0 comments on commit 41f7933

Please sign in to comment.