From 42659d98143b0891db26523e7c176cd518a735e3 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 25 May 2015 19:54:45 +0100 Subject: Handle dollar quoting and new line whitespace --- project2/sql/sql.ll | 27 +++++++++++++++++++++++---- 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(); } -(.|\n) { +{any} { comment += YYText(); } @@ -57,6 +62,11 @@ quote_apos '' yy_push_state(QUOTE); } +{dollarquote} { + statement += YYText(); + yy_push_state(DOLLARQUOTE); +} + {quote} { statement += YYText(); yy_pop_state(); @@ -66,17 +76,26 @@ quote_apos '' statement += YYText(); } -. { +{any} { + statement += YYText(); +} + +{dollarquote} { + statement += YYText(); + yy_pop_state(); +} + +{any} { statement += YYText(); } -; { +{term} { Statement(statement); statement.clear(); yy_pop_state(); } -. { +{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$; + -- cgit v1.2.3