| 19 | namespace parser { |
| 20 | |
| 21 | std::vector<std::shared_ptr<Statement>> Parser::parseQuery(std::string_view query, |
| 22 | std::vector<extension::TransformerExtension*> transformerExtensions) { |
| 23 | auto queryStr = std::string(query); |
| 24 | queryStr = common::StringUtils::ltrim(queryStr); |
| 25 | queryStr = common::StringUtils::ltrimNewlines(queryStr); |
| 26 | // LCOV_EXCL_START |
| 27 | // We should have enforced this in connection, but I also realize empty query will cause |
| 28 | // antlr to hang. So enforce a duplicate check here. |
| 29 | if (queryStr.empty()) { |
| 30 | throw common::ParserException( |
| 31 | "Cannot parse empty query. This should be handled in connection."); |
| 32 | } |
| 33 | // LCOV_EXCL_STOP |
| 34 | |
| 35 | auto inputStream = ANTLRInputStream(queryStr); |
| 36 | auto parserErrorListener = ParserErrorListener(); |
| 37 | |
| 38 | auto cypherLexer = CypherLexer(&inputStream); |
| 39 | cypherLexer.removeErrorListeners(); |
| 40 | cypherLexer.addErrorListener(&parserErrorListener); |
| 41 | auto tokens = CommonTokenStream(&cypherLexer); |
| 42 | tokens.fill(); |
| 43 | |
| 44 | auto lbugCypherParser = LbugCypherParser(&tokens); |
| 45 | lbugCypherParser.removeErrorListeners(); |
| 46 | lbugCypherParser.addErrorListener(&parserErrorListener); |
| 47 | lbugCypherParser.setErrorHandler(std::make_shared<ParserErrorStrategy>()); |
| 48 | |
| 49 | Transformer transformer(*lbugCypherParser.iC_Statements(), std::move(transformerExtensions)); |
| 50 | return transformer.transform(); |
| 51 | } |
| 52 | |
| 53 | } // namespace parser |
| 54 | } // namespace lbug |
no test coverage detected