ms705 / nom-sql

Rust SQL parser written using nom

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Only match balanced parenthesis

tomharmon opened this issue · comments

In master (and on the incoming bump nom to v5 PR), compound_selection will match unbalanced paren pairs. We only want "(nested)" or "nested" to match, but using opt for both paren tags means that "nested)" and "(nested" will also match.

There may be other similar unbalanced issues with parens in other areas of the code or trailing commas.

This might work if the incoming bump nom to v5 PR is merged, but is definitely not pretty. Maybe it could be extracted into a "opt_parenthetical", ore more general opt_delimited :

alt(
    delimited(opt(tag("(")), nested_selection, opt(tag(")"))),
    nested_selection,
)

(line 110 of src/compound_select in the bump nom to v5 PR)