Explain my ridiculous use of parser combinators in day 2

master
Nick Krichevsky 2021-12-02 01:15:49 -05:00
parent 9d2099d76e
commit 548597cd41
1 changed files with 3 additions and 0 deletions

View File

@ -90,6 +90,9 @@ fn simulate(directions: &[Direction], part: &Part) -> i32 {
}
fn parse_line(line: &str) -> IResult<&str, Direction> {
// using a parser combinator to split a string
// https://i.imgur.com/B7bfMdE.jpg
// (I really just want to get practice with nom because it's fun)
let parse_direction = alt((tag("forward"), tag("down"), tag("up")));
let (_, (raw_direction, magnitude)) = terminated(
separated_pair(