reference.hpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright (c) 2001-2011 Hartmut Kaiser
  2. // Copyright (c) 2001-2011 Joel de Guzman
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #if !defined(BOOST_SPIRIT_LEX_REFERENCE_APR_20_2009_0827AM)
  7. #define BOOST_SPIRIT_LEX_REFERENCE_APR_20_2009_0827AM
  8. #if defined(_MSC_VER)
  9. #pragma once
  10. #endif
  11. #include <boost/spirit/home/lex/meta_compiler.hpp>
  12. #include <boost/spirit/home/lex/lexer_type.hpp>
  13. #include <boost/spirit/home/qi/reference.hpp>
  14. #include <boost/spirit/home/support/info.hpp>
  15. #include <boost/spirit/home/support/handles_container.hpp>
  16. #include <boost/ref.hpp>
  17. namespace boost { namespace spirit { namespace lex
  18. {
  19. ///////////////////////////////////////////////////////////////////////////
  20. // reference is a lexer that references another lexer (its Subject)
  21. // all lexer components are at the same time
  22. ///////////////////////////////////////////////////////////////////////////
  23. template <typename Subject, typename IdType = unused_type>
  24. struct reference;
  25. template <typename Subject>
  26. struct reference<Subject, unused_type>
  27. : qi::reference<Subject>
  28. , lexer_type<reference<Subject> >
  29. {
  30. reference(Subject& subject)
  31. : qi::reference<Subject>(subject) {}
  32. template <typename LexerDef, typename String>
  33. void collect(LexerDef& lexdef, String const& state
  34. , String const& targetstate) const
  35. {
  36. this->ref.get().collect(lexdef, state, targetstate);
  37. }
  38. template <typename LexerDef>
  39. void add_actions(LexerDef& lexdef) const
  40. {
  41. this->ref.get().add_actions(lexdef);
  42. }
  43. };
  44. template <typename Subject, typename IdType>
  45. struct reference : reference<Subject>
  46. {
  47. reference(Subject& subject)
  48. : reference<Subject>(subject) {}
  49. IdType id() const
  50. {
  51. return this->ref.get().id();
  52. }
  53. std::size_t unique_id() const
  54. {
  55. return this->ref.get().unique_id();
  56. }
  57. std::size_t state() const
  58. {
  59. return this->ref.get().state();
  60. }
  61. };
  62. }}}
  63. namespace boost { namespace spirit { namespace traits
  64. {
  65. ///////////////////////////////////////////////////////////////////////////
  66. template <typename Subject, typename IdType
  67. , typename Attribute, typename Context, typename Iterator>
  68. struct handles_container<lex::reference<Subject, IdType>
  69. , Attribute, Context, Iterator>
  70. : handles_container<
  71. typename remove_const<Subject>::type, Attribute, Context, Iterator>
  72. {};
  73. }}}
  74. #endif