Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:01:56

0001 /*=============================================================================
0002     Copyright (c) 2002-2003 Martin Wille
0003     http://spirit.sourceforge.net/
0004 
0005     Use, modification and distribution is subject to the Boost Software
0006     License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0007     http://www.boost.org/LICENSE_1_0.txt)
0008 =============================================================================*/
0009 #ifndef BOOST_SPIRIT_CONDITIONS_IPP
0010 #define BOOST_SPIRIT_CONDITIONS_IPP
0011 
0012 ///////////////////////////////////////////////////////////////////////////////
0013 #include <boost/spirit/home/classic/meta/parser_traits.hpp>
0014 #include <boost/spirit/home/classic/core/composite/epsilon.hpp>
0015 
0016 ///////////////////////////////////////////////////////////////////////////////
0017 namespace boost { namespace spirit {
0018 
0019 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
0020 
0021     namespace impl {
0022 
0023 ///////////////////////////////////////////////////////////////////////////////
0024 //
0025 // condition evaluation
0026 //
0027 ///////////////////////////////////////////////////////////////////////////////
0028     //////////////////////////////////
0029     // condition_parser_selector, decides which parser to use for a condition
0030     // If the template argument is a parser then that parser is used.
0031     // If the template argument is a functor then a condition parser using
0032     // the functor is chosen
0033 
0034     template <typename T> struct embed_t_accessor
0035     {
0036         typedef typename T::embed_t type;
0037     };
0038 
0039     template <typename ConditionT>
0040     struct condition_parser_selector
0041     {
0042         typedef
0043             typename mpl::if_<
0044                     is_parser<ConditionT>,
0045                     ConditionT,
0046                     condition_parser<ConditionT>
0047                 >::type
0048             type;
0049 
0050         typedef typename embed_t_accessor<type>::type embed_t;
0051     };
0052 
0053     //////////////////////////////////
0054     // condition_evaluator, uses a parser to check wether a condition is met
0055     // takes a parser or a functor that can be evaluated in boolean context
0056     // as template parameter.
0057 
0058     // JDG 4-15-03 refactored
0059     template <typename ConditionT>
0060     struct condition_evaluator
0061     {
0062         typedef condition_parser_selector<ConditionT>       selector_t;
0063         typedef typename selector_t::type                   selected_t;
0064         typedef typename selector_t::embed_t                cond_embed_t;
0065 
0066         typedef typename boost::call_traits<cond_embed_t>::param_type
0067             param_t;
0068 
0069         condition_evaluator(param_t s) : cond(s) {}
0070 
0071         /////////////////////////////
0072         // evaluate, checks wether condition is met
0073         // returns length of a match or a negative number for no-match
0074         template <typename ScannerT>
0075         std::ptrdiff_t
0076         evaluate(ScannerT const &scan) const
0077         {
0078             typedef typename ScannerT::iterator_t iterator_t;
0079             typedef typename parser_result<selected_t, ScannerT>::type cres_t;
0080             iterator_t save(scan.first);
0081             cres_t result = cond.parse(scan);
0082             if (!result)            // reset the position if evaluation
0083                 scan.first = save;  // fails.
0084             return result.length();
0085         }
0086 
0087         cond_embed_t cond;
0088     };
0089 
0090 ///////////////////////////////////////////////////////////////////////////////
0091     } // namespace impl
0092 
0093 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0094 
0095 }} // namespace boost::spirit
0096 
0097 #endif