From c7d114241818ab5f80f6b67daf2a80dfaf37817e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C5=A0torc?= <storcond@fit.cvut.cz> Date: Sat, 15 Apr 2023 16:15:49 +0200 Subject: [PATCH] cli: Rename new parser --- alib2cli/src/environment/Environment.cpp | 6 +++--- alib2cli/src/parser/{Parser2.cpp => Parser.cpp} | 8 ++++---- alib2cli/src/parser/{Parser2.h => Parser.h} | 2 +- alib2cli/test-src/aql/AqlParserTest.cpp | 4 ++-- alib2cli/test-src/aql/InvalidGrammarTest.cpp | 12 ++++++------ alib2cli/test-src/cli/common/TestLine.cpp | 4 ++-- aql2/src/REPL.cpp | 6 +++--- 7 files changed, 21 insertions(+), 21 deletions(-) rename alib2cli/src/parser/{Parser2.cpp => Parser.cpp} (86%) rename alib2cli/src/parser/{Parser2.h => Parser.h} (97%) diff --git a/alib2cli/src/environment/Environment.cpp b/alib2cli/src/environment/Environment.cpp index 1217d2977..6b4922118 100644 --- a/alib2cli/src/environment/Environment.cpp +++ b/alib2cli/src/environment/Environment.cpp @@ -2,7 +2,7 @@ #include <ext/exception> -#include <parser/Parser2.h> +#include <parser/Parser.h> #include <global/GlobalData.h> @@ -65,11 +65,11 @@ cli::CommandResult Environment::execute(const std::unique_ptr<cli::Command>& com } cli::CommandResult Environment::execute(const std::string& input) { - return execute(Parser2::parseString(input)); + return execute(Parser::parseString(input)); } cli::CommandResult Environment::execute(std::istream& input) { - return execute(Parser2::parseStream(input)); + return execute(Parser::parseStream(input)); } } /* namespace cli */ diff --git a/alib2cli/src/parser/Parser2.cpp b/alib2cli/src/parser/Parser.cpp similarity index 86% rename from alib2cli/src/parser/Parser2.cpp rename to alib2cli/src/parser/Parser.cpp index f2a450abd..4b9d45cc2 100644 --- a/alib2cli/src/parser/Parser2.cpp +++ b/alib2cli/src/parser/Parser.cpp @@ -2,20 +2,20 @@ #include <AltCliParser.h> #include <grammar/BufferedErrorListener.h> #include <parser/AltVisitor.h> -#include "Parser2.h" +#include "Parser.h" #include "antlr4-runtime.h" namespace cli { using namespace cli::grammar::parser; using namespace cli::grammar::lexer; -std::unique_ptr<CommandList> Parser2::parseString(const std::string& unit) +std::unique_ptr<CommandList> Parser::parseString(const std::string& unit) { antlr4::ANTLRInputStream inputStream(unit); return parse(inputStream); } -std::unique_ptr<CommandList> Parser2::parseStream(std::istream& istream) +std::unique_ptr<CommandList> Parser::parseStream(std::istream& istream) { antlr4::ANTLRInputStream fileStream; fileStream.load(istream); @@ -23,7 +23,7 @@ std::unique_ptr<CommandList> Parser2::parseStream(std::istream& istream) return parse(fileStream); } -std::unique_ptr<CommandList> Parser2::parse(antlr4::CharStream& stream) +std::unique_ptr<CommandList> Parser::parse(antlr4::CharStream& stream) { auto listener = std::make_shared<cli::grammar::BufferedErrorListener>(); diff --git a/alib2cli/src/parser/Parser2.h b/alib2cli/src/parser/Parser.h similarity index 97% rename from alib2cli/src/parser/Parser2.h rename to alib2cli/src/parser/Parser.h index b890d3dcc..76bf01148 100644 --- a/alib2cli/src/parser/Parser2.h +++ b/alib2cli/src/parser/Parser.h @@ -19,7 +19,7 @@ namespace cli { -struct Parser2 { +struct Parser { static std::unique_ptr<CommandList> parseString(const std::string& unit); static std::unique_ptr<CommandList> parseStream(std::istream& istream); diff --git a/alib2cli/test-src/aql/AqlParserTest.cpp b/alib2cli/test-src/aql/AqlParserTest.cpp index b8d8205a7..b2070f930 100644 --- a/alib2cli/test-src/aql/AqlParserTest.cpp +++ b/alib2cli/test-src/aql/AqlParserTest.cpp @@ -5,7 +5,7 @@ #include <fstream> #include <global/GlobalData.h> #include <iostream> -#include <parser/Parser2.h> +#include <parser/Parser.h> #include <regex> #include <unordered_set> using namespace std::literals; @@ -14,7 +14,7 @@ using namespace std::literals; std::unique_ptr<cli::CommandList> newParseFile(std::istream&& stream) { try { - return cli::Parser2::parseStream(stream); + return cli::Parser::parseStream(stream); } catch (...) { ext::ostringstream outErr; alib::ExceptionHandler::handle(outErr); diff --git a/alib2cli/test-src/aql/InvalidGrammarTest.cpp b/alib2cli/test-src/aql/InvalidGrammarTest.cpp index 898a54cb1..0b0cbd401 100644 --- a/alib2cli/test-src/aql/InvalidGrammarTest.cpp +++ b/alib2cli/test-src/aql/InvalidGrammarTest.cpp @@ -1,11 +1,11 @@ #include <catch2/catch.hpp> #include <exception/CommonException.h> -#include <parser/Parser2.h> +#include <parser/Parser.h> void newParseString(const std::string& str) { std::istringstream iss(str); - cli::Parser2::parseStream(iss); + cli::Parser::parseStream(iss); } TEST_CASE("Invalid grammar - Scope") @@ -81,11 +81,11 @@ TEST_CASE("Incomplete block") { SECTION("basic begin") { - CHECK_THROWS_AS(newParseString("begin"), cli::Parser2::ContinueException); + CHECK_THROWS_AS(newParseString("begin"), cli::Parser::ContinueException); } SECTION("nested begin") { - CHECK_THROWS_AS(newParseString("begin\nbegin\nendn"), cli::Parser2::ContinueException); + CHECK_THROWS_AS(newParseString("begin\nbegin\nendn"), cli::Parser::ContinueException); } } @@ -94,10 +94,10 @@ TEST_CASE("Incomplete string") { SECTION("basic string") { - CHECK_THROWS_AS(newParseString("print \""), cli::Parser2::ContinueException); + CHECK_THROWS_AS(newParseString("print \""), cli::Parser::ContinueException); } SECTION("nested begin") { - CHECK_THROWS_AS(newParseString("print IsSame \"test\" \"test"), cli::Parser2::ContinueException); + CHECK_THROWS_AS(newParseString("print IsSame \"test\" \"test"), cli::Parser::ContinueException); } } diff --git a/alib2cli/test-src/cli/common/TestLine.cpp b/alib2cli/test-src/cli/common/TestLine.cpp index 1efd8fcc3..ab546a12e 100644 --- a/alib2cli/test-src/cli/common/TestLine.cpp +++ b/alib2cli/test-src/cli/common/TestLine.cpp @@ -1,5 +1,5 @@ #include "TestLine.hpp" -#include "parser/Parser2.h" +#include "parser/Parser.h" #include <readline/StringLineInterface.h> @@ -9,7 +9,7 @@ void testLine(std::string line, cli::Environment& environment) { try { - cli::Parser2::parseString(line)->run(environment); + cli::Parser::parseString(line)->run(environment); } catch (...) { alib::ExceptionHandler::handle(common::Streams::err); throw; diff --git a/aql2/src/REPL.cpp b/aql2/src/REPL.cpp index 487e1464f..30e52fe06 100644 --- a/aql2/src/REPL.cpp +++ b/aql2/src/REPL.cpp @@ -1,7 +1,7 @@ #include <AltCliLexer.h> #include <functional> #include <grammar/Autocomplete.h> -#include <parser/Parser2.h> +#include <parser/Parser.h> #include <replxx.hxx> #include "REPL.h" @@ -49,8 +49,8 @@ cli::CommandResult REPL::run(cli::Environment& env) return rx.invoke(replxx::Replxx::ACTION::COMMIT_LINE, Replxx::KEY::ENTER); } try { - cli::Parser2::parseString(input); - } catch (const cli::Parser2::ContinueException&) { + cli::Parser::parseString(input); + } catch (const cli::Parser::ContinueException&) { return rx.invoke(Replxx::ACTION::NEW_LINE, Replxx::KEY::ENTER); } catch (const std::exception& e) { return rx.invoke(Replxx::ACTION::COMMIT_LINE, Replxx::KEY::ENTER); -- GitLab