/src/contrib/boost/spirit/home/support/detail/lexer/parser/tree/leaf_node.hpp

http://pythonocc.googlecode.com/ · C++ Header · 107 lines · 88 code · 14 blank · 5 comment · 5 complexity · 31e5fee0d8d7c53c66af4b30441e73d0 MD5 · raw file

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