nom icon indicating copy to clipboard operation
nom copied to clipboard

Proposal: extend usage of `nom::sequence::delimited` with `take_until_unbalanced`

Open getreu opened this issue 4 years ago • 4 comments
trafficstars

For my parse-hyperlinks - crate I implemented a parser for balanced nested brackets like in u<<>>r<>.

It is called parse_hyperlinks::take_until_unbalanced and it is designed to work with nom::sequence::delimited:

use nom::bytes::complete::tag;
use nom::sequence::delimited;
use parse_hyperlinks::take_until_unbalanced;

let mut parser = delimited(tag("<"), take_until_unbalanced('<', '>'), tag(">"));
assert_eq!(parser("<<inside>inside>abc"), Ok(("abc", "<inside>inside")));

I think the use case is so general, that you might want to integrate it into Nom. I implemented the code for &str, but as it only uses find, it should be easy to generalize. You can find my implementation here.

getreu avatar Nov 26 '20 14:11 getreu

FYI I used this to answer my SO question here: https://stackoverflow.com/questions/70630556/parse-allowing-nested-parentheses-in-nom

max-sixty avatar Jan 11 '22 09:01 max-sixty

Great! Hopefully it will also accept &str for brackets and be able to customize the escaped characters when integrated into nom. In my case, the brackets are { } and the escape characters are {{ }}.

SpriteOvO avatar Aug 01 '22 19:08 SpriteOvO

This made my day. Thank you so much for this magnificent function!

miguelsilva5989 avatar Dec 08 '22 22:12 miguelsilva5989

Has there been any discussions going on regarding this? I'd love to have this functionality built-in :)

andresovela avatar Sep 28 '23 20:09 andresovela