Parsing successfully

This commit is contained in:
Daniel Flanagan 2023-12-12 10:43:43 -06:00
parent 397a95f2dc
commit 6f1199f3d2
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4

View file

@ -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<Mapping>)> {
// 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> {