| 1 | /*============================================================================= |
| 2 | Copyright (c) 2001-2011 Joel de Guzman |
| 3 | Copyright (c) 2001-2011 Hartmut Kaiser |
| 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_PARSE_APRIL_16_2006_0442PM) |
| 9 | #define BOOST_SPIRIT_PARSE_APRIL_16_2006_0442PM |
| 10 | |
| 11 | #if defined(_MSC_VER) |
| 12 | #pragma once |
| 13 | #endif |
| 14 | |
| 15 | #include <boost/spirit/home/support/context.hpp> |
| 16 | #include <boost/spirit/home/support/nonterminal/locals.hpp> |
| 17 | #include <boost/spirit/home/qi/detail/parse.hpp> |
| 18 | #include <boost/iterator/iterator_concepts.hpp> |
| 19 | |
| 20 | namespace boost { namespace spirit { namespace qi |
| 21 | { |
| 22 | /////////////////////////////////////////////////////////////////////////// |
| 23 | template <typename Iterator, typename Expr> |
| 24 | inline bool |
| 25 | parse( |
| 26 | Iterator& first |
| 27 | , Iterator last |
| 28 | , Expr const& expr) |
| 29 | { |
| 30 | // Make sure the iterator is at least a readable forward traversal iterator. |
| 31 | // If you got a compilation error here, then you are using a weaker iterator |
| 32 | // while calling this function, you need to supply a readable forward traversal |
| 33 | // iterator instead. |
| 34 | BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIteratorConcept<Iterator>)); |
| 35 | BOOST_CONCEPT_ASSERT((boost_concepts::ForwardTraversalConcept<Iterator>)); |
| 36 | |
| 37 | return detail::parse_impl<Expr>::call(first, last, expr); |
| 38 | } |
| 39 | |
| 40 | template <typename Iterator, typename Expr> |
| 41 | inline bool |
| 42 | parse( |
| 43 | Iterator const& first_ |
| 44 | , Iterator last |
| 45 | , Expr const& expr) |
| 46 | { |
| 47 | Iterator first = first_; |
| 48 | return qi::parse(first, last, expr); |
| 49 | } |
| 50 | |
| 51 | /////////////////////////////////////////////////////////////////////////// |
| 52 | namespace detail |
| 53 | { |
| 54 | template <typename T> |
| 55 | struct make_context |
| 56 | { |
| 57 | typedef context<fusion::cons<T&>, locals<> > type; |
| 58 | }; |
| 59 | |
| 60 | template <> |
| 61 | struct make_context<unused_type> |
| 62 | { |
| 63 | typedef unused_type type; |
| 64 | }; |
| 65 | } |
| 66 | |
| 67 | template <typename Iterator, typename Expr, typename Attr> |
| 68 | inline bool |
| 69 | parse( |
| 70 | Iterator& first |
| 71 | , Iterator last |
| 72 | , Expr const& expr |
| 73 | , Attr& attr) |
| 74 | { |
| 75 | // Make sure the iterator is at least a readable forward traversal iterator. |
| 76 | // If you got a compilation error here, then you are using a weaker iterator |
| 77 | // while calling this function, you need to supply a readable forward traversal |
| 78 | // iterator instead. |
| 79 | BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIteratorConcept<Iterator>)); |
| 80 | BOOST_CONCEPT_ASSERT((boost_concepts::ForwardTraversalConcept<Iterator>)); |
| 81 | |
| 82 | // Report invalid expression error as early as possible. |
| 83 | // If you got an error_invalid_expression error message here, |
| 84 | // then the expression (expr) is not a valid spirit qi expression. |
| 85 | BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr); |
| 86 | |
| 87 | typename detail::make_context<Attr>::type context(attr); |
| 88 | return compile<qi::domain>(expr).parse(first, last, context, unused, attr); |
| 89 | } |
| 90 | |
| 91 | template <typename Iterator, typename Expr, typename Attr> |
| 92 | inline bool |
| 93 | parse( |
| 94 | Iterator const& first_ |
| 95 | , Iterator last |
| 96 | , Expr const& expr |
| 97 | , Attr& attr) |
| 98 | { |
| 99 | Iterator first = first_; |
| 100 | return qi::parse(first, last, expr, attr); |
| 101 | } |
| 102 | |
| 103 | /////////////////////////////////////////////////////////////////////////// |
| 104 | template <typename Iterator, typename Expr, typename Skipper> |
| 105 | inline bool |
| 106 | phrase_parse( |
| 107 | Iterator& first |
| 108 | , Iterator last |
| 109 | , Expr const& expr |
| 110 | , Skipper const& skipper |
| 111 | , BOOST_SCOPED_ENUM(skip_flag) post_skip = skip_flag::postskip) |
| 112 | { |
| 113 | // Make sure the iterator is at least a readable forward traversal iterator. |
| 114 | // If you got a compilation error here, then you are using a weaker iterator |
| 115 | // while calling this function, you need to supply a readable forward traversal |
| 116 | // iterator instead. |
| 117 | BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIteratorConcept<Iterator>)); |
| 118 | BOOST_CONCEPT_ASSERT((boost_concepts::ForwardTraversalConcept<Iterator>)); |
| 119 | |
| 120 | return detail::phrase_parse_impl<Expr>::call( |
| 121 | first, last, expr, skipper, post_skip); |
| 122 | } |
| 123 | |
| 124 | template <typename Iterator, typename Expr, typename Skipper> |
| 125 | inline bool |
| 126 | phrase_parse( |
| 127 | Iterator const& first_ |
| 128 | , Iterator last |
| 129 | , Expr const& expr |
| 130 | , Skipper const& skipper |
| 131 | , BOOST_SCOPED_ENUM(skip_flag) post_skip = skip_flag::postskip) |
| 132 | { |
| 133 | Iterator first = first_; |
| 134 | return qi::phrase_parse(first, last, expr, skipper, post_skip); |
| 135 | } |
| 136 | |
| 137 | /////////////////////////////////////////////////////////////////////////// |
| 138 | template <typename Iterator, typename Expr, typename Skipper, typename Attr> |
| 139 | inline bool |
| 140 | phrase_parse( |
| 141 | Iterator& first |
| 142 | , Iterator last |
| 143 | , Expr const& expr |
| 144 | , Skipper const& skipper |
| 145 | , BOOST_SCOPED_ENUM(skip_flag) post_skip |
| 146 | , Attr& attr) |
| 147 | { |
| 148 | // Make sure the iterator is at least a readable forward traversal iterator. |
| 149 | // If you got a compilation error here, then you are using a weaker iterator |
| 150 | // while calling this function, you need to supply a readable forward traversal |
| 151 | // iterator instead. |
| 152 | BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIteratorConcept<Iterator>)); |
| 153 | BOOST_CONCEPT_ASSERT((boost_concepts::ForwardTraversalConcept<Iterator>)); |
| 154 | |
| 155 | // Report invalid expression error as early as possible. |
| 156 | // If you got an error_invalid_expression error message here, |
| 157 | // then either the expression (expr) or skipper is not a valid |
| 158 | // spirit qi expression. |
| 159 | BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr); |
| 160 | BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Skipper); |
| 161 | |
| 162 | typedef |
| 163 | typename result_of::compile<qi::domain, Skipper>::type |
| 164 | skipper_type; |
| 165 | skipper_type const skipper_ = compile<qi::domain>(skipper); |
| 166 | |
| 167 | typename detail::make_context<Attr>::type context(attr); |
| 168 | if (!compile<qi::domain>(expr).parse( |
| 169 | first, last, context, skipper_, attr)) |
| 170 | return false; |
| 171 | |
| 172 | if (post_skip == skip_flag::postskip) |
| 173 | qi::skip_over(first, last, skipper_); |
| 174 | return true; |
| 175 | } |
| 176 | |
| 177 | template <typename Iterator, typename Expr, typename Skipper, typename Attr> |
| 178 | inline bool |
| 179 | phrase_parse( |
| 180 | Iterator const& first_ |
| 181 | , Iterator last |
| 182 | , Expr const& expr |
| 183 | , Skipper const& skipper |
| 184 | , BOOST_SCOPED_ENUM(skip_flag) post_skip |
| 185 | , Attr& attr) |
| 186 | { |
| 187 | Iterator first = first_; |
| 188 | return qi::phrase_parse(first, last, expr, skipper, post_skip, attr); |
| 189 | } |
| 190 | |
| 191 | /////////////////////////////////////////////////////////////////////////// |
| 192 | template <typename Iterator, typename Expr, typename Skipper, typename Attr> |
| 193 | inline bool |
| 194 | phrase_parse( |
| 195 | Iterator& first |
| 196 | , Iterator last |
| 197 | , Expr const& expr |
| 198 | , Skipper const& skipper |
| 199 | , Attr& attr) |
| 200 | { |
| 201 | return qi::phrase_parse(first, last, expr, skipper, skip_flag::postskip, attr); |
| 202 | } |
| 203 | |
| 204 | template <typename Iterator, typename Expr, typename Skipper, typename Attr> |
| 205 | inline bool |
| 206 | phrase_parse( |
| 207 | Iterator const& first_ |
| 208 | , Iterator last |
| 209 | , Expr const& expr |
| 210 | , Skipper const& skipper |
| 211 | , Attr& attr) |
| 212 | { |
| 213 | Iterator first = first_; |
| 214 | return qi::phrase_parse(first, last, expr, skipper, skip_flag::postskip, attr); |
| 215 | } |
| 216 | }}} |
| 217 | |
| 218 | #endif |
| 219 | |
| 220 | |