From 6f1199f3d25dde4c04cc278b465083857e83d6a5 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Tue, 12 Dec 2023 10:43:43 -0600 Subject: [PATCH] Parsing successfully --- 2023/rust/src/day5.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/2023/rust/src/day5.rs b/2023/rust/src/day5.rs index 734c534..3769054 100644 --- a/2023/rust/src/day5.rs +++ b/2023/rust/src/day5.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; extern crate nom; use nom::{ branch::alt, - bytes::complete::{tag, take_while}, + bytes::complete::{tag, take_until, take_while}, character::complete::{line_ending, newline, space1}, combinator::{map_res, value}, multi::separated_list0, @@ -80,11 +80,10 @@ fn mapping(input: &str) -> IResult<&str, Mapping> { } fn mapping_entry(input: &str) -> IResult<&str, (LayerDir, Vec)> { - // TODO: this is probably confusing my parser since the newline separator would need to lookahead? let (input, (from, _, to, _)) = tuple((layer, tag("-to-"), layer, tag(" map:\n")))(input)?; - // take while here + let (rest, input) = take_until("\n\n")(input)?; let (input, mappings) = separated_list0(newline, mapping)(input)?; - Ok((input, (LayerDir { from, to }, mappings))) + Ok((rest, (LayerDir { from, to }, mappings))) } fn almanac(input: &str) -> IResult<&str, Almanac> {