diff options
author | Li Jin <dragon-fly@qq.com> | 2020-01-30 19:19:45 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2020-01-30 19:19:45 +0800 |
commit | 3f535edc133d7d6eb45ebf50627f3ee5deae1155 (patch) | |
tree | 35ea1b1733d01683dfe149b011e8ddb33912f5a8 /src | |
parent | f6a9052be67134aeaad59d0e6f4058dfd09ce324 (diff) | |
download | yuescript-3f535edc133d7d6eb45ebf50627f3ee5deae1155.tar.gz yuescript-3f535edc133d7d6eb45ebf50627f3ee5deae1155.tar.bz2 yuescript-3f535edc133d7d6eb45ebf50627f3ee5deae1155.zip |
make gcc happy.
Diffstat (limited to 'src')
-rw-r--r-- | src/MoonP/moon_compiler.cpp | 2 | ||||
-rw-r--r-- | src/MoonP/moon_parser.cpp | 20 | ||||
-rw-r--r-- | src/MoonP/moon_parser.h | 15 |
3 files changed, 23 insertions, 14 deletions
diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp index e804965..d3e78ed 100644 --- a/src/MoonP/moon_compiler.cpp +++ b/src/MoonP/moon_compiler.cpp | |||
@@ -381,7 +381,7 @@ private: | |||
381 | node->m_end.m_line = parent->m_begin.m_line; | 381 | node->m_end.m_line = parent->m_begin.m_line; |
382 | return traversal::Continue; | 382 | return traversal::Continue; |
383 | }); | 383 | }); |
384 | _codeCache.push_back(std::move(res.input)); | 384 | _codeCache.push_back(std::move(res.codes)); |
385 | return ast_ptr<false, T>(res.node.template to<T>()); | 385 | return ast_ptr<false, T>(res.node.template to<T>()); |
386 | } | 386 | } |
387 | 387 | ||
diff --git a/src/MoonP/moon_parser.cpp b/src/MoonP/moon_parser.cpp index 60096af..b2aba20 100644 --- a/src/MoonP/moon_parser.cpp +++ b/src/MoonP/moon_parser.cpp | |||
@@ -496,8 +496,8 @@ MoonParser::MoonParser() { | |||
496 | ParseInfo MoonParser::parse(const std::string& codes, rule& r) { | 496 | ParseInfo MoonParser::parse(const std::string& codes, rule& r) { |
497 | ParseInfo res; | 497 | ParseInfo res; |
498 | try { | 498 | try { |
499 | res.input = std::make_unique<input>(); | 499 | res.codes = std::make_unique<input>(); |
500 | *(res.input) = _converter.from_bytes(codes); | 500 | *(res.codes) = _converter.from_bytes(codes); |
501 | } catch (const std::range_error&) { | 501 | } catch (const std::range_error&) { |
502 | res.error = "Invalid text encoding."sv; | 502 | res.error = "Invalid text encoding."sv; |
503 | return res; | 503 | return res; |
@@ -505,7 +505,7 @@ ParseInfo MoonParser::parse(const std::string& codes, rule& r) { | |||
505 | error_list errors; | 505 | error_list errors; |
506 | try { | 506 | try { |
507 | State state; | 507 | State state; |
508 | res.node.set(pl::parse(*(res.input), r, errors, &state)); | 508 | res.node.set(pl::parse(*(res.codes), r, errors, &state)); |
509 | } catch (const std::logic_error& err) { | 509 | } catch (const std::logic_error& err) { |
510 | res.error = err.what(); | 510 | res.error = err.what(); |
511 | return res; | 511 | return res; |
@@ -536,12 +536,12 @@ std::string MoonParser::toString(input::iterator begin, input::iterator end) { | |||
536 | return _converter.to_bytes(std::wstring(begin, end)); | 536 | return _converter.to_bytes(std::wstring(begin, end)); |
537 | } | 537 | } |
538 | 538 | ||
539 | input MoonParser::encode(std::string_view input) { | 539 | input MoonParser::encode(std::string_view codes) { |
540 | return _converter.from_bytes(std::string(input)); | 540 | return _converter.from_bytes(std::string(codes)); |
541 | } | 541 | } |
542 | 542 | ||
543 | std::string MoonParser::decode(const input& input) { | 543 | std::string MoonParser::decode(const input& codes) { |
544 | return _converter.to_bytes(input); | 544 | return _converter.to_bytes(codes); |
545 | } | 545 | } |
546 | 546 | ||
547 | namespace Utils { | 547 | namespace Utils { |
@@ -557,10 +557,10 @@ namespace Utils { | |||
557 | std::string ParseInfo::errorMessage(std::string_view msg, const input_range* loc) const { | 557 | std::string ParseInfo::errorMessage(std::string_view msg, const input_range* loc) const { |
558 | const int ASCII = 255; | 558 | const int ASCII = 255; |
559 | int length = loc->m_begin.m_line; | 559 | int length = loc->m_begin.m_line; |
560 | auto begin = input->begin(); | 560 | auto begin = codes->begin(); |
561 | auto end = input->end(); | 561 | auto end = codes->end(); |
562 | int count = 0; | 562 | int count = 0; |
563 | for (auto it = input->begin(); it != input->end(); ++it) { | 563 | for (auto it = codes->begin(); it != codes->end(); ++it) { |
564 | if (*it == '\n') { | 564 | if (*it == '\n') { |
565 | if (count + 1 == length) { | 565 | if (count + 1 == length) { |
566 | end = it; | 566 | end = it; |
diff --git a/src/MoonP/moon_parser.h b/src/MoonP/moon_parser.h index 933aa7a..a0ad2fa 100644 --- a/src/MoonP/moon_parser.h +++ b/src/MoonP/moon_parser.h | |||
@@ -24,14 +24,17 @@ namespace MoonP { | |||
24 | struct ParseInfo { | 24 | struct ParseInfo { |
25 | ast_ptr<false,ast_node> node; | 25 | ast_ptr<false,ast_node> node; |
26 | std::string error; | 26 | std::string error; |
27 | std::unique_ptr<input> input; | 27 | std::unique_ptr<input> codes; |
28 | std::string errorMessage(std::string_view msg, const input_range* loc) const; | 28 | std::string errorMessage(std::string_view msg, const input_range* loc) const; |
29 | }; | 29 | }; |
30 | 30 | ||
31 | template<typename T> | ||
32 | struct identity { typedef T type; }; | ||
33 | |||
31 | #define AST_RULE(type) \ | 34 | #define AST_RULE(type) \ |
32 | rule type; \ | 35 | rule type; \ |
33 | ast<type##_t> type##_impl = type; \ | 36 | ast<type##_t> type##_impl = type; \ |
34 | template<> inline rule& getRule<type##_t>() { return type; } | 37 | inline rule& getRule(identity<type##_t>) { return type; } |
35 | 38 | ||
36 | extern std::unordered_set<std::string> LuaKeywords; | 39 | extern std::unordered_set<std::string> LuaKeywords; |
37 | extern std::unordered_set<std::string> Keywords; | 40 | extern std::unordered_set<std::string> Keywords; |
@@ -76,11 +79,17 @@ protected: | |||
76 | std::stack<bool> doStack; | 79 | std::stack<bool> doStack; |
77 | }; | 80 | }; |
78 | 81 | ||
82 | |||
83 | template <class T> | ||
84 | inline rule& getRule() { | ||
85 | return getRule(identity<T>()); | ||
86 | } | ||
87 | |||
79 | private: | 88 | private: |
80 | Converter _converter; | 89 | Converter _converter; |
81 | 90 | ||
82 | template <class T> | 91 | template <class T> |
83 | inline rule& getRule() { | 92 | inline rule& getRule(identity<T>) { |
84 | assert(false); | 93 | assert(false); |
85 | return Cut; | 94 | return Cut; |
86 | } | 95 | } |