Function aoc_parse::prelude::aoc_parse

source ·
pub fn aoc_parse<P, T, E>(puzzle_input: &str, parser: P) -> Result<T, E>where
    E: From<ParseError>,
    P: for<'p, 's> Parser<'p, 's, Output = T>,
Expand description

Parse the given puzzle input supplied by #[aoc_generator].

This function is like parser.parse(puzzle_input) except that #[aoc_generator] unfortunately strips off trailing newlines. This function therefore checks to see if the last line is missing its final \n and, if so, re-adds it before parsing.

Example

use aoc_runner_derive::*;
use aoc_parse::{parser, prelude::*};

#[aoc_generator(day1)]
fn parse_input(text: &str) -> anyhow::Result<Vec<Vec<u64>>> {
    let p = parser!(repeat_sep(lines(u64), "\n"));
    aoc_parse(text, p)
}