rust-bakery / nom

Rust parser combinator framework
MIT License
9.35k stars 802 forks source link

feature request: `maybe_delimited` #1770

Open zeenix opened 1 month ago

zeenix commented 1 month ago

I would like something like:

delimited(
    opt(char('(')),
    many1(my_parser),
    opt(char(')'),
)

so that outer () are optional but I would only want them optional together so unmatched () are treated as an error.

A maybe_delimited function that treats the delimiters as optional in combination, would help with this.

Test case

I cant provide this if needed but of course it would not work currently. :)

scnerd commented 4 weeks ago

Could be easily written as alt(body | delimited(left, body, right)), right?