1 /*=============================================================================
2 Copyright (c) 2002-2003 Joel de Guzman
3 Copyright (c) 2002-2003 Juan Carlos Arevalo-Baeza
4 http://spirit.sourceforge.net/
6 Distributed under the Boost Software License, Version 1.0. (See accompanying
7 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
9 #ifndef BOOST_SPIRIT_FUNCTOR_PARSER_HPP
10 #define BOOST_SPIRIT_FUNCTOR_PARSER_HPP
12 ///////////////////////////////////////////////////////////////////////////////
13 #include <boost/spirit/home/classic/namespace.hpp>
14 #include <boost/spirit/home/classic/core/parser.hpp>
16 ///////////////////////////////////////////////////////////////////////////////
17 namespace boost { namespace spirit {
19 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
21 ///////////////////////////////////////////////////////////////////////////
23 // functor_parser class
25 // Once a functor parser has been defined, you can build a real
26 // parser from it by passing it to this class as the template
29 ///////////////////////////////////////////////////////////////////////////
30 template < class FunctorT >
31 struct functor_parser : public parser<functor_parser<FunctorT> >
35 functor_parser(): functor() {}
36 functor_parser(FunctorT const& functor_): functor(functor_) {}
38 typedef typename FunctorT::result_t functor_result_t;
39 typedef functor_parser<FunctorT> self_t;
41 template <typename ScannerT>
44 typedef typename match_result<ScannerT, functor_result_t>::type
48 template <typename ScannerT>
49 typename parser_result<self_t, ScannerT>::type
50 parse(ScannerT const& scan) const
52 typedef typename ScannerT::iterator_t iterator_t;
54 iterator_t const s(scan.first);
55 functor_result_t functor_result;
56 std::ptrdiff_t len = functor(scan, functor_result);
59 return scan.no_match();
61 return scan.create_match(std::size_t(len), functor_result, s, scan.first);
65 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
67 }} // namespace BOOST_SPIRIT_CLASSIC_NS