diff options
author | Li Jin <dragon-fly@qq.com> | 2018-03-05 14:18:35 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2018-03-05 14:18:35 +0800 |
commit | 525591758ce178e44da6aa3a11d557fd75b232e7 (patch) | |
tree | 27a2eaef7a47697888ad16ec5b27b9aee999ab71 /MoonParser/parser.hpp | |
parent | 3b270690501cfcc9220c8d5b63ab6f13fc2bd6b0 (diff) | |
download | yuescript-525591758ce178e44da6aa3a11d557fd75b232e7.tar.gz yuescript-525591758ce178e44da6aa3a11d557fd75b232e7.tar.bz2 yuescript-525591758ce178e44da6aa3a11d557fd75b232e7.zip |
refactoring some codes.
Diffstat (limited to '')
-rw-r--r-- | MoonParser/parser.hpp | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/MoonParser/parser.hpp b/MoonParser/parser.hpp index b280155..66d6067 100644 --- a/MoonParser/parser.hpp +++ b/MoonParser/parser.hpp | |||
@@ -13,8 +13,23 @@ | |||
13 | #include <string> | 13 | #include <string> |
14 | #include <list> | 14 | #include <list> |
15 | #include <functional> | 15 | #include <functional> |
16 | #include <codecvt> | ||
17 | #include <locale> | ||
16 | 18 | ||
17 | 19 | ||
20 | ///type of the parser's input. | ||
21 | typedef std::basic_string<char32_t> input; | ||
22 | typedef input::iterator input_it; | ||
23 | |||
24 | template<class Facet> | ||
25 | struct deletable_facet : Facet | ||
26 | { | ||
27 | template<class ...Args> | ||
28 | deletable_facet(Args&& ...args): Facet(std::forward<Args>(args)...) {} | ||
29 | ~deletable_facet() {} | ||
30 | }; | ||
31 | typedef std::wstring_convert<deletable_facet<std::codecvt<input::value_type, char, std::mbstate_t>>, input::value_type> Converter; | ||
32 | |||
18 | namespace parserlib { | 33 | namespace parserlib { |
19 | 34 | ||
20 | 35 | ||
@@ -24,9 +39,6 @@ class _context; | |||
24 | class rule; | 39 | class rule; |
25 | 40 | ||
26 | 41 | ||
27 | ///type of the parser's input. | ||
28 | typedef std::u32string input; | ||
29 | typedef input::iterator input_it; | ||
30 | struct item_t | 42 | struct item_t |
31 | { | 43 | { |
32 | input_it begin; | 44 | input_it begin; |
@@ -65,18 +77,13 @@ public: | |||
65 | /** character terminal constructor. | 77 | /** character terminal constructor. |
66 | @param c character. | 78 | @param c character. |
67 | */ | 79 | */ |
68 | expr(int c); | 80 | expr(char c); |
69 | 81 | ||
70 | /** null-terminated string terminal constructor. | 82 | /** null-terminated string terminal constructor. |
71 | @param s null-terminated string. | 83 | @param s null-terminated string. |
72 | */ | 84 | */ |
73 | expr(const char *s); | 85 | expr(const char *s); |
74 | 86 | ||
75 | /** null-terminated wide string terminal constructor. | ||
76 | @param s null-terminated string. | ||
77 | */ | ||
78 | expr(const wchar_t *s); | ||
79 | |||
80 | /** rule reference constructor. | 87 | /** rule reference constructor. |
81 | @param r rule. | 88 | @param r rule. |
82 | */ | 89 | */ |
@@ -195,18 +202,13 @@ public: | |||
195 | /** character terminal constructor. | 202 | /** character terminal constructor. |
196 | @param c character. | 203 | @param c character. |
197 | */ | 204 | */ |
198 | rule(int c); | 205 | rule(char c); |
199 | 206 | ||
200 | /** null-terminated string terminal constructor. | 207 | /** null-terminated string terminal constructor. |
201 | @param s null-terminated string. | 208 | @param s null-terminated string. |
202 | */ | 209 | */ |
203 | rule(const char *s); | 210 | rule(const char *s); |
204 | 211 | ||
205 | /** null-terminated wide string terminal constructor. | ||
206 | @param s null-terminated string. | ||
207 | */ | ||
208 | rule(const wchar_t *s); | ||
209 | |||
210 | /** constructor from expression. | 212 | /** constructor from expression. |
211 | @param e expression. | 213 | @param e expression. |
212 | */ | 214 | */ |
@@ -330,13 +332,6 @@ expr term(const expr &e); | |||
330 | expr set(const char *s); | 332 | expr set(const char *s); |
331 | 333 | ||
332 | 334 | ||
333 | /** creates a set expression from a null-terminated wide string. | ||
334 | @param s null-terminated string with characters of the set. | ||
335 | @return an expression which parses a single character out of a set. | ||
336 | */ | ||
337 | expr set(const wchar_t *s); | ||
338 | |||
339 | |||
340 | /** creates a range expression. | 335 | /** creates a range expression. |
341 | @param min min character. | 336 | @param min min character. |
342 | @param max max character. | 337 | @param max max character. |