I'm using nom. I'd like to parse a string that's surrounded by parentheses, and allowing for additional nested parentheses within the string.
So (a + b)
would parse as a + b
, and ((a + b))
would parse as (a + b)
This works for the first case, but not the nested case:
pub fn parse_expr(input: &str) -> IResult<&str, &str> {
// TODO: this will fail with nested parentheses, but `rest` doesn't seem to
// be working.
delimited(tag("("), take_until(")"), tag(")"))(input)
}
I tried using rest
but this doesn't respect the final )
:
pub fn parse_expr(input: &str) -> IResult<&str, &str> {
delimited(tag("("), rest, tag(")"))(input)
}
Thanks!