Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/spirit/home/classic/utility/functor_parser.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*=============================================================================
0002     Copyright (c) 2002-2003 Joel de Guzman
0003     Copyright (c) 2002-2003 Juan Carlos Arevalo-Baeza
0004     http://spirit.sourceforge.net/
0005 
0006   Distributed under the Boost Software License, Version 1.0. (See accompanying
0007   file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0008 =============================================================================*/
0009 #ifndef BOOST_SPIRIT_FUNCTOR_PARSER_HPP
0010 #define BOOST_SPIRIT_FUNCTOR_PARSER_HPP
0011 
0012 ///////////////////////////////////////////////////////////////////////////////
0013 #include <boost/spirit/home/classic/namespace.hpp>
0014 #include <boost/spirit/home/classic/core/parser.hpp>
0015 
0016 ///////////////////////////////////////////////////////////////////////////////
0017 namespace boost { namespace spirit {
0018 
0019 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
0020 
0021     ///////////////////////////////////////////////////////////////////////////
0022     //
0023     //  functor_parser class
0024     //
0025     //      Once a functor parser has been defined, you can build a real
0026     //      parser from it by passing it to this class as the template
0027     //      parameter.
0028     //
0029     ///////////////////////////////////////////////////////////////////////////
0030     template < class FunctorT >
0031     struct functor_parser : public parser<functor_parser<FunctorT> >
0032     {
0033         FunctorT functor;
0034 
0035         functor_parser(): functor() {}
0036         functor_parser(FunctorT const& functor_): functor(functor_) {}
0037 
0038         typedef typename FunctorT::result_t functor_result_t;
0039         typedef functor_parser<FunctorT> self_t;
0040 
0041         template <typename ScannerT>
0042         struct result
0043         {
0044             typedef typename match_result<ScannerT, functor_result_t>::type
0045             type;
0046         };
0047 
0048         template <typename ScannerT>
0049         typename parser_result<self_t, ScannerT>::type
0050         parse(ScannerT const& scan) const
0051         {
0052             typedef typename ScannerT::iterator_t   iterator_t;
0053 
0054             iterator_t const s(scan.first);
0055             functor_result_t functor_result;
0056             std::ptrdiff_t len = functor(scan, functor_result);
0057 
0058             if (len < 0)
0059                 return scan.no_match();
0060             else
0061                 return scan.create_match(std::size_t(len), functor_result, s, scan.first);
0062         }
0063     };
0064 
0065 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0066 
0067 }} // namespace BOOST_SPIRIT_CLASSIC_NS
0068 
0069 #endif