xlex_interface.hpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*=============================================================================
  2. Boost.Wave: A Standard compliant C++ preprocessor library
  3. Definition of the abstract lexer interface for the xpressive lexer
  4. http://www.boost.org/
  5. Copyright (c) 2001-2010 Hartmut Kaiser. Distributed under the Boost
  6. Software License, Version 1.0. (See accompanying file
  7. LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  8. =============================================================================*/
  9. #if !defined(XLEX_INTERFACE_HPP)
  10. #define XLEX_INTERFACE_HPP
  11. #include <boost/wave/language_support.hpp>
  12. #include <boost/wave/util/file_position.hpp>
  13. #include <boost/wave/cpplexer/cpp_lex_interface.hpp>
  14. ///////////////////////////////////////////////////////////////////////////////
  15. namespace boost {
  16. namespace wave {
  17. namespace cpplexer {
  18. namespace xlex {
  19. #if BOOST_WAVE_SEPARATE_LEXER_INSTANTIATION != 0
  20. #define BOOST_WAVE_NEW_LEXER_DECL BOOST_WAVE_DECL
  21. #else
  22. #define BOOST_WAVE_NEW_LEXER_DECL
  23. #endif
  24. ///////////////////////////////////////////////////////////////////////////////
  25. //
  26. // new_lexer_gen: generates a new instance of the required C++ lexer
  27. //
  28. ///////////////////////////////////////////////////////////////////////////////
  29. template <
  30. typename IteratorT,
  31. typename PositionT = wave::util::file_position_type
  32. >
  33. struct BOOST_WAVE_NEW_LEXER_DECL new_lexer_gen
  34. {
  35. // The NewLexer function allows the opaque generation of a new lexer object.
  36. // It is coupled to the token type to allow to decouple the lexer/token
  37. // configurations at compile time.
  38. static wave::cpplexer::lex_input_interface<wave::cpplexer::lex_token<PositionT> > *
  39. new_lexer(IteratorT const &first, IteratorT const &last,
  40. PositionT const &pos, wave::language_support language);
  41. };
  42. #undef BOOST_WAVE_NEW_LEXER_DECL
  43. ///////////////////////////////////////////////////////////////////////////////
  44. //
  45. // The xlex_input_interface helps to instantiate a concrete lexer to be used
  46. // by the Wave preprocessor module.
  47. // This is done to allow compile time reduction.
  48. //
  49. ///////////////////////////////////////////////////////////////////////////////
  50. template <typename TokenT>
  51. struct xlex_input_interface
  52. : lex_input_interface<TokenT>
  53. {
  54. typedef typename wave::cpplexer::lex_input_interface<TokenT>::position_type
  55. position_type;
  56. ~xlex_input_interface() {}
  57. // The new_lexer function allows the opaque generation of a new lexer object.
  58. // It is coupled to the token type to allow to distinguish different
  59. // lexer/token configurations at compile time.
  60. template <typename IteratorT>
  61. static wave::cpplexer::lex_input_interface<TokenT> *
  62. new_lexer(IteratorT const &first, IteratorT const &last,
  63. position_type const &pos, wave::language_support language)
  64. {
  65. return new_lexer_gen<IteratorT, position_type>::new_lexer (first, last,
  66. pos, language);
  67. }
  68. };
  69. ///////////////////////////////////////////////////////////////////////////////
  70. } // namespace xlex
  71. } // namespace cpplexer
  72. } // namespace wave
  73. } // namespace boost
  74. #endif // !defined(XLEX_INTERFACE_HPP)