#include "parser/parser.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include "cypher_lexer.h"
#pragma GCC diagnostic pop
#include "common/exception/parser.h"
#include "common/string_utils.h"
#include "parser/antlr_parser/lbug_cypher_parser.h"
#include "parser/antlr_parser/parser_error_listener.h"
#include "parser/antlr_parser/parser_error_strategy.h"
#include "parser/transformer.h"
using namespace antlr4;
namespace lbug {
namespace parser {
std::vector<std::shared_ptr<Statement>> Parser::parseQuery(std::string_view query,
std::vector<extension::TransformerExtension*> transformerExtensions) {
auto queryStr = std::string(query);
queryStr = common::StringUtils::ltrim(queryStr);
queryStr = common::StringUtils::ltrimNewlines(queryStr);
if (queryStr.empty()) {
throw common::ParserException(
"Cannot parse empty query. This should be handled in connection.");
}
auto inputStream = ANTLRInputStream(queryStr);
auto parserErrorListener = ParserErrorListener();
auto cypherLexer = CypherLexer(&inputStream);
cypherLexer.removeErrorListeners();
cypherLexer.addErrorListener(&parserErrorListener);
auto tokens = CommonTokenStream(&cypherLexer);
tokens.fill();
auto lbugCypherParser = LbugCypherParser(&tokens);
lbugCypherParser.removeErrorListeners();
lbugCypherParser.addErrorListener(&parserErrorListener);
lbugCypherParser.setErrorHandler(std::make_shared<ParserErrorStrategy>());
Transformer transformer(*lbugCypherParser.iC_Statements(), std::move(transformerExtensions));
return transformer.transform();
}
} }