The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

The many1 nom Parser Panics With multispace0 in Rust

TODO: Pull subtitle into page object
Code
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.

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


Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

The many1 nom Parser Panics With multispace0 in Rust

Still learning how all this stuff works, but it seems
like `multispace0`` won't throw an error that
`many1`` needs to stop trying to process. I thought
`many1`` 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. 


-- code
-- 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))
}

-- p

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


-- code
-- rust

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




-- ref
-- url: https://docs.rs/nom/latest/nom/multi/fn.many1.html




-- categories
-- Rust 
-- nom 

-- metadata
-- date: 2023-07-19 20:30:16
-- id: 2sovezvx
-- site: aws
-- type: post
-- status: published