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/concept_check.hpp>
20 namespace boost { namespace spirit { namespace qi
22 ///////////////////////////////////////////////////////////////////////////
23 template <typename Iterator, typename Expr>
30 // Make sure the iterator is at least a forward_iterator. If you got a
31 // compilation error here, then you are using an input_iterator while
32 // calling this function, you need to supply at least a
33 // forward_iterator instead.
34 BOOST_CONCEPT_ASSERT((ForwardIterator<Iterator>));
36 return detail::parse_impl<Expr>::call(first, last, expr);
39 template <typename Iterator, typename Expr>
42 Iterator const& first_
46 Iterator first = first_;
47 return qi::parse(first, last, expr);
50 ///////////////////////////////////////////////////////////////////////////
56 typedef context<fusion::cons<T&>, locals<> > type;
60 struct make_context<unused_type>
62 typedef unused_type type;
66 template <typename Iterator, typename Expr, typename Attr>
74 // Make sure the iterator is at least a forward_iterator. If you got a
75 // compilation error here, then you are using an input_iterator while
76 // calling this function, you need to supply at least a
77 // forward_iterator instead.
78 BOOST_CONCEPT_ASSERT((ForwardIterator<Iterator>));
80 // Report invalid expression error as early as possible.
81 // If you got an error_invalid_expression error message here,
82 // then the expression (expr) is not a valid spirit qi expression.
83 BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr);
85 typename detail::make_context<Attr>::type context(attr);
86 return compile<qi::domain>(expr).parse(first, last, context, unused, attr);
89 template <typename Iterator, typename Expr, typename Attr>
92 Iterator const& first_
97 Iterator first = first_;
98 return qi::parse(first, last, expr, attr);
101 ///////////////////////////////////////////////////////////////////////////
102 template <typename Iterator, typename Expr, typename Skipper>
108 , Skipper const& skipper
109 , BOOST_SCOPED_ENUM(skip_flag) post_skip = skip_flag::postskip)
111 // Make sure the iterator is at least a forward_iterator. If you got a
112 // compilation error here, then you are using an input_iterator while
113 // calling this function, you need to supply at least a
114 // forward_iterator instead.
115 BOOST_CONCEPT_ASSERT((ForwardIterator<Iterator>));
117 return detail::phrase_parse_impl<Expr>::call(
118 first, last, expr, skipper, post_skip);
121 template <typename Iterator, typename Expr, typename Skipper>
124 Iterator const& first_
127 , Skipper const& skipper
128 , BOOST_SCOPED_ENUM(skip_flag) post_skip = skip_flag::postskip)
130 Iterator first = first_;
131 return qi::phrase_parse(first, last, expr, skipper, post_skip);
134 ///////////////////////////////////////////////////////////////////////////
135 template <typename Iterator, typename Expr, typename Skipper, typename Attr>
141 , Skipper const& skipper
142 , BOOST_SCOPED_ENUM(skip_flag) post_skip
145 // Make sure the iterator is at least a forward_iterator. If you got a
146 // compilation error here, then you are using an input_iterator while
147 // calling this function, you need to supply at least a
148 // forward_iterator instead.
149 BOOST_CONCEPT_ASSERT((ForwardIterator<Iterator>));
151 // Report invalid expression error as early as possible.
152 // If you got an error_invalid_expression error message here,
153 // then either the expression (expr) or skipper is not a valid
154 // spirit qi expression.
155 BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr);
156 BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Skipper);
159 typename result_of::compile<qi::domain, Skipper>::type
161 skipper_type const skipper_ = compile<qi::domain>(skipper);
163 typename detail::make_context<Attr>::type context(attr);
164 if (!compile<qi::domain>(expr).parse(
165 first, last, context, skipper_, attr))
168 if (post_skip == skip_flag::postskip)
169 qi::skip_over(first, last, skipper_);
173 template <typename Iterator, typename Expr, typename Skipper, typename Attr>
176 Iterator const& first_
179 , Skipper const& skipper
180 , BOOST_SCOPED_ENUM(skip_flag) post_skip
183 Iterator first = first_;
184 return qi::phrase_parse(first, last, expr, skipper, post_skip, attr);
187 ///////////////////////////////////////////////////////////////////////////
188 template <typename Iterator, typename Expr, typename Skipper, typename Attr>
194 , Skipper const& skipper
197 return qi::phrase_parse(first, last, expr, skipper, skip_flag::postskip, attr);
200 template <typename Iterator, typename Expr, typename Skipper, typename Attr>
203 Iterator const& first_
206 , Skipper const& skipper
209 Iterator first = first_;
210 return qi::phrase_parse(first, last, expr, skipper, skip_flag::postskip, attr);