1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
3 Copyright (c) 2001-2011 Hartmut Kaiser
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
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>
20 namespace boost { namespace spirit { namespace qi
22 ///////////////////////////////////////////////////////////////////////////
23 template <typename Iterator, typename Expr>
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
34 BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIteratorConcept<Iterator>));
35 BOOST_CONCEPT_ASSERT((boost_concepts::ForwardTraversalConcept<Iterator>));
37 return detail::parse_impl<Expr>::call(first, last, expr);
40 template <typename Iterator, typename Expr>
43 Iterator const& first_
47 Iterator first = first_;
48 return qi::parse(first, last, expr);
51 ///////////////////////////////////////////////////////////////////////////
57 typedef context<fusion::cons<T&>, locals<> > type;
61 struct make_context<unused_type>
63 typedef unused_type type;
67 template <typename Iterator, typename Expr, typename Attr>
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
79 BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIteratorConcept<Iterator>));
80 BOOST_CONCEPT_ASSERT((boost_concepts::ForwardTraversalConcept<Iterator>));
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);
87 typename detail::make_context<Attr>::type context(attr);
88 return compile<qi::domain>(expr).parse(first, last, context, unused, attr);
91 template <typename Iterator, typename Expr, typename Attr>
94 Iterator const& first_
99 Iterator first = first_;
100 return qi::parse(first, last, expr, attr);
103 ///////////////////////////////////////////////////////////////////////////
104 template <typename Iterator, typename Expr, typename Skipper>
110 , Skipper const& skipper
111 , BOOST_SCOPED_ENUM(skip_flag) post_skip = skip_flag::postskip)
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
117 BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIteratorConcept<Iterator>));
118 BOOST_CONCEPT_ASSERT((boost_concepts::ForwardTraversalConcept<Iterator>));
120 return detail::phrase_parse_impl<Expr>::call(
121 first, last, expr, skipper, post_skip);
124 template <typename Iterator, typename Expr, typename Skipper>
127 Iterator const& first_
130 , Skipper const& skipper
131 , BOOST_SCOPED_ENUM(skip_flag) post_skip = skip_flag::postskip)
133 Iterator first = first_;
134 return qi::phrase_parse(first, last, expr, skipper, post_skip);
137 ///////////////////////////////////////////////////////////////////////////
138 template <typename Iterator, typename Expr, typename Skipper, typename Attr>
144 , Skipper const& skipper
145 , BOOST_SCOPED_ENUM(skip_flag) post_skip
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
152 BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIteratorConcept<Iterator>));
153 BOOST_CONCEPT_ASSERT((boost_concepts::ForwardTraversalConcept<Iterator>));
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);
163 typename result_of::compile<qi::domain, Skipper>::type
165 skipper_type const skipper_ = compile<qi::domain>(skipper);
167 typename detail::make_context<Attr>::type context(attr);
168 if (!compile<qi::domain>(expr).parse(
169 first, last, context, skipper_, attr))
172 if (post_skip == skip_flag::postskip)
173 qi::skip_over(first, last, skipper_);
177 template <typename Iterator, typename Expr, typename Skipper, typename Attr>
180 Iterator const& first_
183 , Skipper const& skipper
184 , BOOST_SCOPED_ENUM(skip_flag) post_skip
187 Iterator first = first_;
188 return qi::phrase_parse(first, last, expr, skipper, post_skip, attr);
191 ///////////////////////////////////////////////////////////////////////////
192 template <typename Iterator, typename Expr, typename Skipper, typename Attr>
198 , Skipper const& skipper
201 return qi::phrase_parse(first, last, expr, skipper, skip_flag::postskip, attr);
204 template <typename Iterator, typename Expr, typename Skipper, typename Attr>
207 Iterator const& first_
210 , Skipper const& skipper
213 Iterator first = first_;
214 return qi::phrase_parse(first, last, expr, skipper, skip_flag::postskip, attr);