diff options
-rw-r--r-- | libdbpp/sqlParse.ll | 8 | ||||
-rw-r--r-- | libdbpp/unittests/parseTest.sql | 9 | ||||
-rw-r--r-- | libdbpp/unittests/testParse.cpp | 16 |
3 files changed, 32 insertions, 1 deletions
diff --git a/libdbpp/sqlParse.ll b/libdbpp/sqlParse.ll index 835ce20..41d337a 100644 --- a/libdbpp/sqlParse.ll +++ b/libdbpp/sqlParse.ll @@ -13,10 +13,11 @@ %} space [ \t\n\r\f] +linespace [ \t] non_newline [^\r\n] mcomment_start ("/*"{space}*) mcomment_stop ({space}*"*/") -lcomment_start ({space}*"--"{space}*) +lcomment_start ({space}*"--"{linespace}*) other . term ; any ({other}|{space}) @@ -71,6 +72,11 @@ scriptdir "$SCRIPTDIR" yy_pop_state(); } +<LCOMMENT>[\r\n]+ { + Comment(comment); + yy_pop_state(); +} + <INITIAL>{term} { // Random terminator } diff --git a/libdbpp/unittests/parseTest.sql b/libdbpp/unittests/parseTest.sql index 6a3df82..5e1fbcd 100644 --- a/libdbpp/unittests/parseTest.sql +++ b/libdbpp/unittests/parseTest.sql @@ -4,6 +4,15 @@ CREATE TABLE name ( primary key(i) ); -- Single line comment +-- + -- + -- +-- + +/* Comment */ + /**/ + /* */ + /**/ INSERT INTO name(t, i) VALUES('string', 3); /* Multi line diff --git a/libdbpp/unittests/testParse.cpp b/libdbpp/unittests/testParse.cpp index 093cc7d..b5f3d65 100644 --- a/libdbpp/unittests/testParse.cpp +++ b/libdbpp/unittests/testParse.cpp @@ -56,6 +56,22 @@ BOOST_AUTO_TEST_CASE( parse ) p.Execute(); BOOST_REQUIRE_EQUAL(p.executed.size(), 3); BOOST_REQUIRE_EQUAL(p.executed[1], "INSERT INTO name(t, i) VALUES('string', 3)"); + auto cs = { + "Single line comment", + "", + "", + "", + "", + "Comment", + "", + "", + "", + "Multi line\n\t comment", + "! Stupid MySQL terminates", + "! comments with a ;", + "! Because reasons", + }; + BOOST_CHECK_EQUAL_COLLECTIONS(p.comments.begin(), p.comments.end(), cs.begin(), cs.end()); } BOOST_AUTO_TEST_CASE( parseDollarQuote ) |