diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-05-25 19:54:45 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-05-25 19:54:45 +0100 |
commit | 42659d98143b0891db26523e7c176cd518a735e3 (patch) | |
tree | 87812e98c6df17cfd8bebdb549398b94e2bf7d6d | |
parent | Use a flex based parser for SQL instead of a noddy upto ; based one (diff) | |
download | project2-42659d98143b0891db26523e7c176cd518a735e3.tar.bz2 project2-42659d98143b0891db26523e7c176cd518a735e3.tar.xz project2-42659d98143b0891db26523e7c176cd518a735e3.zip |
Handle dollar quoting and new line whitespace
-rw-r--r-- | project2/sql/sql.ll | 27 | ||||
-rw-r--r-- | project2/sql/unittests/pqschema.sql | 12 |
2 files changed, 35 insertions, 4 deletions
diff --git a/project2/sql/sql.ll b/project2/sql/sql.ll index 2127e3f..dd51742 100644 --- a/project2/sql/sql.ll +++ b/project2/sql/sql.ll @@ -10,17 +10,22 @@ std::string comment; std::string statement; %} +space [ \t\n\r\f] non_newline [^\r\n] mcomment_start "/*" mcomment_stop "*/" comment ("--"{non_newline}*) other . +term ; +any ({other}|{space}) quote ' quote_apos '' +dollarquote "$".[a-zA-Z]."$" %x COMMENT %x STATEMENT %x QUOTE +%x DOLLARQUOTE %% {mcomment_start} { @@ -35,7 +40,7 @@ quote_apos '' yy_pop_state(); } -<COMMENT>(.|\n) { +<COMMENT>{any} { comment += YYText(); } @@ -57,6 +62,11 @@ quote_apos '' yy_push_state(QUOTE); } +<STATEMENT>{dollarquote} { + statement += YYText(); + yy_push_state(DOLLARQUOTE); +} + <QUOTE>{quote} { statement += YYText(); yy_pop_state(); @@ -66,17 +76,26 @@ quote_apos '' statement += YYText(); } -<QUOTE>. { +<DOLLARQUOTE>{any} { + statement += YYText(); +} + +<DOLLARQUOTE>{dollarquote} { + statement += YYText(); + yy_pop_state(); +} + +<QUOTE>{any} { statement += YYText(); } -<STATEMENT>; { +<STATEMENT>{term} { Statement(statement); statement.clear(); yy_pop_state(); } -<STATEMENT>. { +<STATEMENT>{any} { statement += YYText(); } diff --git a/project2/sql/unittests/pqschema.sql b/project2/sql/unittests/pqschema.sql index 506365b..21277ca 100644 --- a/project2/sql/unittests/pqschema.sql +++ b/project2/sql/unittests/pqschema.sql @@ -2,10 +2,12 @@ -- pg_dump style comment -- Table: test; owner: comment: ; -- + /* This is a multiline comment */ + CREATE TABLE test( id int, fl numeric(5,2), @@ -13,4 +15,14 @@ CREATE TABLE test( boolean bool, dt timestamp without time zone, ts interval); + INSERT INTO test VALUES(4, 123.45, 'some text with a ; in it and a '' too', true, '2015-04-27 23:06:03', '1 day 14:13:12'); + +CREATE FUNCTION event_tsvector() RETURNS int +LANGUAGE sql STABLE +AS $tag$ + SELECT max(id) + FROM test + WHERE string != 'complex '' string;'; +$tag$; + |