idl_lex_interface.hpp 2.9 KB

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