aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/common/log.hpp4
-rw-r--r--server/lexer/details/parse.cpp41
-rw-r--r--server/lexer/details/parse.hpp22
-rw-r--r--server/lexer/input.hpp6
-rw-r--r--server/lexer/lexer.cpp2
-rw-r--r--server/lexer/lexer.hpp2
-rw-r--r--server/lexer/token.hpp2
-rw-r--r--server/parser/parser.hpp2
8 files changed, 40 insertions, 41 deletions
diff --git a/server/common/log.hpp b/server/common/log.hpp
index 0d5bb19..52f96c1 100644
--- a/server/common/log.hpp
+++ b/server/common/log.hpp
@@ -41,12 +41,12 @@ inline void log(const std::string& msg) {
} // namespace details
template <typename... Args>
-inline void log(const std::string_view& fmt, Args&&... args) {
+inline void log(std::string_view fmt, Args&&... args) {
details::log(boost::str((boost::format(fmt.data()) % ... % args)));
}
template <typename... Args>
-inline void error(const std::string_view& fmt, Args&&... args) {
+inline void error(std::string_view fmt, Args&&... args) {
details::log(boost::str((boost::format(fmt.data()) % ... % args)));
}
diff --git a/server/lexer/details/parse.cpp b/server/lexer/details/parse.cpp
index 1ba8097..75072a4 100644
--- a/server/lexer/details/parse.cpp
+++ b/server/lexer/details/parse.cpp
@@ -26,7 +26,7 @@ class RegexMatcher {
public:
virtual ~RegexMatcher() = default;
- virtual bool match_regex(const std::string_view& input) = 0;
+ virtual bool match_regex(std::string_view input) = 0;
std::string_view to_view() const {
return {&*m_match[0].first, static_cast<std::size_t>(m_match[0].length())};
@@ -44,7 +44,7 @@ protected:
template <typename MatchResultsT>
class RegexNumberMatcher : public RegexMatcher<MatchResultsT> {
public:
- bool match(const std::string_view& input) {
+ bool match(std::string_view input) {
if (!this->match_regex(input)) {
return false;
}
@@ -78,7 +78,7 @@ private:
class StdNumberMatcher
: public RegexNumberMatcher<std::match_results<std::string_view::const_iterator>> {
public:
- bool match_regex(const std::string_view& input) override {
+ bool match_regex(std::string_view input) override {
return std::regex_search(input.cbegin(), input.cend(), m_match, get_regex());
}
@@ -94,7 +94,7 @@ private:
class BoostNumberMatcher
: public RegexNumberMatcher<boost::match_results<std::string_view::const_iterator>> {
public:
- bool match_regex(const std::string_view& input) override {
+ bool match_regex(std::string_view input) override {
return boost::regex_search(input.cbegin(), input.cend(), m_match, get_regex());
}
@@ -108,7 +108,7 @@ private:
};
template <typename MatchResultsT>
-std::optional<double> parse_number(const std::string_view& input,
+std::optional<double> parse_number(std::string_view input,
RegexNumberMatcher<MatchResultsT>&& matcher,
std::string_view& token) {
if (!matcher.match(input)) {
@@ -134,7 +134,7 @@ protected:
class StdWhitespaceMatcher
: public RegexWhitespaceMatcher<std::match_results<std::string_view::const_iterator>> {
public:
- bool match_regex(const std::string_view& input) override {
+ bool match_regex(std::string_view input) override {
return std::regex_search(input.cbegin(), input.cend(), m_match, get_regex());
}
@@ -149,7 +149,7 @@ private:
class BoostWhitespaceMatcher
: public RegexWhitespaceMatcher<boost::match_results<std::string_view::const_iterator>> {
public:
- bool match_regex(const std::string_view& input) override {
+ bool match_regex(std::string_view input) override {
return boost::regex_search(input.cbegin(), input.cend(), m_match, get_regex());
}
@@ -162,7 +162,7 @@ private:
};
template <typename MatchResultsT>
-std::string_view parse_whitespace(const std::string_view& input,
+std::string_view parse_whitespace(std::string_view input,
RegexWhitespaceMatcher<MatchResultsT>&& matcher) {
if (matcher.match_regex(input)) {
return matcher.to_view();
@@ -170,7 +170,7 @@ std::string_view parse_whitespace(const std::string_view& input,
return {};
}
-bool starts_with(const std::string_view& a, const std::string_view& b) noexcept {
+bool starts_with(std::string_view a, std::string_view b) noexcept {
return a.length() >= b.length() && a.compare(0, b.length(), b) == 0;
}
@@ -178,45 +178,44 @@ bool starts_with(const std::string_view& a, const std::string_view& b) noexcept
namespace impl {
-std::optional<double> std_parse_number(const std::string_view& input, std::string_view& token) {
+std::optional<double> std_parse_number(std::string_view input, std::string_view& token) {
return parse_number(input, StdNumberMatcher{}, token);
}
-std::optional<double> std_parse_number(const std::string_view& input) {
+std::optional<double> std_parse_number(std::string_view input) {
std::string_view token;
return std_parse_number(input, token);
}
-std::optional<double> boost_parse_number(const std::string_view& input, std::string_view& token) {
+std::optional<double> boost_parse_number(std::string_view input, std::string_view& token) {
return parse_number(input, BoostNumberMatcher{}, token);
}
-std::optional<double> boost_parse_number(const std::string_view& input) {
+std::optional<double> boost_parse_number(std::string_view input) {
std::string_view token;
return boost_parse_number(input, token);
}
-std::string_view std_parse_whitespace(const std::string_view& input) {
+std::string_view std_parse_whitespace(std::string_view input) {
return parse_whitespace(input, StdWhitespaceMatcher{});
}
-std::string_view boost_parse_whitespace(const std::string_view& input) {
+std::string_view boost_parse_whitespace(std::string_view input) {
return parse_whitespace(input, BoostWhitespaceMatcher{});
}
} // namespace impl
-std::optional<double> parse_number(const std::string_view& input, std::string_view& token) {
+std::optional<double> parse_number(std::string_view input, std::string_view& token) {
return impl::boost_parse_number(input, token);
}
-std::optional<double> parse_number(const std::string_view& input) {
+std::optional<double> parse_number(std::string_view input) {
std::string_view token;
return parse_number(input, token);
}
-std::optional<token::Type> parse_const_token(const std::string_view& input,
- std::string_view& token) {
+std::optional<token::Type> parse_const_token(std::string_view input, std::string_view& token) {
for (const auto type : token::const_tokens()) {
const auto str = token::type_to_string(type);
if (starts_with(input, str)) {
@@ -227,12 +226,12 @@ std::optional<token::Type> parse_const_token(const std::string_view& input,
return {};
}
-std::optional<token::Type> parse_const_token(const std::string_view& input) {
+std::optional<token::Type> parse_const_token(std::string_view input) {
std::string_view token;
return parse_const_token(input, token);
}
-std::string_view parse_whitespace(const std::string_view& input) {
+std::string_view parse_whitespace(std::string_view input) {
return impl::boost_parse_whitespace(input);
}
diff --git a/server/lexer/details/parse.hpp b/server/lexer/details/parse.hpp
index acf014b..d945c74 100644
--- a/server/lexer/details/parse.hpp
+++ b/server/lexer/details/parse.hpp
@@ -15,21 +15,21 @@ namespace impl {
// Exposed for benchmarking:
-std::optional<double> std_parse_number(const std::string_view&, std::string_view&);
-std::optional<double> std_parse_number(const std::string_view&);
-std::optional<double> boost_parse_number(const std::string_view&, std::string_view&);
-std::optional<double> boost_parse_number(const std::string_view&);
+std::optional<double> std_parse_number(std::string_view, std::string_view&);
+std::optional<double> std_parse_number(std::string_view);
+std::optional<double> boost_parse_number(std::string_view, std::string_view&);
+std::optional<double> boost_parse_number(std::string_view);
-std::string_view std_parse_whitespace(const std::string_view&);
-std::string_view boost_parse_whitespace(const std::string_view&);
+std::string_view std_parse_whitespace(std::string_view);
+std::string_view boost_parse_whitespace(std::string_view);
} // namespace impl
// Exposed for testing:
-std::string_view parse_whitespace(const std::string_view&);
-std::optional<double> parse_number(const std::string_view&, std::string_view&);
-std::optional<double> parse_number(const std::string_view&);
-std::optional<token::Type> parse_const_token(const std::string_view&, std::string_view&);
-std::optional<token::Type> parse_const_token(const std::string_view&);
+std::string_view parse_whitespace(std::string_view);
+std::optional<double> parse_number(std::string_view, std::string_view&);
+std::optional<double> parse_number(std::string_view);
+std::optional<token::Type> parse_const_token(std::string_view, std::string_view&);
+std::optional<token::Type> parse_const_token(std::string_view);
} // namespace math::server::lexer::details
diff --git a/server/lexer/input.hpp b/server/lexer/input.hpp
index 0e28b13..1f3b749 100644
--- a/server/lexer/input.hpp
+++ b/server/lexer/input.hpp
@@ -14,9 +14,9 @@ namespace math::server::lexer {
class Input {
public:
- explicit Input(const std::string_view& input) : m_pos{0}, m_input{input} {}
+ explicit Input(std::string_view input) : m_pos{0}, m_input{input} {}
- const std::string_view& get_input() const {
+ std::string_view get_input() const {
return m_input;
}
@@ -40,7 +40,7 @@ public:
m_input.remove_prefix(len);
}
- void consume(const std::string_view& sub) {
+ void consume(std::string_view sub) {
consume(sub.length());
}
diff --git a/server/lexer/lexer.cpp b/server/lexer/lexer.cpp
index e82e564..14ae24e 100644
--- a/server/lexer/lexer.cpp
+++ b/server/lexer/lexer.cpp
@@ -17,7 +17,7 @@
namespace math::server {
-Lexer::Lexer(const std::string_view& input) : Lexer{lexer::Input{input}} {}
+Lexer::Lexer(std::string_view input) : Lexer{lexer::Input{input}} {}
Lexer::Lexer(const lexer::Input& input) : m_input{input} {
consume_token();
diff --git a/server/lexer/lexer.hpp b/server/lexer/lexer.hpp
index 302eb66..ceddc08 100644
--- a/server/lexer/lexer.hpp
+++ b/server/lexer/lexer.hpp
@@ -18,7 +18,7 @@ namespace math::server {
class Lexer {
public:
- explicit Lexer(const std::string_view& input);
+ explicit Lexer(std::string_view input);
explicit Lexer(const lexer::Input& input);
using Token = lexer::Token;
diff --git a/server/lexer/token.hpp b/server/lexer/token.hpp
index 359536f..b045347 100644
--- a/server/lexer/token.hpp
+++ b/server/lexer/token.hpp
@@ -41,7 +41,7 @@ private:
class ParsedToken : public Token {
public:
- ParsedToken(Token&& token, std::size_t pos, const std::string_view& view)
+ ParsedToken(Token&& token, std::size_t pos, std::string_view view)
: Token{std::move(token)}, m_pos{pos}, m_view{view} {}
std::size_t get_pos() const {
diff --git a/server/parser/parser.hpp b/server/parser/parser.hpp
index 5b17f70..ddce8d9 100644
--- a/server/parser/parser.hpp
+++ b/server/parser/parser.hpp
@@ -24,7 +24,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(std::string_view input) : m_lexer{input} {}
double exec() {
const auto result = exec_dmas();