fail_at_first_char_expected.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef BOOST_METAPARSE_V1_FAIL_AT_FIRST_CHAR_EXPECTED_HPP
  2. #define BOOST_METAPARSE_V1_FAIL_AT_FIRST_CHAR_EXPECTED_HPP
  3. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2015.
  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/accept.hpp>
  9. #include <boost/metaparse/v1/reject.hpp>
  10. #include <boost/metaparse/v1/is_error.hpp>
  11. #include <boost/metaparse/v1/get_position.hpp>
  12. #include <boost/metaparse/v1/error/expected_to_fail.hpp>
  13. #include <boost/mpl/eval_if.hpp>
  14. #include <boost/mpl/equal_to.hpp>
  15. namespace boost
  16. {
  17. namespace metaparse
  18. {
  19. namespace v1
  20. {
  21. template <class P>
  22. struct fail_at_first_char_expected
  23. {
  24. private:
  25. template <class S, class Pos>
  26. struct apply_err :
  27. boost::mpl::eval_if<
  28. typename boost::mpl::equal_to<
  29. Pos,
  30. typename get_position<typename P::template apply<S, Pos> >::type
  31. >::type,
  32. accept<impl::void_, S, Pos>,
  33. typename P::template apply<S, Pos>
  34. >
  35. {};
  36. public:
  37. typedef fail_at_first_char_expected type;
  38. template <class S, class Pos>
  39. struct apply :
  40. boost::mpl::eval_if<
  41. typename is_error<typename P::template apply<S, Pos> >::type,
  42. apply_err<S, Pos>,
  43. reject<error::expected_to_fail, Pos>
  44. >
  45. {};
  46. };
  47. }
  48. }
  49. }
  50. #endif