source: NonGTP/Boost/boost/wave/cpplexer/cpp_lex_interface.hpp @ 857

Revision 857, 3.1 KB checked in by igarcia, 19 years ago (diff)
Line 
1/*=============================================================================
2    Boost.Wave: A Standard compliant C++ preprocessor library
3
4    Definition of the abstract lexer interface
5   
6    http://www.boost.org/
7
8    Copyright (c) 2001-2005 Hartmut Kaiser. Distributed under the Boost
9    Software License, Version 1.0. (See accompanying file
10    LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11=============================================================================*/
12
13#if !defined(CPP_LEX_INTERFACE_HPP_E83F52A4_90AC_4FBE_A9A7_B65F7F94C497_INCLUDED)
14#define CPP_LEX_INTERFACE_HPP_E83F52A4_90AC_4FBE_A9A7_B65F7F94C497_INCLUDED
15
16#include <boost/wave/util/file_position.hpp>
17#include <boost/wave/language_support.hpp>
18
19///////////////////////////////////////////////////////////////////////////////
20namespace boost {
21namespace wave {
22namespace cpplexer {
23
24///////////////////////////////////////////////////////////////////////////////
25// 
26//  new_lexer_gen: generates a new instance of the required C++ lexer
27//
28///////////////////////////////////////////////////////////////////////////////
29template <typename TokenT> struct lex_input_interface;
30
31template <
32    typename IteratorT,
33    typename PositionT = boost::wave::util::file_position_type
34>
35struct new_lexer_gen
36{
37//  The NewLexer function allows the opaque generation of a new lexer object.
38//  It is coupled to the token type to allow to decouple the lexer/token
39//  configurations at compile time.
40    static lex_input_interface<lex_token<PositionT> > *
41    new_lexer(IteratorT const &first, IteratorT const &last,
42        PositionT const &pos, boost::wave::language_support language);
43};
44
45///////////////////////////////////////////////////////////////////////////////
46//
47//  The lex_input_interface decouples the lex_iterator_shim from the actual
48//  lexer. This is done to allow compile time reduction.
49//  Thanks to JCAB for having this idea.
50//
51///////////////////////////////////////////////////////////////////////////////
52
53template <typename TokenT>
54struct lex_input_interface
55{
56    typedef typename TokenT::position_type position_type;
57   
58    virtual TokenT get() = 0;
59    virtual void set_position(position_type const &pos) = 0;
60
61    virtual ~lex_input_interface() {}
62   
63//  The new_lexer function allows the opaque generation of a new lexer object.
64//  It is coupled to the token type to allow to distinguish different
65//  lexer/token configurations at compile time.
66    template <typename IteratorT>
67    static lex_input_interface *
68    new_lexer(IteratorT const &first, IteratorT const &last,
69        position_type const &pos, boost::wave::language_support language)
70    {
71        return new_lexer_gen<IteratorT, position_type>::new_lexer (first, last,
72            pos, language);
73    }
74};
75
76///////////////////////////////////////////////////////////////////////////////
77}   // namespace cpplexer
78}   // namespace wave
79}   // namespace boost
80
81#endif // !defined(CPP_LEX_INTERFACE_HPP_E83F52A4_90AC_4FBE_A9A7_B65F7F94C497_INCLUDED)
Note: See TracBrowser for help on using the repository browser.