1 #ifndef BOOST_METAPARSE_V1_ONE_CHAR_HPP
2 #define BOOST_METAPARSE_V1_ONE_CHAR_HPP
3 
4 // Copyright Abel Sinkovics (abel@sinkovics.hu)  2009 - 2011.
5 // Distributed under the Boost Software License, Version 1.0.
6 //    (See accompanying file LICENSE_1_0.txt or copy at
7 //          http://www.boost.org/LICENSE_1_0.txt)
8 
9 #include <boost/metaparse/v1/error/unexpected_end_of_input.hpp>
10 #include <boost/metaparse/v1/next_char.hpp>
11 #include <boost/metaparse/v1/next_line.hpp>
12 #include <boost/metaparse/v1/accept.hpp>
13 #include <boost/metaparse/v1/reject.hpp>
14 #include <boost/metaparse/v1/get_prev_char.hpp>
15 
16 #include <boost/mpl/empty.hpp>
17 #include <boost/mpl/eval_if.hpp>
18 #include <boost/mpl/front.hpp>
19 #include <boost/mpl/pop_front.hpp>
20 #include <boost/mpl/bool.hpp>
21 
22 namespace boost
23 {
24   namespace metaparse
25   {
26     namespace v1
27     {
28       struct one_char
29       {
30       private:
31         template <class C, class Pos>
32         struct next_pos :
33           boost::mpl::eval_if<
34             boost::mpl::bool_<
35               C::type::value == '\r'
36               || (
37                 C::type::value == '\n'
38                 && get_prev_char<Pos>::type::value != '\r'
39               )
40             >,
41             next_line<Pos, C>,
42             next_char<Pos, C>
43           >
44         {};
45 
46         template <class S, class NextPos>
47         struct unchecked :
48           accept<
49             typename boost::mpl::front<S>::type,
50             boost::mpl::pop_front<S>,
51             NextPos
52           >
53         {};
54       public:
55         typedef one_char type;
56 
57         template <class S, class Pos>
58         struct apply :
59           boost::mpl::eval_if<
60             typename boost::mpl::empty<S>::type,
61             reject<error::unexpected_end_of_input, Pos>,
62             unchecked<S, next_pos<boost::mpl::front<S>, Pos> >
63           >
64         {};
65       };
66     }
67   }
68 }
69 
70 #endif
71 
72