PageRenderTime 43ms CodeModel.GetById 12ms app.highlight 26ms RepoModel.GetById 1ms app.codeStats 1ms

/Src/Dependencies/Boost/boost/spirit/home/qi/parse.hpp

http://hadesmem.googlecode.com/
C++ Header | 215 lines | 156 code | 24 blank | 35 comment | 3 complexity | 67c126f4465079bf25d71147727aeead MD5 | raw file
  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/concept_check.hpp>
 19
 20namespace 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 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>));
 35
 36        return detail::parse_impl<Expr>::call(first, last, expr);
 37    }
 38
 39    template <typename Iterator, typename Expr>
 40    inline bool
 41    parse(
 42        Iterator const& first_
 43      , Iterator last
 44      , Expr const& expr)
 45    {
 46        Iterator first = first_;
 47        return qi::parse(first, last, expr);
 48    }
 49
 50    ///////////////////////////////////////////////////////////////////////////
 51    namespace detail
 52    {
 53        template <typename T>
 54        struct make_context
 55        {
 56            typedef context<fusion::cons<T&>, locals<> > type;
 57        };
 58
 59        template <>
 60        struct make_context<unused_type>
 61        {
 62            typedef unused_type type;
 63        };
 64    }
 65
 66    template <typename Iterator, typename Expr, typename Attr>
 67    inline bool
 68    parse(
 69        Iterator& first
 70      , Iterator last
 71      , Expr const& expr
 72      , Attr& attr)
 73    {
 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>));
 79
 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);
 84
 85        typename detail::make_context<Attr>::type context(attr);
 86        return compile<qi::domain>(expr).parse(first, last, context, unused, attr);
 87    }
 88
 89    template <typename Iterator, typename Expr, typename Attr>
 90    inline bool
 91    parse(
 92        Iterator const& first_
 93      , Iterator last
 94      , Expr const& expr
 95      , Attr& attr)
 96    {
 97        Iterator first = first_;
 98        return qi::parse(first, last, expr, attr);
 99    }
100
101    ///////////////////////////////////////////////////////////////////////////
102    template <typename Iterator, typename Expr, typename Skipper>
103    inline bool
104    phrase_parse(
105        Iterator& first
106      , Iterator last
107      , Expr const& expr
108      , Skipper const& skipper
109      , BOOST_SCOPED_ENUM(skip_flag) post_skip = skip_flag::postskip)
110    {
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>));
116
117        return detail::phrase_parse_impl<Expr>::call(
118            first, last, expr, skipper, post_skip);
119    }
120
121    template <typename Iterator, typename Expr, typename Skipper>
122    inline bool
123    phrase_parse(
124        Iterator const& first_
125      , Iterator last
126      , Expr const& expr
127      , Skipper const& skipper
128      , BOOST_SCOPED_ENUM(skip_flag) post_skip = skip_flag::postskip)
129    {
130        Iterator first = first_;
131        return qi::phrase_parse(first, last, expr, skipper, post_skip);
132    }
133
134    ///////////////////////////////////////////////////////////////////////////
135    template <typename Iterator, typename Expr, typename Skipper, typename Attr>
136    inline bool
137    phrase_parse(
138        Iterator& first
139      , Iterator last
140      , Expr const& expr
141      , Skipper const& skipper
142      , BOOST_SCOPED_ENUM(skip_flag) post_skip
143      , Attr& attr)
144    {
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>));
150
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);
157
158        typedef
159            typename result_of::compile<qi::domain, Skipper>::type
160        skipper_type;
161        skipper_type const skipper_ = compile<qi::domain>(skipper);
162
163        typename detail::make_context<Attr>::type context(attr);
164        if (!compile<qi::domain>(expr).parse(
165                first, last, context, skipper_, attr))
166            return false;
167
168        if (post_skip == skip_flag::postskip)
169            qi::skip_over(first, last, skipper_);
170        return true;
171    }
172
173    template <typename Iterator, typename Expr, typename Skipper, typename Attr>
174    inline bool
175    phrase_parse(
176        Iterator const& first_
177      , Iterator last
178      , Expr const& expr
179      , Skipper const& skipper
180      , BOOST_SCOPED_ENUM(skip_flag) post_skip
181      , Attr& attr)
182    {
183        Iterator first = first_;
184        return qi::phrase_parse(first, last, expr, skipper, post_skip, attr);
185    }
186
187    ///////////////////////////////////////////////////////////////////////////
188    template <typename Iterator, typename Expr, typename Skipper, typename Attr>
189    inline bool
190    phrase_parse(
191        Iterator& first
192      , Iterator last
193      , Expr const& expr
194      , Skipper const& skipper
195      , Attr& attr)
196    {
197        return qi::phrase_parse(first, last, expr, skipper, skip_flag::postskip, attr);
198    }
199
200    template <typename Iterator, typename Expr, typename Skipper, typename Attr>
201    inline bool
202    phrase_parse(
203        Iterator const& first_
204      , Iterator last
205      , Expr const& expr
206      , Skipper const& skipper
207      , Attr& attr)
208    {
209        Iterator first = first_;
210        return qi::phrase_parse(first, last, expr, skipper, skip_flag::postskip, attr);
211    }
212}}}
213
214#endif
215