lexeme.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. =============================================================================*/
  6. #if !defined(SPIRIT_LEXEME_MARCH_24_2007_0802AM)
  7. #define SPIRIT_LEXEME_MARCH_24_2007_0802AM
  8. #if defined(_MSC_VER)
  9. #pragma once
  10. #endif
  11. #include <boost/spirit/home/qi/meta_compiler.hpp>
  12. #include <boost/spirit/home/qi/skip_over.hpp>
  13. #include <boost/spirit/home/qi/parser.hpp>
  14. #include <boost/spirit/home/qi/detail/unused_skipper.hpp>
  15. #include <boost/spirit/home/support/unused.hpp>
  16. #include <boost/spirit/home/support/common_terminals.hpp>
  17. #include <boost/spirit/home/qi/detail/attributes.hpp>
  18. #include <boost/spirit/home/support/info.hpp>
  19. #include <boost/spirit/home/support/handles_container.hpp>
  20. namespace boost { namespace spirit
  21. {
  22. ///////////////////////////////////////////////////////////////////////////
  23. // Enablers
  24. ///////////////////////////////////////////////////////////////////////////
  25. template <>
  26. struct use_directive<qi::domain, tag::lexeme> // enables lexeme
  27. : mpl::true_ {};
  28. }}
  29. namespace boost { namespace spirit { namespace qi
  30. {
  31. #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
  32. using spirit::lexeme;
  33. #endif
  34. using spirit::lexeme_type;
  35. template <typename Subject>
  36. struct lexeme_directive : unary_parser<lexeme_directive<Subject> >
  37. {
  38. typedef Subject subject_type;
  39. lexeme_directive(Subject const& subject_)
  40. : subject(subject_) {}
  41. template <typename Context, typename Iterator>
  42. struct attribute
  43. {
  44. typedef typename
  45. traits::attribute_of<subject_type, Context, Iterator>::type
  46. type;
  47. };
  48. template <typename Iterator, typename Context
  49. , typename Skipper, typename Attribute>
  50. bool parse(Iterator& first, Iterator const& last
  51. , Context& context, Skipper const& skipper
  52. , Attribute& attr_) const
  53. {
  54. qi::skip_over(first, last, skipper);
  55. return subject.parse(first, last, context
  56. , detail::unused_skipper<Skipper>(skipper), attr_);
  57. }
  58. template <typename Context>
  59. info what(Context& context) const
  60. {
  61. return info("lexeme", subject.what(context));
  62. }
  63. Subject subject;
  64. };
  65. ///////////////////////////////////////////////////////////////////////////
  66. // Parser generators: make_xxx function (objects)
  67. ///////////////////////////////////////////////////////////////////////////
  68. template <typename Subject, typename Modifiers>
  69. struct make_directive<tag::lexeme, Subject, Modifiers>
  70. {
  71. typedef lexeme_directive<Subject> result_type;
  72. result_type operator()(unused_type, Subject const& subject, unused_type) const
  73. {
  74. return result_type(subject);
  75. }
  76. };
  77. }}}
  78. namespace boost { namespace spirit { namespace traits
  79. {
  80. ///////////////////////////////////////////////////////////////////////////
  81. template <typename Subject>
  82. struct has_semantic_action<qi::lexeme_directive<Subject> >
  83. : unary_has_semantic_action<Subject> {};
  84. ///////////////////////////////////////////////////////////////////////////
  85. template <typename Subject, typename Attribute, typename Context
  86. , typename Iterator>
  87. struct handles_container<qi::lexeme_directive<Subject>, Attribute
  88. , Context, Iterator>
  89. : unary_handles_container<Subject, Attribute, Context, Iterator> {};
  90. }}}
  91. #endif