diff options
Diffstat (limited to 'src/MoonP/parser.cpp')
| -rw-r--r-- | src/MoonP/parser.cpp | 50 |
1 files changed, 21 insertions, 29 deletions
diff --git a/src/MoonP/parser.cpp b/src/MoonP/parser.cpp index 94f80af..cb896c2 100644 --- a/src/MoonP/parser.cpp +++ b/src/MoonP/parser.cpp | |||
| @@ -21,25 +21,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |||
| 21 | namespace parserlib { | 21 | namespace parserlib { |
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | //internal map from rules to parse procs | ||
| 25 | typedef std::unordered_map<rule *, parse_proc> _parse_proc_map_t; | ||
| 26 | |||
| 27 | //on exit, it deletes the parse proc map | ||
| 28 | static _parse_proc_map_t& _get_parse_proc_map() { | ||
| 29 | static _parse_proc_map_t _parse_proc_map; | ||
| 30 | return _parse_proc_map; | ||
| 31 | } | ||
| 32 | |||
| 33 | |||
| 34 | //get the parse proc from the map | ||
| 35 | static parse_proc _get_parse_proc(rule *r) { | ||
| 36 | _parse_proc_map_t& _parse_proc_map = _get_parse_proc_map(); | ||
| 37 | _parse_proc_map_t::iterator it = _parse_proc_map.find(r); | ||
| 38 | if (it == _parse_proc_map.end()) return 0; | ||
| 39 | return it->second; | ||
| 40 | } | ||
| 41 | |||
| 42 | |||
| 43 | //internal private class that manages access to the public classes' internals. | 24 | //internal private class that manages access to the public classes' internals. |
| 44 | class _private { | 25 | class _private { |
| 45 | public: | 26 | public: |
| @@ -1175,14 +1156,19 @@ bool error::operator < (const error &e) const { | |||
| 1175 | return m_begin.m_it < e.m_begin.m_it; | 1156 | return m_begin.m_it < e.m_begin.m_it; |
| 1176 | } | 1157 | } |
| 1177 | 1158 | ||
| 1159 | rule::rule() : | ||
| 1160 | m_expr(nullptr), | ||
| 1161 | m_parse_proc(nullptr) | ||
| 1162 | { | ||
| 1163 | } | ||
| 1178 | 1164 | ||
| 1179 | /** character terminal constructor. | 1165 | /** character terminal constructor. |
| 1180 | @param c character. | 1166 | @param c character. |
| 1181 | */ | 1167 | */ |
| 1182 | rule::rule(char c) : | 1168 | rule::rule(char c) : |
| 1183 | m_expr(new _char(c)) | 1169 | m_expr(new _char(c)), |
| 1170 | m_parse_proc(nullptr) | ||
| 1184 | { | 1171 | { |
| 1185 | m_parse_proc = _get_parse_proc(this); | ||
| 1186 | } | 1172 | } |
| 1187 | 1173 | ||
| 1188 | 1174 | ||
| @@ -1190,9 +1176,9 @@ rule::rule(char c) : | |||
| 1190 | @param s null-terminated string. | 1176 | @param s null-terminated string. |
| 1191 | */ | 1177 | */ |
| 1192 | rule::rule(const char *s) : | 1178 | rule::rule(const char *s) : |
| 1193 | m_expr(new _string(s)) | 1179 | m_expr(new _string(s)), |
| 1180 | m_parse_proc(nullptr) | ||
| 1194 | { | 1181 | { |
| 1195 | m_parse_proc = _get_parse_proc(this); | ||
| 1196 | } | 1182 | } |
| 1197 | 1183 | ||
| 1198 | 1184 | ||
| @@ -1200,9 +1186,9 @@ rule::rule(const char *s) : | |||
| 1200 | @param e expression. | 1186 | @param e expression. |
| 1201 | */ | 1187 | */ |
| 1202 | rule::rule(const expr &e) : | 1188 | rule::rule(const expr &e) : |
| 1203 | m_expr(_private::get_expr(e)) | 1189 | m_expr(_private::get_expr(e)), |
| 1190 | m_parse_proc(nullptr) | ||
| 1204 | { | 1191 | { |
| 1205 | m_parse_proc = _get_parse_proc(this); | ||
| 1206 | } | 1192 | } |
| 1207 | 1193 | ||
| 1208 | 1194 | ||
| @@ -1211,11 +1197,19 @@ rule::rule(const expr &e) : | |||
| 1211 | */ | 1197 | */ |
| 1212 | rule::rule(rule &r) : | 1198 | rule::rule(rule &r) : |
| 1213 | m_expr(new _ref(r)), | 1199 | m_expr(new _ref(r)), |
| 1214 | m_parse_proc(0) | 1200 | m_parse_proc(nullptr) |
| 1215 | { | 1201 | { |
| 1216 | m_parse_proc = _get_parse_proc(this); | ||
| 1217 | } | 1202 | } |
| 1218 | 1203 | ||
| 1204 | rule& rule::operator = (rule & r) { | ||
| 1205 | m_expr = new _ref(r); | ||
| 1206 | return *this; | ||
| 1207 | } | ||
| 1208 | |||
| 1209 | rule &rule::operator = (const expr & e) { | ||
| 1210 | m_expr = _private::get_expr(e); | ||
| 1211 | return *this; | ||
| 1212 | } | ||
| 1219 | 1213 | ||
| 1220 | /** invalid constructor from rule (required by gcc). | 1214 | /** invalid constructor from rule (required by gcc). |
| 1221 | @exception std::logic_error always thrown. | 1215 | @exception std::logic_error always thrown. |
| @@ -1278,8 +1272,6 @@ expr rule::operator !() { | |||
| 1278 | void rule::set_parse_proc(parse_proc p) { | 1272 | void rule::set_parse_proc(parse_proc p) { |
| 1279 | assert(p); | 1273 | assert(p); |
| 1280 | m_parse_proc = p; | 1274 | m_parse_proc = p; |
| 1281 | _parse_proc_map_t& _parse_proc_map = _get_parse_proc_map(); | ||
| 1282 | _parse_proc_map[this] = p; | ||
| 1283 | } | 1275 | } |
| 1284 | 1276 | ||
| 1285 | 1277 | ||
