]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Copyright (c) 2001-2013 Joel de Guzman | |
3 | ||
4 | Distributed under the Boost Software License, Version 1.0. (See accompanying | |
5 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | =============================================================================*/ | |
7 | #if !defined(BOOST_SPIRIT_TEST_FEBRUARY_01_2007_0605PM) | |
8 | #define BOOST_SPIRIT_TEST_FEBRUARY_01_2007_0605PM | |
9 | ||
10 | #include <boost/spirit/home/x3/core/parse.hpp> | |
92f5a8d4 | 11 | #include <boost/utility/string_view.hpp> |
7c673cae FG |
12 | #include <iostream> |
13 | ||
14 | namespace spirit_test | |
15 | { | |
16 | template <typename Char, typename Parser> | |
17 | bool test(Char const* in, Parser const& p, bool full_match = true) | |
18 | { | |
19 | Char const* last = in; | |
20 | while (*last) | |
21 | last++; | |
22 | return boost::spirit::x3::parse(in, last, p) | |
23 | && (!full_match || (in == last)); | |
24 | } | |
25 | ||
92f5a8d4 TL |
26 | template <typename Char, typename Parser> |
27 | bool test(boost::basic_string_view<Char, std::char_traits<Char>> in, | |
28 | Parser const& p, bool full_match = true) | |
29 | { | |
30 | auto const last = in.end(); | |
31 | auto pos = in.begin(); | |
32 | ||
33 | return boost::spirit::x3::parse(pos, last, p) && (!full_match || (pos == last)); | |
34 | } | |
35 | ||
7c673cae FG |
36 | template <typename Char, typename Parser, typename Skipper> |
37 | bool test(Char const* in, Parser const& p | |
38 | , Skipper const& s, bool full_match = true) | |
39 | { | |
40 | Char const* last = in; | |
41 | while (*last) | |
42 | last++; | |
43 | return boost::spirit::x3::phrase_parse(in, last, p, s) | |
44 | && (!full_match || (in == last)); | |
45 | } | |
46 | ||
47 | template <typename Char, typename Parser> | |
48 | bool test_failure(Char const* in, Parser const& p) | |
49 | { | |
92f5a8d4 | 50 | Char const * const start = in; |
7c673cae FG |
51 | Char const* last = in; |
52 | while (*last) | |
53 | last++; | |
54 | ||
55 | return !boost::spirit::x3::parse(in, last, p) && (in == start); | |
56 | } | |
57 | ||
92f5a8d4 TL |
58 | template <typename Char, typename Parser> |
59 | bool test_failure(boost::basic_string_view<Char, std::char_traits<Char>> const in, | |
60 | Parser const& p) | |
61 | { | |
62 | auto pos = in.begin(); | |
63 | return !boost::spirit::x3::parse(pos, in.end(), p) && (pos == in.begin()); | |
64 | } | |
65 | ||
7c673cae FG |
66 | template <typename Char, typename Parser, typename Attr> |
67 | bool test_attr(Char const* in, Parser const& p | |
68 | , Attr& attr, bool full_match = true) | |
69 | { | |
70 | Char const* last = in; | |
71 | while (*last) | |
72 | last++; | |
73 | return boost::spirit::x3::parse(in, last, p, attr) | |
74 | && (!full_match || (in == last)); | |
75 | } | |
76 | ||
77 | template <typename Char, typename Parser, typename Attr, typename Skipper> | |
78 | bool test_attr(Char const* in, Parser const& p | |
79 | , Attr& attr, Skipper const& s, bool full_match = true) | |
80 | { | |
81 | Char const* last = in; | |
82 | while (*last) | |
83 | last++; | |
84 | return boost::spirit::x3::phrase_parse(in, last, p, s, attr) | |
85 | && (!full_match || (in == last)); | |
86 | } | |
87 | ||
88 | template <typename Char, typename Parser> | |
89 | bool binary_test(Char const* in, std::size_t size, Parser const& p, | |
90 | bool full_match = true) | |
91 | { | |
92 | Char const* last = in + size; | |
93 | return boost::spirit::x3::parse(in, last, p) | |
94 | && (!full_match || (in == last)); | |
95 | } | |
96 | ||
97 | template <typename Char, typename Parser, typename Skipper> | |
98 | bool binary_test(Char const* in, std::size_t size, Parser const& p, | |
99 | Skipper const& s, bool full_match = true) | |
100 | { | |
101 | Char const* last = in + size; | |
102 | return boost::spirit::x3::phrase_parse(in, last, p, s) | |
103 | && (!full_match || (in == last)); | |
104 | } | |
105 | ||
106 | template <typename Char, typename Parser, typename Attr> | |
107 | bool binary_test_attr(Char const* in, std::size_t size, Parser const& p, | |
108 | Attr& attr, bool full_match = true) | |
109 | { | |
110 | Char const* last = in + size; | |
111 | return boost::spirit::x3::parse(in, last, p, attr) | |
112 | && (!full_match || (in == last)); | |
113 | } | |
114 | ||
115 | template <typename Char, typename Parser, typename Attr, typename Skipper> | |
116 | bool binary_test_attr(Char const* in, std::size_t size, Parser const& p, | |
117 | Attr& attr, Skipper const& s, bool full_match = true) | |
118 | { | |
119 | Char const* last = in + size; | |
120 | return boost::spirit::x3::phrase_parse(in, last, p, s, attr) | |
121 | && (!full_match || (in == last)); | |
122 | } | |
123 | } | |
124 | ||
125 | #endif |