build_parser.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef BOOST_METAPARSE_V1_BUILD_PARSER_HPP
  2. #define BOOST_METAPARSE_V1_BUILD_PARSER_HPP
  3. // Copyright Abel Sinkovics ([email protected]) 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/fwd/build_parser.hpp>
  8. #include <boost/metaparse/v1/start.hpp>
  9. #include <boost/metaparse/v1/get_result.hpp>
  10. #include <boost/metaparse/v1/get_position.hpp>
  11. #include <boost/metaparse/v1/get_message.hpp>
  12. #include <boost/metaparse/v1/get_line.hpp>
  13. #include <boost/metaparse/v1/get_col.hpp>
  14. #include <boost/metaparse/v1/is_error.hpp>
  15. #include <boost/mpl/eval_if.hpp>
  16. #include <boost/static_assert.hpp>
  17. namespace boost
  18. {
  19. namespace metaparse
  20. {
  21. namespace v1
  22. {
  23. template <int Line, int Col, class Msg>
  24. struct x__________________PARSING_FAILED__________________x
  25. {
  26. BOOST_STATIC_ASSERT(Line == Line + 1);
  27. };
  28. template <class P, class S>
  29. struct parsing_failed :
  30. x__________________PARSING_FAILED__________________x<
  31. get_line<
  32. get_position<typename P::template apply<S, start> >
  33. >::type::value,
  34. get_col<
  35. get_position<typename P::template apply<S, start> >
  36. >::type::value,
  37. typename get_message<typename P::template apply<S, start> >::type
  38. >
  39. {};
  40. template <class P>
  41. struct build_parser
  42. {
  43. typedef build_parser type;
  44. template <class S>
  45. struct apply :
  46. boost::mpl::eval_if<
  47. typename is_error<typename P::template apply<S, start> >::type,
  48. parsing_failed<P, S>,
  49. get_result<typename P::template apply<S, start> >
  50. >
  51. {};
  52. };
  53. }
  54. }
  55. }
  56. #endif