diff --git a/components/core/src/clp_s/search/antlr_common/ErrorListener.hpp b/components/core/src/clp_s/search/antlr_common/ErrorListener.hpp new file mode 100644 index 000000000..8b05a29ca --- /dev/null +++ b/components/core/src/clp_s/search/antlr_common/ErrorListener.hpp @@ -0,0 +1,30 @@ +#ifndef CLP_S_SEARCH_ANTLRCOMMON_ERRORLISTENER_HPP +#define CLP_S_SEARCH_ANTLRCOMMON_ERRORLISTENER_HPP +#include + +namespace clp_s::search::antlr_common { +class ErrorListener : public antlr4::BaseErrorListener { +public: + void syntaxError( + antlr4::Recognizer* recognizer, + antlr4::Token* offending_symbol, + size_t line, + size_t char_position_in_line, + std::string const& msg, + std::exception_ptr e + ) override { + m_error = true; + m_error_message = msg; + } + + bool error() const { return m_error; } + + std::string const& message() const { return m_error_message; } + +private: + bool m_error{false}; + std::string m_error_message; +}; +} // namespace clp_s::search::antlr_common + +#endif // CLP_S_SEARCH_ANTLRCOMMON_ERRORLISTENER_HPP diff --git a/components/core/src/clp_s/search/kql/CMakeLists.txt b/components/core/src/clp_s/search/kql/CMakeLists.txt index ee36ee124..b15990180 100644 --- a/components/core/src/clp_s/search/kql/CMakeLists.txt +++ b/components/core/src/clp_s/search/kql/CMakeLists.txt @@ -8,6 +8,7 @@ ANTLR_TARGET( add_library( kql ../../Utils.hpp + ../antlr_common/ErrorListener.hpp ../AndExpr.hpp ../BooleanLiteral.hpp ../ColumnDescriptor.hpp diff --git a/components/core/src/clp_s/search/kql/kql.cpp b/components/core/src/clp_s/search/kql/kql.cpp index fa560cef5..80c9d0acf 100644 --- a/components/core/src/clp_s/search/kql/kql.cpp +++ b/components/core/src/clp_s/search/kql/kql.cpp @@ -13,6 +13,7 @@ #include "../../Utils.hpp" #include "../AndExpr.hpp" +#include "../antlr_common/ErrorListener.hpp" #include "../BooleanLiteral.hpp" #include "../ColumnDescriptor.hpp" #include "../DateLiteral.hpp" @@ -25,31 +26,10 @@ using namespace antlr4; using namespace kql; +using clp_s::search::antlr_common::ErrorListener; namespace clp_s::search::kql { -class ErrorListener : public BaseErrorListener { -public: - void syntaxError( - Recognizer* recognizer, - Token* offending_symbol, - size_t line, - size_t char_position_in_line, - std::string const& msg, - std::exception_ptr e - ) override { - m_error = true; - m_error_message = msg; - } - - bool error() const { return m_error; } - - std::string const& message() const { return m_error_message; } - -private: - bool m_error{false}; - std::string m_error_message; -}; - +namespace { class ParseTreeVisitor : public KqlBaseVisitor { private: static void @@ -224,6 +204,7 @@ class ParseTreeVisitor : public KqlBaseVisitor { return base; } }; +} // namespace std::shared_ptr parse_kql_expression(std::istream& in) { ErrorListener lexer_error_listener; diff --git a/components/core/src/clp_s/search/sql/CMakeLists.txt b/components/core/src/clp_s/search/sql/CMakeLists.txt index af2a8ef81..dde7f27cc 100644 --- a/components/core/src/clp_s/search/sql/CMakeLists.txt +++ b/components/core/src/clp_s/search/sql/CMakeLists.txt @@ -8,6 +8,7 @@ ANTLR_TARGET( add_library( sql ../../Utils.hpp + ../antlr_common/ErrorListener.hpp ../AndExpr.hpp ../BooleanLiteral.hpp ../ColumnDescriptor.hpp diff --git a/components/core/src/clp_s/search/sql/sql.cpp b/components/core/src/clp_s/search/sql/sql.cpp index 4004e8a17..53c9d560b 100644 --- a/components/core/src/clp_s/search/sql/sql.cpp +++ b/components/core/src/clp_s/search/sql/sql.cpp @@ -5,6 +5,7 @@ #include #include +#include "../antlr_common/ErrorListener.hpp" #include "../EmptyExpr.hpp" #include "SqlBaseVisitor.h" #include "SqlLexer.h" @@ -12,6 +13,7 @@ using namespace antlr4; using namespace sql; +using clp_s::search::antlr_common::ErrorListener; namespace clp_s::search::sql { class ErrorListener : public BaseErrorListener { @@ -37,10 +39,12 @@ class ErrorListener : public BaseErrorListener { std::string m_error_message; }; +namespace { class ParseTreeVisitor : public SqlBaseVisitor { public: std::any visitStart(SqlParser::StartContext* ctx) override { return EmptyExpr::create(); } }; +} // namespace std::shared_ptr parse_sql_expression(std::istream& in) { ErrorListener lexer_error_listener;