diff options
Diffstat (limited to '')
| -rw-r--r-- | .clang-format | 3 | ||||
| -rw-r--r-- | client/client.hpp | 5 | ||||
| -rw-r--r-- | client/settings.hpp | 31 | ||||
| -rw-r--r-- | client/transport.hpp | 6 | ||||
| -rw-r--r-- | server/lexer/details/parse.cpp | 17 | ||||
| -rw-r--r-- | server/lexer/token.cpp | 5 | ||||
| -rw-r--r-- | server/lexer/token_type.cpp | 10 | ||||
| -rw-r--r-- | server/main/server.cpp | 8 | ||||
| -rw-r--r-- | server/main/session.cpp | 8 | ||||
| -rw-r--r-- | server/main/settings.hpp | 6 | ||||
| -rw-r--r-- | test/unit_tests/lexer.cpp | 26 | ||||
| -rw-r--r-- | test/unit_tests/parser.cpp | 23 |
12 files changed, 94 insertions, 54 deletions
diff --git a/.clang-format b/.clang-format index ca228ce..4ce6542 100644 --- a/.clang-format +++ b/.clang-format @@ -5,14 +5,17 @@ BasedOnStyle: Chromium IndentWidth: 4 AccessModifierOffset: -4 +AlignAfterOpenBracket: BlockIndent AlignConsecutiveMacros: AcrossComments AllowShortFunctionsOnASingleLine: Empty BinPackArguments: false +BinPackParameters: OnePerLine BreakConstructorInitializers: BeforeComma BreakInheritanceList: BeforeComma BreakStringLiterals: false ColumnLimit: 100 IncludeBlocks: Regroup +PenaltyReturnTypeOnItsOwnLine: 1000 SpacesBeforeTrailingComments: 1 WrapNamespaceBodyWithEmptyLines: Always diff --git a/client/client.hpp b/client/client.hpp index 97b4c7c..4c6894e 100644 --- a/client/client.hpp +++ b/client/client.hpp @@ -25,8 +25,9 @@ public: void run() { m_input_reader->for_each_input([this](const std::string& input) { - m_transport->send_query(input, - [](const std::string& reply) { std::cout << reply << '\n'; }); + m_transport->send_query(input, [](const std::string& reply) { + std::cout << reply << '\n'; + }); return true; }); } diff --git a/client/settings.hpp b/client/settings.hpp index b351282..ea3f1d1 100644 --- a/client/settings.hpp +++ b/client/settings.hpp @@ -48,19 +48,24 @@ public: namespace po = boost::program_options; m_visible.add_options()("help,h", "show this message and exit"); - m_visible.add_options()("command,c", - po::value(&m_settings.m_input), - "evaluate the argument expression and exit"); - m_visible.add_options()("host,H", - po::value(&m_settings.m_host)->default_value("localhost"), - "server host address"); + m_visible.add_options()( + "command,c", po::value(&m_settings.m_input), "evaluate the argument expression and exit" + ); + m_visible.add_options()( + "host,H", + po::value(&m_settings.m_host)->default_value("localhost"), + "server host address" + ); m_visible.add_options()( "port,p", po::value(&m_settings.m_port)->default_value(NetworkTransport::DEFAULT_PORT), - "server port number"); - m_hidden.add_options()("files", - po::value<std::vector<std::string>>(&m_settings.m_files), - "shouldn't be visible"); + "server port number" + ); + m_hidden.add_options()( + "files", + po::value<std::vector<std::string>>(&m_settings.m_files), + "shouldn't be visible" + ); m_positional.add("files", -1); } @@ -73,8 +78,10 @@ public: po::options_description all; all.add(m_hidden).add(m_visible); - po::store(po::command_line_parser{argc, argv}.options(all).positional(m_positional).run(), - m_settings.m_vm); + po::store( + po::command_line_parser{argc, argv}.options(all).positional(m_positional).run(), + m_settings.m_vm + ); if (m_settings.exit_with_usage()) { return m_settings; } diff --git a/client/transport.hpp b/client/transport.hpp index 5bac4d3..57cacb0 100644 --- a/client/transport.hpp +++ b/client/transport.hpp @@ -97,8 +97,10 @@ private: boost::asio::streambuf m_buffer; }; -inline TransportPtr make_blocking_network_transport(const std::string& host, - const std::string& port) { +inline TransportPtr make_blocking_network_transport( + const std::string& host, + const std::string& port +) { return std::make_unique<BlockingNetworkTransport>(host, port); } diff --git a/server/lexer/details/parse.cpp b/server/lexer/details/parse.cpp index 75072a4..5df6254 100644 --- a/server/lexer/details/parse.cpp +++ b/server/lexer/details/parse.cpp @@ -63,7 +63,8 @@ protected: // numbers using a regex (the tests seem to pass though). // A proper NFA would be better, I guess. static constexpr std::string_view NUMBER_REGEX{ - R"REGEX(^(?:\d+(?:\.\d*)?|\.\d+)(e[+-]?(\d*))?)REGEX"}; + R"REGEX(^(?:\d+(?:\.\d*)?|\.\d+)(e[+-]?(\d*))?)REGEX" + }; private: bool matched_e() const { @@ -108,9 +109,11 @@ private: }; template <typename MatchResultsT> -std::optional<double> parse_number(std::string_view input, - RegexNumberMatcher<MatchResultsT>&& matcher, - std::string_view& token) { +std::optional<double> parse_number( + std::string_view input, + RegexNumberMatcher<MatchResultsT>&& matcher, + std::string_view& token +) { if (!matcher.match(input)) { return {}; } @@ -162,8 +165,10 @@ private: }; template <typename MatchResultsT> -std::string_view parse_whitespace(std::string_view input, - RegexWhitespaceMatcher<MatchResultsT>&& matcher) { +std::string_view parse_whitespace( + std::string_view input, + RegexWhitespaceMatcher<MatchResultsT>&& matcher +) { if (matcher.match_regex(input)) { return matcher.to_view(); } diff --git a/server/lexer/token.cpp b/server/lexer/token.cpp index 61ab1e7..e2d0a3f 100644 --- a/server/lexer/token.cpp +++ b/server/lexer/token.cpp @@ -49,8 +49,9 @@ bool Token::operator==(const Token& other) const { if (m_type == Type::NUMBER) { return numbers_equal(as_number(), other.as_number()); } - throw LexerError{"internal: can't compare tokens of type: " + - token::type_to_int_string(m_type)}; + throw LexerError{ + "internal: can't compare tokens of type: " + token::type_to_int_string(m_type) + }; } double Token::as_number() const { diff --git a/server/lexer/token_type.cpp b/server/lexer/token_type.cpp index b0ab9e0..d26e6a4 100644 --- a/server/lexer/token_type.cpp +++ b/server/lexer/token_type.cpp @@ -54,8 +54,9 @@ private: for (const auto& [type, str] : m_map) { const auto [_, inserted] = strings.emplace(str); if (!inserted) { - throw std::logic_error{"multiple tokens have the same string representation: " + - str}; + throw std::logic_error{ + "multiple tokens have the same string representation: " + str + }; } } } @@ -82,8 +83,9 @@ private: for (const auto& [type, str] : to_string) { const auto [_, inserted] = from_string.emplace(str, type); if (!inserted) { - throw std::logic_error{"multiple tokens have the same string representation: " + - str}; + throw std::logic_error{ + "multiple tokens have the same string representation: " + str + }; } } return from_string; diff --git a/server/main/server.cpp b/server/main/server.cpp index b27c551..4c0ab83 100644 --- a/server/main/server.cpp +++ b/server/main/server.cpp @@ -68,8 +68,9 @@ void Server::wait_for_signal() { m_signals.add(SIGINT); m_signals.add(SIGTERM); - m_signals.async_wait( - [this](const boost::system::error_code& ec, int signo) { handle_signal(ec, signo); }); + m_signals.async_wait([this](const boost::system::error_code& ec, int signo) { + handle_signal(ec, signo); + }); } catch (const boost::system::system_error& e) { throw Error{e.what()}; } @@ -94,7 +95,8 @@ void Server::accept() { const auto session = m_session_mgr.make_session(m_io_context); m_acceptor.async_accept( session->socket(), - [session, this](const boost::system::error_code& ec) { handle_accept(session, ec); }); + [session, this](const boost::system::error_code& ec) { handle_accept(session, ec); } + ); } void Server::handle_accept(SessionPtr session, const boost::system::error_code& ec) { diff --git a/server/main/session.cpp b/server/main/session.cpp index 31f37fc..b4b9fc5 100644 --- a/server/main/session.cpp +++ b/server/main/session.cpp @@ -75,7 +75,9 @@ void Session::read() { boost::asio::bind_executor( m_strand, [this, self](const boost::system::error_code& ec, std::size_t bytes) { handle_read(ec, bytes); - })); + } + ) + ); } void Session::handle_read(const boost::system::error_code& ec, std::size_t bytes) { @@ -108,7 +110,9 @@ void Session::write(const std::string& output) { boost::asio::bind_executor( m_strand, [this, self](const boost::system::error_code& ec, std::size_t bytes) { handle_write(ec, bytes); - })); + } + ) + ); } void Session::handle_write(const boost::system::error_code& ec, std::size_t) { diff --git a/server/main/settings.hpp b/server/main/settings.hpp index 16d9ecb..afe2f01 100644 --- a/server/main/settings.hpp +++ b/server/main/settings.hpp @@ -43,11 +43,13 @@ public: m_visible.add_options()( "port,p", po::value(&m_settings.m_port)->default_value(Settings::DEFAULT_PORT), - "server port number"); + "server port number" + ); m_visible.add_options()( "threads,n", po::value(&m_settings.m_threads)->default_value(Settings::default_threads()), - "number of threads"); + "number of threads" + ); } static const char* get_short_description() { diff --git a/test/unit_tests/lexer.cpp b/test/unit_tests/lexer.cpp index bfb752a..3a38416 100644 --- a/test/unit_tests/lexer.cpp +++ b/test/unit_tests/lexer.cpp @@ -149,26 +149,32 @@ BOOST_AUTO_TEST_CASE(test_parse_const_token) { BOOST_TEST(!details::parse_const_token("&+").has_value()); } -BOOST_DATA_TEST_CASE(test_get_tokens_valid, - bdata::make(get_tokens::valid::input) ^ get_tokens::valid::expected, - input, - expected) { +BOOST_DATA_TEST_CASE( + test_get_tokens_valid, + bdata::make(get_tokens::valid::input) ^ get_tokens::valid::expected, + input, + expected +) { Lexer lexer{input}; const auto actual = lexer.get_tokens(); BOOST_CHECK_EQUAL_COLLECTIONS( - actual.cbegin(), actual.cend(), expected.cbegin(), expected.cend()); + actual.cbegin(), actual.cend(), expected.cbegin(), expected.cend() + ); } -BOOST_DATA_TEST_CASE(test_get_tokens_invalid, - bdata::make(get_tokens::invalid::input) ^ get_tokens::invalid::error_msg, - input, - error_msg) { +BOOST_DATA_TEST_CASE( + test_get_tokens_invalid, + bdata::make(get_tokens::invalid::input) ^ get_tokens::invalid::error_msg, + input, + error_msg +) { BOOST_REQUIRE_THROW( do { Lexer lexer{input}; lexer.get_tokens(); } while (0), - LexerError); + LexerError + ); try { Lexer lexer{input}; diff --git a/test/unit_tests/parser.cpp b/test/unit_tests/parser.cpp index 641c4d6..c4c1fa0 100644 --- a/test/unit_tests/parser.cpp +++ b/test/unit_tests/parser.cpp @@ -114,24 +114,29 @@ const std::vector<std::string> error_msg{ BOOST_AUTO_TEST_SUITE(parser_tests) -BOOST_DATA_TEST_CASE(test_exec_valid, - bdata::make(exec::valid::input) ^ exec::valid::expected, - input, - expected) { +BOOST_DATA_TEST_CASE( + test_exec_valid, + bdata::make(exec::valid::input) ^ exec::valid::expected, + input, + expected +) { Parser parser{input}; BOOST_TEST(parser.exec() == expected); } -BOOST_DATA_TEST_CASE(test_exec_invalid, - bdata::make(exec::invalid::input) ^ exec::invalid::error_msg, - input, - error_msg) { +BOOST_DATA_TEST_CASE( + test_exec_invalid, + bdata::make(exec::invalid::input) ^ exec::invalid::error_msg, + input, + error_msg +) { BOOST_REQUIRE_THROW( do { Parser parser{input}; parser.exec(); } while (0), - ParserError); + ParserError + ); try { Parser parser{input}; |
