1 // iteration_node.hpp 2 // Copyright (c) 2007-2009 Ben Hanson (http://www.benhanson.net/) 3 // 4 // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 // file licence_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 #ifndef BOOST_SPIRIT_SUPPORT_DETAIL_LEXER_PARSER_TREE_ITERATION_NODE_HPP 7 #define BOOST_SPIRIT_SUPPORT_DETAIL_LEXER_PARSER_TREE_ITERATION_NODE_HPP 8 9 #include "node.hpp" 10 11 namespace boost 12 { 13 namespace lexer 14 { 15 namespace detail 16 { 17 class iteration_node : public node 18 { 19 public: iteration_node(node * next_,const bool greedy_)20 iteration_node (node *next_, const bool greedy_) : 21 node (true), 22 _next (next_), 23 _greedy (greedy_) 24 { 25 node_vector::iterator iter_; 26 node_vector::iterator end_; 27 28 _next->append_firstpos (_firstpos); 29 _next->append_lastpos (_lastpos); 30 31 for (iter_ = _lastpos.begin (), end_ = _lastpos.end (); 32 iter_ != end_; ++iter_) 33 { 34 (*iter_)->append_followpos (_firstpos); 35 } 36 37 for (iter_ = _firstpos.begin (), end_ = _firstpos.end (); 38 iter_ != end_; ++iter_) 39 { 40 (*iter_)->greedy (greedy_); 41 } 42 } 43 ~iteration_node()44 virtual ~iteration_node () 45 { 46 } 47 what_type() const48 virtual type what_type () const 49 { 50 return ITERATION; 51 } 52 traverse(const_node_stack & node_stack_,bool_stack & perform_op_stack_) const53 virtual bool traverse (const_node_stack &node_stack_, 54 bool_stack &perform_op_stack_) const 55 { 56 perform_op_stack_.push (true); 57 node_stack_.push (_next); 58 return true; 59 } 60 61 private: 62 // Not owner of this pointer... 63 node *_next; 64 bool _greedy; 65 copy_node(node_ptr_vector & node_ptr_vector_,node_stack & new_node_stack_,bool_stack & perform_op_stack_,bool & down_) const66 virtual void copy_node (node_ptr_vector &node_ptr_vector_, 67 node_stack &new_node_stack_, bool_stack &perform_op_stack_, 68 bool &down_) const 69 { 70 if (perform_op_stack_.top ()) 71 { 72 node *ptr_ = new_node_stack_.top (); 73 74 node_ptr_vector_->push_back (static_cast<iteration_node *>(0)); 75 node_ptr_vector_->back () = new iteration_node (ptr_, _greedy); 76 new_node_stack_.top () = node_ptr_vector_->back (); 77 } 78 else 79 { 80 down_ = true; 81 } 82 83 perform_op_stack_.pop (); 84 } 85 }; 86 } 87 } 88 } 89 90 #endif 91