raw.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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_RAW_APRIL_9_2007_0912AM)
  7. #define SPIRIT_RAW_APRIL_9_2007_0912AM
  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/assign_to.hpp>
  15. #include <boost/spirit/home/support/unused.hpp>
  16. #include <boost/spirit/home/support/info.hpp>
  17. #include <boost/spirit/home/support/common_terminals.hpp>
  18. #include <boost/spirit/home/support/unused.hpp>
  19. #include <boost/spirit/home/support/has_semantic_action.hpp>
  20. #include <boost/spirit/home/support/handles_container.hpp>
  21. #include <boost/range/iterator_range.hpp>
  22. namespace boost { namespace spirit
  23. {
  24. ///////////////////////////////////////////////////////////////////////////
  25. // Enablers
  26. ///////////////////////////////////////////////////////////////////////////
  27. template <>
  28. struct use_directive<qi::domain, tag::raw> // enables raw
  29. : mpl::true_ {};
  30. }}
  31. namespace boost { namespace spirit { namespace qi
  32. {
  33. #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
  34. using spirit::raw;
  35. #endif
  36. using spirit::raw_type;
  37. template <typename Subject>
  38. struct raw_directive : unary_parser<raw_directive<Subject> >
  39. {
  40. typedef Subject subject_type;
  41. raw_directive(Subject const& subject_)
  42. : subject(subject_) {}
  43. template <typename Context, typename Iterator>
  44. struct attribute
  45. {
  46. typedef iterator_range<Iterator> 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, Attribute& attr_) const
  52. {
  53. qi::skip_over(first, last, skipper);
  54. Iterator i = first;
  55. if (subject.parse(i, last, context, skipper, unused))
  56. {
  57. spirit::traits::assign_to(first, i, attr_);
  58. first = i;
  59. return true;
  60. }
  61. return false;
  62. }
  63. template <typename Context>
  64. info what(Context& context) const
  65. {
  66. return info("raw", subject.what(context));
  67. }
  68. Subject subject;
  69. };
  70. ///////////////////////////////////////////////////////////////////////////
  71. // Parser generators: make_xxx function (objects)
  72. ///////////////////////////////////////////////////////////////////////////
  73. template <typename Subject, typename Modifiers>
  74. struct make_directive<tag::raw, Subject, Modifiers>
  75. {
  76. typedef raw_directive<Subject> result_type;
  77. result_type operator()(unused_type, Subject const& subject, unused_type) const
  78. {
  79. return result_type(subject);
  80. }
  81. };
  82. }}}
  83. namespace boost { namespace spirit { namespace traits
  84. {
  85. ///////////////////////////////////////////////////////////////////////////
  86. template <typename Subject>
  87. struct has_semantic_action<qi::raw_directive<Subject> >
  88. : unary_has_semantic_action<Subject> {};
  89. ///////////////////////////////////////////////////////////////////////////
  90. template <typename Subject, typename Attribute, typename Context
  91. , typename Iterator>
  92. struct handles_container<qi::raw_directive<Subject>, Attribute
  93. , Context, Iterator>
  94. : unary_handles_container<Subject, Attribute, Context, Iterator> {};
  95. }}}
  96. #endif