Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*=============================================================================
0002     Copyright (c) 2003 Hartmut Kaiser
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_SELECT_IPP
0010 #define BOOST_SPIRIT_SELECT_IPP
0011 
0012 #include <boost/spirit/home/classic/core/parser.hpp>
0013 #include <boost/spirit/home/classic/core/composite/composite.hpp>
0014 #include <boost/spirit/home/classic/meta/as_parser.hpp>
0015 
0016 ///////////////////////////////////////////////////////////////////////////////
0017 namespace boost { namespace spirit {
0018 
0019 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
0020 
0021 ///////////////////////////////////////////////////////////////////////////////
0022 namespace impl {
0023 
0024 ///////////////////////////////////////////////////////////////////////////////
0025 template <typename ParserT>
0026 struct as_embedded_parser : public as_parser<ParserT>
0027 {
0028     typedef typename as_parser<ParserT>::type::derived_t::embed_t type;
0029 };
0030 
0031 ///////////////////////////////////////////////////////////////////////////////
0032 
0033 // no implementation here to catch unknown BehaviourT template arguments
0034 template <typename ResultT, typename BehaviourT>
0035 struct select_match_gen;
0036 
0037 // implementation for the select_default_no_fail behaviour
0038 template <typename ResultT>
0039 struct select_match_gen<ResultT, select_default_no_fail> {
0040 
0041     template <typename ScannerT>
0042     static ResultT
0043     do_ (ScannerT const &scan)
0044     {
0045         return scan.create_match(0, -1, scan.first, scan.first);
0046     }
0047 };
0048 
0049 // implementation for the select_default_fail behaviour
0050 template <typename ResultT>
0051 struct select_match_gen<ResultT, select_default_fail> {
0052 
0053     template <typename ScannerT>
0054     static ResultT
0055     do_ (ScannerT const &scan)
0056     {
0057         return scan.no_match();
0058     }
0059 };
0060 
0061 ///////////////////////////////////////////////////////////////////////////////
0062 template <int N, typename ResultT, typename TupleT, typename BehaviourT>
0063 struct parse_tuple_element {
0064 
0065     BOOST_STATIC_CONSTANT(int, index = (TupleT::length - N));
0066     
0067     template <typename ScannerT>
0068     static ResultT
0069     do_(TupleT const &t, ScannerT const &scan)
0070     {
0071         typedef typename ::phoenix::tuple_element<index, TupleT>::type parser_t;
0072         typedef typename ScannerT::iterator_t                       iterator_t;
0073         typedef typename parser_result<parser_t, ScannerT>::type    result_t;
0074     
0075         iterator_t save(scan.first);
0076         ::phoenix::tuple_index<index> const idx;
0077         result_t result(t[idx].parse(scan));
0078 
0079         if (result) {
0080             return scan.create_match(result.length(), TupleT::length - N, 
0081                 save, scan.first);
0082         }
0083         scan.first = save;    // reset the input stream 
0084         return parse_tuple_element<N-1, ResultT, TupleT, BehaviourT>::
0085             do_(t, scan);
0086     }
0087 };
0088 
0089 template <typename ResultT, typename TupleT, typename BehaviourT>
0090 struct parse_tuple_element<1, ResultT, TupleT, BehaviourT> {
0091 
0092     BOOST_STATIC_CONSTANT(int, index = (TupleT::length - 1));
0093     
0094     template <typename ScannerT>
0095     static ResultT
0096     do_(TupleT const &t, ScannerT const &scan)
0097     {
0098         typedef typename ::phoenix::tuple_element<index, TupleT>::type  parser_t;
0099         typedef typename ScannerT::iterator_t                       iterator_t;
0100         typedef typename parser_result<parser_t, ScannerT>::type    result_t;
0101         
0102         iterator_t save(scan.first);
0103         ::phoenix::tuple_index<index> const idx;
0104         result_t result(t[idx].parse(scan));
0105 
0106         if (result) {
0107             return scan.create_match(result.length(), TupleT::length - 1, 
0108                 save, scan.first);
0109         }
0110         scan.first = save;    // reset the input stream 
0111         return select_match_gen<ResultT, BehaviourT>::do_(scan);
0112     }
0113 };
0114 
0115 ///////////////////////////////////////////////////////////////////////////////
0116 }   // namespace impl
0117 
0118 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0119 
0120 }}  // namespace boost::spirit
0121 
0122 #endif  // BOOST_SPIRIT_SELECT_IPP