]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Copyright (c) 2001-2011 Hartmut Kaiser | |
3 | Copyright (c) 2001-2011 Joel de Guzman | |
4 | ||
5 | Distributed under the Boost Software License, Version 1.0. (See accompanying | |
6 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
7 | ==============================================================================*/ | |
8 | #if !defined(BOOST_SPIRIT_EOL_APRIL_18_2008_0751PM) | |
9 | #define BOOST_SPIRIT_EOL_APRIL_18_2008_0751PM | |
10 | ||
11 | #if defined(_MSC_VER) | |
12 | #pragma once | |
13 | #endif | |
14 | ||
15 | #include <boost/mpl/bool.hpp> | |
16 | #include <boost/spirit/home/qi/domain.hpp> | |
17 | #include <boost/spirit/home/qi/parser.hpp> | |
18 | #include <boost/spirit/home/qi/meta_compiler.hpp> | |
19 | #include <boost/spirit/home/qi/skip_over.hpp> | |
20 | #include <boost/spirit/home/support/common_terminals.hpp> | |
21 | ||
22 | namespace boost { namespace spirit | |
23 | { | |
24 | /////////////////////////////////////////////////////////////////////////// | |
25 | // Enablers | |
26 | /////////////////////////////////////////////////////////////////////////// | |
27 | template <> | |
28 | struct use_terminal<qi::domain, tag::eol> // enables eol | |
29 | : mpl::true_ {}; | |
30 | }} | |
31 | ||
32 | namespace boost { namespace spirit { namespace qi | |
33 | { | |
34 | #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS | |
35 | using spirit::eol; | |
36 | #endif | |
37 | using spirit::eol_type; | |
38 | ||
39 | struct eol_parser : primitive_parser<eol_parser> | |
40 | { | |
41 | template <typename Context, typename Iterator> | |
42 | struct attribute | |
43 | { | |
44 | typedef unused_type type; | |
45 | }; | |
46 | ||
47 | template <typename Iterator, typename Context | |
48 | , typename Skipper, typename Attribute> | |
49 | bool parse(Iterator& first, Iterator const& last | |
50 | , Context& /*context*/, Skipper const& skipper | |
51 | , Attribute& /*attr*/) const | |
52 | { | |
53 | qi::skip_over(first, last, skipper); | |
54 | ||
55 | Iterator it = first; | |
56 | bool matched = false; | |
57 | if (it != last && *it == '\r') // CR | |
58 | { | |
59 | matched = true; | |
60 | ++it; | |
61 | } | |
62 | if (it != last && *it == '\n') // LF | |
63 | { | |
64 | matched = true; | |
65 | ++it; | |
66 | } | |
67 | ||
68 | if (!matched) | |
69 | return false; | |
70 | ||
71 | first = it; | |
72 | return true; | |
73 | } | |
74 | ||
75 | template <typename Context> | |
76 | info what(Context& /*context*/) const | |
77 | { | |
78 | return info("eol"); | |
79 | } | |
80 | }; | |
81 | ||
82 | /////////////////////////////////////////////////////////////////////////// | |
83 | // Parser generators: make_xxx function (objects) | |
84 | /////////////////////////////////////////////////////////////////////////// | |
85 | template <typename Modifiers> | |
86 | struct make_primitive<tag::eol, Modifiers> | |
87 | { | |
88 | typedef eol_parser result_type; | |
89 | result_type operator()(unused_type, unused_type) const | |
90 | { | |
91 | return result_type(); | |
92 | } | |
93 | }; | |
94 | }}} | |
95 | ||
96 | #endif | |
97 | ||
98 |