how does a separator in nom become an optional terminating separator?

Here’s one (of possibly many solutions).

Just use terminated along with opt:

pub fn parse_list(input: &str) -> IResult<&str, Vec<&str>> {
    delimited(
        ws(tag("[")),
        terminated(
            separated_list0(
                ws(tag(",")),
                take_while1(|x| char::is_alphabetic(x) || x == '_'),
            ),
            opt(ws(tag(","))),
        ),
        ws(tag("]")),
    )(input)
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top