one_char.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #ifndef BOOST_METAPARSE_V1_ONE_CHAR_HPP
  2. #define BOOST_METAPARSE_V1_ONE_CHAR_HPP
  3. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2009 - 2011.
  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/error/unexpected_end_of_input.hpp>
  8. #include <boost/metaparse/v1/next_char.hpp>
  9. #include <boost/metaparse/v1/next_line.hpp>
  10. #include <boost/metaparse/v1/accept.hpp>
  11. #include <boost/metaparse/v1/reject.hpp>
  12. #include <boost/metaparse/v1/get_prev_char.hpp>
  13. #include <boost/mpl/empty.hpp>
  14. #include <boost/mpl/eval_if.hpp>
  15. #include <boost/mpl/front.hpp>
  16. #include <boost/mpl/pop_front.hpp>
  17. #include <boost/mpl/bool.hpp>
  18. namespace boost
  19. {
  20. namespace metaparse
  21. {
  22. namespace v1
  23. {
  24. struct one_char
  25. {
  26. private:
  27. template <class C, class Pos>
  28. struct next_pos :
  29. boost::mpl::eval_if<
  30. boost::mpl::bool_<
  31. C::type::value == '\r'
  32. || (
  33. C::type::value == '\n'
  34. && get_prev_char<Pos>::type::value != '\r'
  35. )
  36. >,
  37. next_line<Pos, C>,
  38. next_char<Pos, C>
  39. >
  40. {};
  41. template <class S, class NextPos>
  42. struct unchecked :
  43. accept<
  44. typename boost::mpl::front<S>::type,
  45. boost::mpl::pop_front<S>,
  46. NextPos
  47. >
  48. {};
  49. public:
  50. typedef one_char type;
  51. template <class S, class Pos>
  52. struct apply :
  53. boost::mpl::eval_if<
  54. typename boost::mpl::empty<S>::type,
  55. reject<error::unexpected_end_of_input, Pos>,
  56. unchecked<S, next_pos<boost::mpl::front<S>, Pos> >
  57. >
  58. {};
  59. };
  60. }
  61. }
  62. }
  63. #endif