1 // leaf_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_LEAF_NODE_HPP 7 #define BOOST_SPIRIT_SUPPORT_DETAIL_LEXER_PARSER_TREE_LEAF_NODE_HPP 8 9 #include "../../consts.hpp" // null_token 10 #include "node.hpp" 11 #include "../../size_t.hpp" 12 13 namespace boost 14 { 15 namespace lexer 16 { 17 namespace detail 18 { 19 class leaf_node : public node 20 { 21 public: leaf_node(const std::size_t token_,const bool greedy_)22 leaf_node (const std::size_t token_, const bool greedy_) : 23 node (token_ == null_token), 24 _token (token_), 25 _set_greedy (!greedy_), 26 _greedy (greedy_) 27 { 28 if (!_nullable) 29 { 30 _firstpos.push_back (this); 31 _lastpos.push_back (this); 32 } 33 } 34 ~leaf_node()35 virtual ~leaf_node () 36 { 37 } 38 append_followpos(const node_vector & followpos_)39 virtual void append_followpos (const node_vector &followpos_) 40 { 41 for (node_vector::const_iterator iter_ = followpos_.begin (), 42 end_ = followpos_.end (); iter_ != end_; ++iter_) 43 { 44 _followpos.push_back (*iter_); 45 } 46 } 47 what_type() const48 virtual type what_type () const 49 { 50 return LEAF; 51 } 52 traverse(const_node_stack &,bool_stack &) const53 virtual bool traverse (const_node_stack &/*node_stack_*/, 54 bool_stack &/*perform_op_stack_*/) const 55 { 56 return false; 57 } 58 token() const59 virtual std::size_t token () const 60 { 61 return _token; 62 } 63 greedy(const bool greedy_)64 virtual void greedy (const bool greedy_) 65 { 66 if (!_set_greedy) 67 { 68 _greedy = greedy_; 69 _set_greedy = true; 70 } 71 } 72 greedy() const73 virtual bool greedy () const 74 { 75 return _greedy; 76 } 77 followpos() const78 virtual const node_vector &followpos () const 79 { 80 return _followpos; 81 } 82 followpos()83 virtual node_vector &followpos () 84 { 85 return _followpos; 86 } 87 88 private: 89 std::size_t _token; 90 bool _set_greedy; 91 bool _greedy; 92 node_vector _followpos; 93 copy_node(node_ptr_vector & node_ptr_vector_,node_stack & new_node_stack_,bool_stack &,bool &) const94 virtual void copy_node (node_ptr_vector &node_ptr_vector_, 95 node_stack &new_node_stack_, bool_stack &/*perform_op_stack_*/, 96 bool &/*down_*/) const 97 { 98 node_ptr_vector_->push_back (static_cast<leaf_node *>(0)); 99 node_ptr_vector_->back () = new leaf_node (_token, _greedy); 100 new_node_stack_.push (node_ptr_vector_->back ()); 101 } 102 }; 103 } 104 } 105 } 106 107 #endif 108