From 70297cec8122c0a0a7957664b60129e6809d57b6 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 31 May 2015 23:24:40 +0100 Subject: Add some experience to the flex, prefixes --- project2/files/configFlexLexer.cpp | 8 ++------ project2/files/configFlexLexer.h | 1 - project2/files/configuration.ll | 12 ++++++++++++ project2/files/optionsSource.cpp | 1 + project2/sql/sql.ll | 10 ++++++++-- project2/sql/sqlFlexLexer.cpp | 4 +++- project2/sql/sqlFlexLexer.h | 4 +++- 7 files changed, 29 insertions(+), 11 deletions(-) diff --git a/project2/files/configFlexLexer.cpp b/project2/files/configFlexLexer.cpp index fe44b0c..6d6f700 100644 --- a/project2/files/configFlexLexer.cpp +++ b/project2/files/configFlexLexer.cpp @@ -1,4 +1,5 @@ -#include "FlexLexer.h" +#define yyFlexLexer configBaseFlexLexer +#include #include "configFlexLexer.h" #include @@ -15,11 +16,6 @@ configFlexLexer::process() const consume(domain.empty() ? option : domain + "." + option, platform, value, currentPlatform); } -void -configFlexLexer::LexerOutput(const char *, int) -{ -} - void configFlexLexer::LexerError(const char * msg) { diff --git a/project2/files/configFlexLexer.h b/project2/files/configFlexLexer.h index 177f11c..180c1fa 100644 --- a/project2/files/configFlexLexer.h +++ b/project2/files/configFlexLexer.h @@ -9,7 +9,6 @@ class configFlexLexer : public yyFlexLexer { configFlexLexer(std::istream & in, const ConfigConsumer & consume, const Options::CurrentPlatform &); int yylex(); - void LexerOutput(const char *, int) override; void LexerError(const char * msg) override; private: diff --git a/project2/files/configuration.ll b/project2/files/configuration.ll index b3c8de7..aa04456 100644 --- a/project2/files/configuration.ll +++ b/project2/files/configuration.ll @@ -1,10 +1,15 @@ %option batch %option c++ %option noyywrap +%option 8bit +%option stack +%option yylineno %option yyclass="configFlexLexer" +%option prefix="configBase" %{ #include "configFlexLexer.h" +#pragma GCC diagnostic ignored "-Wsign-compare" %} element [a-zA-Z][a-zA-Z0-9_-]* @@ -62,3 +67,10 @@ value [^ ][^\r\n]* BEGIN(INITIAL); } +<*>[ \t\r\n\f] { +} + +<*>. { + throw std::runtime_error("Unexpected input"); +} + diff --git a/project2/files/optionsSource.cpp b/project2/files/optionsSource.cpp index 2ebebdb..8e98df0 100644 --- a/project2/files/optionsSource.cpp +++ b/project2/files/optionsSource.cpp @@ -1,6 +1,7 @@ #include #include #include "optionsSource.h" +#define yyFlexLexer configBaseFlexLexer #include #include "configFlexLexer.h" #include diff --git a/project2/sql/sql.ll b/project2/sql/sql.ll index 604a53d..ab40642 100644 --- a/project2/sql/sql.ll +++ b/project2/sql/sql.ll @@ -1,13 +1,16 @@ %option batch %option c++ %option noyywrap +%option 8bit +%option stack +%option yylineno %option yyclass="sqlFlexLexer" +%option prefix="sqlBase" %{ #include #include "sqlFlexLexer.h" -std::string comment; -std::string statement; +#pragma GCC diagnostic ignored "-Wsign-compare" %} space [ \t\n\r\f] @@ -115,3 +118,6 @@ p2mockscriptdir "$P2MOCKSCRIPTDIR" statement += YYText(); } +<*>[ \t\r\n\f] { +} + diff --git a/project2/sql/sqlFlexLexer.cpp b/project2/sql/sqlFlexLexer.cpp index cbf2416..eaacd50 100644 --- a/project2/sql/sqlFlexLexer.cpp +++ b/project2/sql/sqlFlexLexer.cpp @@ -1,3 +1,4 @@ +#define yyFlexLexer sqlBaseFlexLexer #include #include "sqlFlexLexer.h" #include @@ -10,8 +11,9 @@ sqlFlexLexer::sqlFlexLexer(const boost::filesystem::path & s, std::istream & f, } void -sqlFlexLexer::LexerOutput(const char *, int) +sqlFlexLexer::LexerError(const char * msg) { + throw std::runtime_error(msg); } void diff --git a/project2/sql/sqlFlexLexer.h b/project2/sql/sqlFlexLexer.h index fbaf799..55019e5 100644 --- a/project2/sql/sqlFlexLexer.h +++ b/project2/sql/sqlFlexLexer.h @@ -13,10 +13,12 @@ class sqlFlexLexer : public yyFlexLexer { std::string MockScriptDir() const; protected: - void LexerOutput(const char *, int) override; + void LexerError(const char *) override; private: DB::Connection * conn; const boost::filesystem::path script; + std::string comment; + std::string statement; }; -- cgit v1.2.3