diff options
author | crupest <crupest@outlook.com> | 2021-09-13 15:51:02 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-09-13 15:51:02 +0800 |
commit | 9bc202a2e1664df3e3c148abfe90a90501bc1650 (patch) | |
tree | edb3f908ab30b0a6df498d47a38d9e1cefd7a7b1 | |
parent | fe45ee2dde28c995f1aa16a9cdc3119e00a26a8a (diff) | |
download | cru-9bc202a2e1664df3e3c148abfe90a90501bc1650.tar.gz cru-9bc202a2e1664df3e3c148abfe90a90501bc1650.tar.bz2 cru-9bc202a2e1664df3e3c148abfe90a90501bc1650.zip |
...
-rw-r--r-- | include/cru/common/String.hpp | 19 | ||||
-rw-r--r-- | include/cru/parse/Grammar.hpp | 3 | ||||
-rw-r--r-- | src/parse/Grammar.cpp | 2 |
3 files changed, 20 insertions, 4 deletions
diff --git a/include/cru/common/String.hpp b/include/cru/common/String.hpp index 8197c402..42143c9d 100644 --- a/include/cru/common/String.hpp +++ b/include/cru/common/String.hpp @@ -1,8 +1,8 @@ #pragma once #include "Base.hpp" -#include "StringUtil.hpp" #include "Range.hpp" +#include "StringUtil.hpp" #include <cstdint> #include <iterator> @@ -119,15 +119,28 @@ class CRU_BASE_API String { iterator insert(const_iterator pos, std::uint16_t value) { return this->insert(pos, &value, 1); } - iterator insert(const_iterator pos, std::uint16_t* str, Index size); + iterator insert(const_iterator pos, const std::uint16_t* str, Index size); iterator erase(const_iterator pos) { return this->erase(pos, pos + 1); } iterator erase(const_iterator start, const_iterator end); void push_back(std::uint16_t value) { this->append(value); } void pop_back() { this->erase(cend() - 1); } void append(std::uint16_t value) { this->insert(cend(), value); } - void append(std::uint16_t* str, Index size) { + void append(const std::uint16_t* str, Index size) { this->insert(cend(), str, size); } + void append(const String& other) { append(other.data(), other.size()); } + + public: + String& operator+=(const String& other) { + append(other); + return *this; + } + + String operator+(const String& other) const { + String result(*this); + result += other; + return result; + } public: Utf16CodePointIterator CodePointIterator() const { diff --git a/include/cru/parse/Grammar.hpp b/include/cru/parse/Grammar.hpp index 5b37ceba..659c4302 100644 --- a/include/cru/parse/Grammar.hpp +++ b/include/cru/parse/Grammar.hpp @@ -46,6 +46,9 @@ class Grammar : public Object { // Require grammar has no cycles or empty-productions. void EliminateLeftRecursions(); + // Algorithm 4.21 + void LeftFactor(); + private: Nonterminal* start_symbol_; std::vector<Terminal*> terminals_; diff --git a/src/parse/Grammar.cpp b/src/parse/Grammar.cpp index 3bd387d7..95c65e99 100644 --- a/src/parse/Grammar.cpp +++ b/src/parse/Grammar.cpp @@ -148,7 +148,7 @@ void Grammar::EliminateLeftRecursions() { auto new_right = right; new_right.insert(new_right.cbegin(), jp->GetRight().cbegin(), jp->GetRight().cend()); - CreateProduction(String{}, ni, std::move(new_right)); + CreateProduction(u"", ni, std::move(new_right)); } } } |