diff options
Diffstat (limited to 'src/MoonP/ast.hpp')
-rw-r--r-- | src/MoonP/ast.hpp | 24 |
1 files changed, 1 insertions, 23 deletions
diff --git a/src/MoonP/ast.hpp b/src/MoonP/ast.hpp index 0b5ffca..38141e2 100644 --- a/src/MoonP/ast.hpp +++ b/src/MoonP/ast.hpp | |||
@@ -522,7 +522,6 @@ public: | |||
522 | ast(rule& r) { | 522 | ast(rule& r) { |
523 | r.set_parse_proc(&_parse_proc); | 523 | r.set_parse_proc(&_parse_proc); |
524 | } | 524 | } |
525 | |||
526 | private: | 525 | private: |
527 | //parse proc | 526 | //parse proc |
528 | static void _parse_proc(const pos& b, const pos& e, void* d) { | 527 | static void _parse_proc(const pos& b, const pos& e, void* d) { |
@@ -544,28 +543,7 @@ private: | |||
544 | @return pointer to ast node created, or null if there was an error. | 543 | @return pointer to ast node created, or null if there was an error. |
545 | The return object must be deleted by the caller. | 544 | The return object must be deleted by the caller. |
546 | */ | 545 | */ |
547 | ast_node* _parse(input& i, rule& g, error_list& el, void* ud); | 546 | ast_node* parse(input& i, rule& g, error_list& el, void* ud); |
548 | |||
549 | |||
550 | /** parses the given input. | ||
551 | @param i input. | ||
552 | @param g root rule of grammar. | ||
553 | @param el list of errors. | ||
554 | @param ud user data, passed to the parse procedures. | ||
555 | @return ast nodes. | ||
556 | */ | ||
557 | template <class T> ast_ptr<false, T> parse(input& i, rule& g, error_list& el, void* ud = nullptr) { | ||
558 | ast_node* node = _parse(i, g, el, ud); | ||
559 | T* ast = ast_cast<T>(node); | ||
560 | ast_ptr<false, T> ptr; | ||
561 | if (ast) { | ||
562 | ast_stack st{node}; | ||
563 | ptr.construct(st); | ||
564 | } else if (node) { | ||
565 | delete node; | ||
566 | } | ||
567 | return ptr; | ||
568 | } | ||
569 | 547 | ||
570 | 548 | ||
571 | } //namespace parserlib | 549 | } //namespace parserlib |