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-2010 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(IDL_LEX_INTERFACE_HPP_INCLUDED)
14 #define IDL_LEX_INTERFACE_HPP_INCLUDED
15 
16 #include <boost/wave/util/file_position.hpp>
17 #include <boost/wave/language_support.hpp>
18 #include <boost/wave/cpplexer/cpp_lex_interface_generator.hpp>
19 
20 ///////////////////////////////////////////////////////////////////////////////
21 namespace boost {
22 namespace wave {
23 namespace idllexer {
24 
25 ///////////////////////////////////////////////////////////////////////////////
26 //
27 //  new_lexer_gen: generates a new instance of the required C++ lexer
28 //
29 ///////////////////////////////////////////////////////////////////////////////
30 template <
31     typename IteratorT,
32     typename PositionT = boost::wave::util::file_position_type
33 >
34 struct new_lexer_gen
35 {
36 //  The NewLexer function allows the opaque generation of a new lexer object.
37 //  It is coupled to the token type to allow to decouple the lexer/token
38 //  configurations at compile time.
39     static cpplexer::lex_input_interface<
40         cpplexer::lex_token<PositionT>
41     > *
42     new_lexer(IteratorT const &first, IteratorT const &last,
43         PositionT const &pos, boost::wave::language_support language);
44 };
45 
46 ///////////////////////////////////////////////////////////////////////////////
47 //
48 //  The lex_input_interface decouples the lex_iterator_shim from the actual
49 //  lexer. This is done to allow compile time reduction.
50 //  Thanks to JCAB for having this idea.
51 //
52 ///////////////////////////////////////////////////////////////////////////////
53 
54 template <typename TokenT>
55 struct lex_input_interface_generator
56 :   cpplexer::lex_input_interface<TokenT>
57 {
58     typedef typename cpplexer::lex_input_interface<TokenT>::position_type position_type;
59 
60 //  The new_lexer function allows the opaque generation of a new lexer object.
61 //  It is coupled to the token type to allow to distinguish different
62 //  lexer/token configurations at compile time.
63     template <typename IteratorT>
64     static cpplexer::lex_input_interface<TokenT> *
new_lexerboost::wave::idllexer::lex_input_interface_generator65     new_lexer(IteratorT const &first, IteratorT const &last,
66         position_type const &pos, boost::wave::language_support language)
67     {
68         return new_lexer_gen<IteratorT, position_type>::new_lexer (first, last,
69             pos, language);
70     }
71 };
72 
73 ///////////////////////////////////////////////////////////////////////////////
74 }   // namespace cpplexer
75 }   // namespace wave
76 }   // namespace boost
77 
78 #endif // !defined(IDL_LEX_INTERFACE_HPP_INCLUDED)
79