ms705 / nom-sql

Rust SQL parser written using nom

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Optional multispace when next to parenthesis

ivanceras opened this issue · comments

These 2 queries

INSERT INTO user(name, password) VALUES('aaa','xxx');
INSERT INTO user (name, password) VALUES ('aaa','xxx');

are both valid, but nom-sql only parses the 2nd correctly.
I'm guessing this is a bit of complex to do in nom, where the multispace becomes optional when tag!('(') is in the next few bytes.

nom-sql/src/insert.rs

Lines 23 to 40 in 8fe4e92

table: table_reference ~
multispace ~
fields: opt!(chain!(
tag!("(") ~
multispace? ~
fields: field_list ~
multispace? ~
tag!(")") ~
multispace,
|| { fields }
)
) ~
caseless_tag!("values") ~
multispace ~
tag!("(") ~
values: value_list ~
tag!(")") ~
statement_terminator,

No underlying nom-related reason, just unawareness on my part that this is permitted!

(multispace? generally works fine for an optional space)

I thought the solution was more complicated than that.