File indexing completed on 2025-02-27 09:55:13
0001
0002
0003
0004
0005
0006
0007
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
0024
0025
0026
0027
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 }}
0068
0069 #endif