Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

The many1 nom Parser Panics With multispace0 in Rust

Still learning how all this stuff works, but it seems like [TODO: Code shorthand span ] won't throw an error that [TODO: Code shorthand span ] needs to stop trying to process. I thought [TODO: Code shorthand span ] would stop on it's own error, but I don't think that's the case. I think it only stops it if gets an error from a child parser.

rust
use nom::character::complete::multispace0;
use nom::multi::many1;
use nom::IResult;

fn main() {
    let source = "  -- alfa\n-- bravo\n\ncharlie\ndelta\n\necho\n\n-- foxtrot\n\ngolf\nhotel";
    dbg!(sections(source).unwrap());
}

fn sections(source: &str) -> IResult<&str, Vec<&str>> {
    dbg!(&source);
    let (source, sections) = many1(section)(source)?;
    Ok((source, sections))
}

fn section(source: &str) -> IResult<&str, &str> {
    dbg!(&source);
    let (source, section) = multispace0(source)?;
    Ok((source, section))
}

If you add something like this below the multispace line, the output shows two dashes and returns the rest of the content.

rust
let (source, section) = tag("-")(source)?;

Footnotes And References