aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/server/parser/parser.hpp
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/parser.hpp
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 '')
-rw-r--r--server/parser/parser.hpp19
1 files changed, 8 insertions, 11 deletions
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