keyword.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef BOOST_METAPARSE_V1_KEYWORD_HPP
  2. #define BOOST_METAPARSE_V1_KEYWORD_HPP
  3. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2009 - 2010.
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #include <boost/metaparse/v1/impl/void_.hpp>
  8. #include <boost/metaparse/v1/lit.hpp>
  9. #include <boost/metaparse/v1/return_.hpp>
  10. #include <boost/metaparse/v1/is_error.hpp>
  11. #include <boost/metaparse/v1/get_remaining.hpp>
  12. #include <boost/metaparse/v1/get_position.hpp>
  13. #include <boost/mpl/if.hpp>
  14. #include <boost/mpl/eval_if.hpp>
  15. #include <boost/mpl/empty.hpp>
  16. #include <boost/mpl/pop_front.hpp>
  17. #include <boost/mpl/front.hpp>
  18. namespace boost
  19. {
  20. namespace metaparse
  21. {
  22. namespace v1
  23. {
  24. // Does not consume/check anything after the keyword
  25. template <class Kw, class ResultType = impl::void_>
  26. struct keyword
  27. {
  28. private:
  29. struct nonempty
  30. {
  31. private:
  32. typedef lit<typename boost::mpl::front<Kw>::type> next_char_parser;
  33. typedef
  34. keyword<typename boost::mpl::pop_front<Kw>::type, ResultType>
  35. rest_parser;
  36. template <class S, class Pos>
  37. struct apply_unchecked :
  38. rest_parser::template apply<
  39. typename get_remaining<
  40. typename next_char_parser::template apply<S, Pos>
  41. >::type,
  42. typename get_position<
  43. typename next_char_parser::template apply<S, Pos>
  44. >::type
  45. >
  46. {};
  47. public:
  48. template <class S, class Pos>
  49. struct apply :
  50. boost::mpl::eval_if<
  51. typename is_error<
  52. typename next_char_parser::template apply<S, Pos>
  53. >::type,
  54. typename next_char_parser::template apply<S, Pos>,
  55. apply_unchecked<S, Pos>
  56. >
  57. {};
  58. };
  59. public:
  60. typedef keyword type;
  61. template <class S, class Pos>
  62. struct apply :
  63. boost::mpl::if_<
  64. boost::mpl::empty<Kw>,
  65. return_<ResultType>,
  66. nonempty
  67. >::type::template apply<S, Pos>
  68. {};
  69. };
  70. }
  71. }
  72. }
  73. #endif