use nom::{ branch::alt, character::complete::{char, line_ending}, combinator::{map, value}, multi::{many1, separated_list1}, IResult, }; use std::fs; fn main() -> Result<(), Box> { let input = fs::read_to_string("inputs/day_23.txt")?; let parsed = ForestMap::parser(&input).unwrap().1; dbg!(&parsed); Ok(()) } #[derive(Debug)] struct ForestMap(Vec>); #[derive(Debug, Clone)] enum ForestTile { Wall, Open, SlopeUp, SlopeDown, SlopeLeft, SlopeRight, } impl ForestMap { fn parser(input: &str) -> IResult<&str, Self> { map( separated_list1(line_ending, many1(ForestTile::parser)), ForestMap, )(input) } } impl ForestTile { fn parser(input: &str) -> IResult<&str, Self> { alt(( value(ForestTile::Wall, char('#')), value(ForestTile::Open, char('.')), value(ForestTile::SlopeUp, char('^')), value(ForestTile::SlopeDown, char('v')), value(ForestTile::SlopeLeft, char('<')), value(ForestTile::SlopeRight, char('>')), ))(input) } }