nom
nom copied to clipboard
Proposal: extend usage of `nom::sequence::delimited` with `take_until_unbalanced`
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.
FYI I used this to answer my SO question here: https://stackoverflow.com/questions/70630556/parse-allowing-nested-parentheses-in-nom
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 {{ }}.
This made my day. Thank you so much for this magnificent function!
Has there been any discussions going on regarding this? I'd love to have this functionality built-in :)