no_actions.hpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*=============================================================================
  2. Copyright (c) 1998-2003 Joel de Guzman
  3. Copyright (c) 2003 Vaclav Vesely
  4. http://spirit.sourceforge.net/
  5. Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. =============================================================================*/
  8. #if !defined(BOOST_SPIRIT_NO_ACTIONS_HPP)
  9. #define BOOST_SPIRIT_NO_ACTIONS_HPP
  10. #include <boost/spirit/home/classic/core/parser.hpp>
  11. #include <boost/spirit/home/classic/core/composite/composite.hpp>
  12. #include <boost/spirit/home/classic/core/non_terminal/rule.hpp>
  13. namespace boost {
  14. namespace spirit {
  15. BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
  16. //-----------------------------------------------------------------------------
  17. // no_actions_action_policy
  18. template<typename BaseT = action_policy>
  19. struct no_actions_action_policy:
  20. public BaseT
  21. {
  22. typedef BaseT base_t;
  23. no_actions_action_policy():
  24. BaseT()
  25. {}
  26. template<typename PolicyT>
  27. no_actions_action_policy(PolicyT const& other):
  28. BaseT(other)
  29. {}
  30. template<typename ActorT, typename AttrT, typename IteratorT>
  31. void
  32. do_action(
  33. ActorT const& /*actor*/,
  34. AttrT& /*val*/,
  35. IteratorT const& /*first*/,
  36. IteratorT const& /*last*/) const
  37. {}
  38. };
  39. //-----------------------------------------------------------------------------
  40. // no_actions_scanner
  41. namespace detail
  42. {
  43. template <typename ActionPolicy>
  44. struct compute_no_actions_action_policy
  45. {
  46. typedef no_actions_action_policy<ActionPolicy> type;
  47. };
  48. template <typename ActionPolicy>
  49. struct compute_no_actions_action_policy<no_actions_action_policy<ActionPolicy> >
  50. {
  51. typedef no_actions_action_policy<ActionPolicy> type;
  52. };
  53. }
  54. template<typename ScannerT = scanner<> >
  55. struct no_actions_scanner
  56. {
  57. typedef scanner_policies<
  58. typename ScannerT::iteration_policy_t,
  59. typename ScannerT::match_policy_t,
  60. typename detail::compute_no_actions_action_policy<typename ScannerT::action_policy_t>::type
  61. > policies_t;
  62. typedef typename
  63. rebind_scanner_policies<ScannerT, policies_t>::type type;
  64. };
  65. #if BOOST_SPIRIT_RULE_SCANNERTYPE_LIMIT > 1
  66. template<typename ScannerT = scanner<> >
  67. struct no_actions_scanner_list
  68. {
  69. typedef
  70. scanner_list<
  71. ScannerT,
  72. typename no_actions_scanner<ScannerT>::type
  73. >
  74. type;
  75. };
  76. #endif // BOOST_SPIRIT_RULE_SCANNERTYPE_LIMIT > 1
  77. //-----------------------------------------------------------------------------
  78. // no_actions_parser
  79. struct no_actions_parser_gen;
  80. template<typename ParserT>
  81. struct no_actions_parser:
  82. public unary<ParserT, parser<no_actions_parser<ParserT> > >
  83. {
  84. typedef no_actions_parser<ParserT> self_t;
  85. typedef unary_parser_category parser_category_t;
  86. typedef no_actions_parser_gen parser_generator_t;
  87. typedef unary<ParserT, parser<self_t> > base_t;
  88. template<typename ScannerT>
  89. struct result
  90. {
  91. typedef typename parser_result<ParserT, ScannerT>::type type;
  92. };
  93. no_actions_parser(ParserT const& p)
  94. : base_t(p)
  95. {}
  96. template<typename ScannerT>
  97. typename result<ScannerT>::type
  98. parse(ScannerT const& scan) const
  99. {
  100. typedef typename no_actions_scanner<ScannerT>::policies_t policies_t;
  101. return this->subject().parse(scan.change_policies(policies_t(scan)));
  102. }
  103. };
  104. //-----------------------------------------------------------------------------
  105. // no_actions_parser_gen
  106. struct no_actions_parser_gen
  107. {
  108. template<typename ParserT>
  109. struct result
  110. {
  111. typedef no_actions_parser<ParserT> type;
  112. };
  113. template<typename ParserT>
  114. static no_actions_parser<ParserT>
  115. generate(parser<ParserT> const& subject)
  116. {
  117. return no_actions_parser<ParserT>(subject.derived());
  118. }
  119. template<typename ParserT>
  120. no_actions_parser<ParserT>
  121. operator[](parser<ParserT> const& subject) const
  122. {
  123. return no_actions_parser<ParserT>(subject.derived());
  124. }
  125. };
  126. //-----------------------------------------------------------------------------
  127. // no_actions_d
  128. const no_actions_parser_gen no_actions_d = no_actions_parser_gen();
  129. //-----------------------------------------------------------------------------
  130. BOOST_SPIRIT_CLASSIC_NAMESPACE_END
  131. } // namespace spirit
  132. } // namespace boost
  133. #endif // !defined(BOOST_SPIRIT_NO_ACTIONS_HPP)