From 2f77312b05dc9b80537002daca31d0f898a8b935 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 21 Sep 2015 00:49:14 +0100 Subject: Migrate SQL script parser and add support for executing a script on a connection --- project2/sql/sql.ll | 123 ------------------------------------------ project2/sql/sqlFlexLexer.cpp | 37 ------------- project2/sql/sqlFlexLexer.h | 24 --------- 3 files changed, 184 deletions(-) delete mode 100644 project2/sql/sql.ll delete mode 100644 project2/sql/sqlFlexLexer.cpp delete mode 100644 project2/sql/sqlFlexLexer.h diff --git a/project2/sql/sql.ll b/project2/sql/sql.ll deleted file mode 100644 index ab40642..0000000 --- a/project2/sql/sql.ll +++ /dev/null @@ -1,123 +0,0 @@ -%option batch -%option c++ -%option noyywrap -%option 8bit -%option stack -%option yylineno -%option yyclass="sqlFlexLexer" -%option prefix="sqlBase" - -%{ -#include -#include "sqlFlexLexer.h" -#pragma GCC diagnostic ignored "-Wsign-compare" -%} - -space [ \t\n\r\f] -non_newline [^\r\n] -mcomment_start "/*" -mcomment_stop "*/" -comment ("--"{non_newline}*) -other . -term ; -any ({other}|{space}) -quote ' -quote_apos '' -dolq_start [A-Za-z\200-\377_] -dolq_cont [A-Za-z\200-\377_0-9] -dollarquote \$({dolq_start}{dolq_cont}*)?\$ - -p2mockscriptdir "$P2MOCKSCRIPTDIR" - -%x COMMENT -%x STATEMENT -%x QUOTE -%x DOLLARQUOTE - -%% -{mcomment_start} { - comment += YYText(); - yy_push_state(COMMENT); -} - -{mcomment_stop} { - comment += YYText(); - Comment(comment); - comment.clear(); - yy_pop_state(); -} - -{any} { - comment += YYText(); -} - -<> { - throw std::runtime_error("Unterminated comment"); -} - -{comment} { - Comment(YYText()); -} - -{other} { - statement += YYText(); - yy_push_state(STATEMENT); -} - -{quote} { - statement += YYText(); - yy_push_state(QUOTE); -} - -{dollarquote} { - statement += YYText(); - yy_push_state(DOLLARQUOTE); -} - -{quote} { - statement += YYText(); - yy_pop_state(); -} - -{p2mockscriptdir} { - statement += MockScriptDir(); -} - -{quote_apos} { - statement += YYText(); -} - -{any} { - statement += YYText(); -} - -{dollarquote} { - statement += YYText(); - yy_pop_state(); -} - -<> { - throw std::runtime_error("Unterminated dollar quoted string"); -} - -{any} { - statement += YYText(); -} - -<> { - throw std::runtime_error("Unterminated quoted string"); -} - -{term} { - Statement(statement); - statement.clear(); - yy_pop_state(); -} - -{any} { - statement += YYText(); -} - -<*>[ \t\r\n\f] { -} - diff --git a/project2/sql/sqlFlexLexer.cpp b/project2/sql/sqlFlexLexer.cpp deleted file mode 100644 index eaacd50..0000000 --- a/project2/sql/sqlFlexLexer.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#define yyFlexLexer sqlBaseFlexLexer -#include -#include "sqlFlexLexer.h" -#include - -sqlFlexLexer::sqlFlexLexer(const boost::filesystem::path & s, std::istream & f, DB::Connection * c) : - yyFlexLexer(&f, NULL), - conn(c), - script(s) -{ -} - -void -sqlFlexLexer::LexerError(const char * msg) -{ - throw std::runtime_error(msg); -} - -void -sqlFlexLexer::Comment(const std::string & text) -{ - Logger()->messagebf(LOG_DEBUG, "Got comment: %s", text); -} - -void -sqlFlexLexer::Statement(const std::string & text) -{ - Logger()->messagebf(LOG_DEBUG, "Got statement: %s", text); - conn->execute(text); -} - -std::string -sqlFlexLexer::MockScriptDir() const -{ - return script.string(); -} - diff --git a/project2/sql/sqlFlexLexer.h b/project2/sql/sqlFlexLexer.h deleted file mode 100644 index 55019e5..0000000 --- a/project2/sql/sqlFlexLexer.h +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include -#include -#include - -class sqlFlexLexer : public yyFlexLexer { - public: - sqlFlexLexer(const boost::filesystem::path &, std::istream &, DB::Connection *); - int yylex(); - - void Comment(const std::string &); - void Statement(const std::string &); - std::string MockScriptDir() const; - - protected: - void LexerError(const char *) override; - - private: - DB::Connection * conn; - const boost::filesystem::path script; - std::string comment; - std::string statement; -}; - -- cgit v1.2.3