/*============================================================================= Wave: A Standard compliant C++ preprocessor library Definition of the lexer iterator Copyright (c) 2001-2004 Hartmut Kaiser http://spirit.sourceforge.net/ Use, modification and distribution is subject to the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ #if !defined(SLEX_ITERATOR_HPP_AF0C37E3_CBD8_4F33_A225_51CF576FA61F_INCLUDED) #define SLEX_ITERATOR_HPP_AF0C37E3_CBD8_4F33_A225_51CF576FA61F_INCLUDED #include #include #include #include #include #include #include #include #include "slex_interface.hpp" /////////////////////////////////////////////////////////////////////////////// namespace boost { namespace wave { namespace cpp_token_sample { namespace impl { /////////////////////////////////////////////////////////////////////////////// // // lex_iterator_functor_shim // /////////////////////////////////////////////////////////////////////////////// template class slex_iterator_functor_shim { public: template slex_iterator_functor_shim(IteratorT const &first, IteratorT const &last, typename TokenT::position_t const &pos, boost::wave::language_support language) : functor_ptr(slex_input_interface ::new_lexer(first, last, pos, language)) {} // interface to the boost::spirit::multi_pass_policies::functor_input policy typedef TokenT result_type; /*static*/ result_type const eof; result_type operator()() { BOOST_ASSERT(0 != functor_ptr.get()); return functor_ptr->get(); } void set_position(typename TokenT::position_t const &pos) { BOOST_ASSERT(0 != functor_ptr.get()); functor_ptr->set_position(pos); } private: boost::shared_ptr > functor_ptr; }; /////////////////////////////////////////////////////////////////////////////// // eof token //template //typename slex_iterator_functor_shim::result_type const // slex_iterator_functor_shim::eof = // typename slex_iterator_functor_shim::result_type(); /////////////////////////////////////////////////////////////////////////////// } // namespace impl /////////////////////////////////////////////////////////////////////////////// // // slex_iterator // // A generic C++ lexer interface class, which allows to plug in different // lexer implementations (template parameter LexT). The following // requirement apply: // // - the lexer type should have a function implemented, which returnes // the next lexed token from the input stream: // typename LexT::token_t get(); // - at the end of the input stream this function should return the // eof token equivalent // - the lexer should implement a constructor taking two iterators // pointing to the beginning and the end of the input stream and // a third parameter containing the name of the parsed input file // /////////////////////////////////////////////////////////////////////////////// template class slex_iterator : public boost::spirit::multi_pass< impl::slex_iterator_functor_shim, boost::wave::util::functor_input > { typedef impl::slex_iterator_functor_shim input_policy_t; typedef boost::spirit::multi_pass base_t; typedef slex_iterator self_t; public: typedef TokenT token_t; slex_iterator() {} template slex_iterator(IteratorT const &first, IteratorT const &last, typename TokenT::position_t const &pos, boost::wave::language_support language) : base_t(input_policy_t(first, last, pos, language)) {} }; /////////////////////////////////////////////////////////////////////////////// } // namespace cpp_token_sample } // namespace wave } // namespace boost #endif // !defined(SLEX_ITERATOR_HPP_AF0C37E3_CBD8_4F33_A225_51CF576FA61F_INCLUDED)