Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:02:15

0001 //  Copyright (c) 2001-2011 Hartmut Kaiser
0002 // 
0003 //  Distributed under the Boost Software License, Version 1.0. (See accompanying 
0004 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 #if !defined(BOOST_SPIRIT_LEX_LEXER_ITERATOR_MAR_16_2007_0353PM)
0007 #define BOOST_SPIRIT_LEX_LEXER_ITERATOR_MAR_16_2007_0353PM
0008 
0009 #if defined(_MSC_VER)
0010 #pragma once
0011 #endif
0012 
0013 #include <boost/spirit/home/support/multi_pass_wrapper.hpp>
0014 #if defined(BOOST_SPIRIT_DEBUG)
0015 #include <boost/spirit/home/support/iterators/detail/buf_id_check_policy.hpp>
0016 #else
0017 #include <boost/spirit/home/support/iterators/detail/no_check_policy.hpp>
0018 #endif
0019 #include <boost/spirit/home/support/iterators/detail/split_functor_input_policy.hpp>
0020 #include <boost/spirit/home/support/iterators/detail/ref_counted_policy.hpp>
0021 #include <boost/spirit/home/support/iterators/detail/split_std_deque_policy.hpp>
0022 #include <boost/spirit/home/support/iterators/multi_pass.hpp>
0023 
0024 namespace boost { namespace spirit { namespace lex { namespace lexertl
0025 { 
0026     ///////////////////////////////////////////////////////////////////////////
0027     template <typename FunctorData>
0028     struct make_multi_pass
0029     {
0030         // Divide the given functor type into its components (unique and 
0031         // shared) and build a std::pair from these parts
0032         typedef std::pair<typename FunctorData::unique
0033           , typename FunctorData::shared> functor_data_type;
0034 
0035         // This is the result type returned from the iterator
0036         typedef typename FunctorData::result_type result_type;
0037 
0038         // Compose the multi_pass iterator policy type from the appropriate 
0039         // policies
0040         typedef iterator_policies::split_functor_input input_policy;
0041         typedef iterator_policies::ref_counted ownership_policy;
0042 #if defined(BOOST_SPIRIT_DEBUG)
0043         typedef iterator_policies::buf_id_check check_policy;
0044 #else
0045         typedef iterator_policies::no_check check_policy;
0046 #endif
0047         typedef iterator_policies::split_std_deque storage_policy;
0048 
0049         typedef iterator_policies::default_policy<
0050                 ownership_policy, check_policy, input_policy, storage_policy>
0051             policy_type;
0052 
0053         // Compose the multi_pass iterator from the policy
0054         typedef spirit::multi_pass<functor_data_type, policy_type> type;
0055     };
0056 
0057     ///////////////////////////////////////////////////////////////////////////
0058     //  lexer_iterator exposes an iterator for a lexertl based dfa (lexer) 
0059     //  The template parameters have the same semantics as described for the
0060     //  functor above.
0061     ///////////////////////////////////////////////////////////////////////////
0062     template <typename Functor>
0063     class iterator : public make_multi_pass<Functor>::type
0064     {
0065     public:
0066         typedef typename Functor::unique unique_functor_type;
0067         typedef typename Functor::shared shared_functor_type;
0068 
0069         typedef typename Functor::iterator_type base_iterator_type;
0070         typedef typename Functor::result_type token_type;
0071 
0072     private:
0073         typedef typename make_multi_pass<Functor>::functor_data_type 
0074             functor_type;
0075         typedef typename make_multi_pass<Functor>::type base_type;
0076         typedef typename Functor::char_type char_type;
0077 
0078     public:
0079         // create a new iterator encapsulating the lexer object to be used
0080         // for tokenization
0081         template <typename IteratorData>
0082         iterator(IteratorData const& iterdata_, base_iterator_type& first
0083               , base_iterator_type const& last, char_type const* state = 0)
0084           : base_type(functor_type(unique_functor_type()
0085               , shared_functor_type(iterdata_, first, last))) 
0086         {
0087             set_state(map_state(state));
0088         }
0089 
0090         // create an end iterator usable for end of range checking
0091         iterator() {}
0092 
0093         // (wash): < mgaunard> T it; T it2 = ++it; doesn't ocmpile
0094         //         < mgaunard> this gets fixed by adding
0095         iterator(const base_type& base)
0096           : base_type(base) { }
0097 
0098         // set the new required state for the underlying lexer object
0099         std::size_t set_state(std::size_t state)
0100         {
0101             return unique_functor_type::set_state(*this, state);
0102         }
0103 
0104         // get the current state for the underlying lexer object
0105         std::size_t get_state()
0106         {
0107             return unique_functor_type::get_state(*this);
0108         }
0109 
0110         // map the given state name to a corresponding state id as understood
0111         // by the underlying lexer object
0112         std::size_t map_state(char_type const* statename)
0113         {
0114             return (0 != statename) 
0115               ? unique_functor_type::map_state(*this, statename)
0116               : 0;
0117         }
0118     };
0119 }}
0120 
0121 namespace traits 
0122 { 
0123     template <typename Functor>
0124     struct is_multi_pass<spirit::lex::lexertl::iterator<Functor> >
0125       : mpl::true_ {};
0126 
0127     template <typename Functor>
0128     void clear_queue(spirit::lex::lexertl::iterator<Functor> & mp
0129         , BOOST_SCOPED_ENUM(traits::clear_mode) mode)
0130     {
0131         mp.clear_queue(mode);
0132     }
0133 
0134     template <typename Functor>
0135     void inhibit_clear_queue(spirit::lex::lexertl::iterator<Functor>& mp, bool flag)
0136     {
0137         mp.inhibit_clear_queue(flag);
0138     }
0139 
0140     template <typename Functor> 
0141     bool inhibit_clear_queue(spirit::lex::lexertl::iterator<Functor>& mp)
0142     {
0143         return mp.inhibit_clear_queue();
0144     }
0145 }
0146 
0147 }}
0148 
0149 #endif