aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/server/parser
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2020-01-13 08:39:02 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2020-01-13 08:42:08 +0300
commit6913c6d965d64481ed09fc06a43154f35e8bd914 (patch)
treefa8d3f360a651a31fba4b91a09a5bba505a904c4 /server/parser
parentTravis: only run clang-format on master (diff)
downloadmath-server-6913c6d965d64481ed09fc06a43154f35e8bd914.tar.gz
math-server-6913c6d965d64481ed09fc06a43154f35e8bd914.zip
clang-format all the code
Diffstat (limited to 'server/parser')
-rw-r--r--server/parser/error.hpp6
-rw-r--r--server/parser/operator.hpp13
-rw-r--r--server/parser/parser.hpp19
3 files changed, 14 insertions, 24 deletions
diff --git a/server/parser/error.hpp b/server/parser/error.hpp
index 66d6e45..6862a8f 100644
--- a/server/parser/error.hpp
+++ b/server/parser/error.hpp
@@ -13,9 +13,7 @@ namespace math::server {
class ParserError : public Error {
public:
- explicit ParserError(const std::string& what)
- : Error{"parser error: " + what}
- { }
+ explicit ParserError(const std::string& what) : Error{"parser error: " + what} {}
};
-}
+} // namespace math::server
diff --git a/server/parser/operator.hpp b/server/parser/operator.hpp
index fd45aa2..9030c65 100644
--- a/server/parser/operator.hpp
+++ b/server/parser/operator.hpp
@@ -5,10 +5,9 @@
#pragma once
-#include "error.hpp"
-
#include "../lexer/token.hpp"
#include "../lexer/token_type.hpp"
+#include "error.hpp"
#include <cmath>
@@ -72,9 +71,7 @@ public:
}
}
- bool is_left_associative() const {
- return !is_right_associative();
- }
+ bool is_left_associative() const { return !is_right_associative(); }
double exec(double lhs, double rhs) const {
switch (m_type) {
@@ -103,11 +100,9 @@ public:
}
private:
- explicit BinaryOp(const Token& token)
- : m_type{token.get_type()}
- { }
+ explicit BinaryOp(const Token& token) : m_type{token.get_type()} {}
Type m_type;
};
-}
+} // namespace math::server::parser
diff --git a/server/parser/parser.hpp b/server/parser/parser.hpp
index 0a8c761..844b36e 100644
--- a/server/parser/parser.hpp
+++ b/server/parser/parser.hpp
@@ -5,11 +5,10 @@
#pragma once
+#include "../lexer/lexer.hpp"
#include "error.hpp"
#include "operator.hpp"
-#include "../lexer/lexer.hpp"
-
#include <optional>
#include <string_view>
@@ -24,9 +23,7 @@ public:
// a finer algorithm for parsing arithmetic expressions.
// Reference: https://en.wikipedia.org/wiki/Operator-precedence_parser
- explicit Parser(const std::string_view& input)
- : m_lexer{input}
- { }
+ explicit Parser(const std::string_view& input) : m_lexer{input} {}
double exec() {
const auto result = exec_dmas();
@@ -38,9 +35,7 @@ public:
private:
// DMAS as in Division, Multiplication, Addition and Subtraction
- double exec_dmas() {
- return exec_binary_op(exec_factor(), parser::BinaryOp::min_precedence());
- }
+ double exec_dmas() { return exec_binary_op(exec_factor(), parser::BinaryOp::min_precedence()); }
// Exponentiation operator
double exec_exp() {
@@ -61,7 +56,8 @@ private:
{
const auto acc_left_assoc = next.is_left_associative() && next_prec > prev_prec;
- const auto acc_right_assoc = next.is_right_associative() && next_prec == prev_prec;
+ const auto acc_right_assoc =
+ next.is_right_associative() && next_prec == prev_prec;
const auto acc = acc_left_assoc || acc_right_assoc;
if (!acc) {
@@ -109,7 +105,8 @@ private:
if (m_lexer.drop_token_of_type(Type::LEFT_PAREN).has_value()) {
const auto inner = exec_dmas();
- if (!m_lexer.has_token() || !m_lexer.drop_token_of_type(Type::RIGHT_PAREN).has_value()) {
+ if (!m_lexer.has_token() ||
+ !m_lexer.drop_token_of_type(Type::RIGHT_PAREN).has_value()) {
throw ParserError{"missing closing ')'"};
}
return inner;
@@ -125,4 +122,4 @@ private:
Lexer m_lexer;
};
-}
+} // namespace math::server