Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:47:49

0001 // leaf_node.hpp
0002 // Copyright (c) 2007-2009 Ben Hanson (http://www.benhanson.net/)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file licence_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 #ifndef BOOST_SPIRIT_SUPPORT_DETAIL_LEXER_PARSER_TREE_LEAF_NODE_HPP
0007 #define BOOST_SPIRIT_SUPPORT_DETAIL_LEXER_PARSER_TREE_LEAF_NODE_HPP
0008 
0009 #include "../../consts.hpp" // null_token
0010 #include "node.hpp"
0011 #include "../../size_t.hpp"
0012 
0013 namespace boost
0014 {
0015 namespace lexer
0016 {
0017 namespace detail
0018 {
0019 class leaf_node : public node
0020 {
0021 public:
0022     leaf_node (const std::size_t token_, const bool greedy_) :
0023         node (token_ == null_token),
0024         _token (token_),
0025         _set_greedy (!greedy_),
0026         _greedy (greedy_)
0027     {
0028         if (!_nullable)
0029         {
0030             _firstpos.push_back (this);
0031             _lastpos.push_back (this);
0032         }
0033     }
0034 
0035     virtual ~leaf_node ()
0036     {
0037     }
0038 
0039     virtual void append_followpos (const node_vector &followpos_)
0040     {
0041         for (node_vector::const_iterator iter_ = followpos_.begin (),
0042             end_ = followpos_.end (); iter_ != end_; ++iter_)
0043         {
0044             _followpos.push_back (*iter_);
0045         }
0046     }
0047 
0048     virtual type what_type () const
0049     {
0050         return LEAF;
0051     }
0052 
0053     virtual bool traverse (const_node_stack &/*node_stack_*/,
0054         bool_stack &/*perform_op_stack_*/) const
0055     {
0056         return false;
0057     }
0058 
0059     virtual std::size_t token () const
0060     {
0061         return _token;
0062     }
0063 
0064     virtual void greedy (const bool greedy_)
0065     {
0066         if (!_set_greedy)
0067         {
0068             _greedy = greedy_;
0069             _set_greedy = true;
0070         }
0071     }
0072 
0073     virtual bool greedy () const
0074     {
0075         return _greedy;
0076     }
0077 
0078     virtual const node_vector &followpos () const
0079     {
0080         return _followpos;
0081     }
0082 
0083     virtual node_vector &followpos ()
0084     {
0085         return _followpos;
0086     }
0087 
0088 private:
0089     std::size_t _token;
0090     bool _set_greedy;
0091     bool _greedy;
0092     node_vector _followpos;
0093 
0094     virtual void copy_node (node_ptr_vector &node_ptr_vector_,
0095         node_stack &new_node_stack_, bool_stack &/*perform_op_stack_*/,
0096         bool &/*down_*/) const
0097     {
0098         node_ptr_vector_->push_back (static_cast<leaf_node *>(0));
0099         node_ptr_vector_->back () = new leaf_node (_token, _greedy);
0100         new_node_stack_.push (node_ptr_vector_->back ());
0101     }
0102 };
0103 }
0104 }
0105 }
0106 
0107 #endif