raw.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*=============================================================================
  2. Copyright (c) 2014 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_X3_RAW_APRIL_9_2007_0912AM)
  7. #define SPIRIT_X3_RAW_APRIL_9_2007_0912AM
  8. #include <boost/spirit/home/x3/core/skip_over.hpp>
  9. #include <boost/spirit/home/x3/core/parser.hpp>
  10. #include <boost/spirit/home/x3/support/traits/move_to.hpp>
  11. #include <boost/range/iterator_range.hpp>
  12. namespace boost { namespace spirit { namespace x3
  13. {
  14. // this is a pseudo attribute type indicating that the parser wants the
  15. // iterator range pointing to the [first, last) matching characters from
  16. // the input iterators.
  17. struct raw_attribute_type {};
  18. template <typename Subject>
  19. struct raw_directive : unary_parser<Subject, raw_directive<Subject>>
  20. {
  21. typedef unary_parser<Subject, raw_directive<Subject> > base_type;
  22. typedef raw_attribute_type attribute_type;
  23. static bool const handles_container = Subject::handles_container;
  24. typedef Subject subject_type;
  25. raw_directive(Subject const& subject)
  26. : base_type(subject) {}
  27. template <typename Iterator, typename Context
  28. , typename RContext, typename Attribute>
  29. bool parse(Iterator& first, Iterator const& last
  30. , Context const& context, RContext& rcontext, Attribute& attr) const
  31. {
  32. x3::skip_over(first, last, context);
  33. Iterator i = first;
  34. if (this->subject.parse(i, last, context, rcontext, unused))
  35. {
  36. traits::move_to(first, i, attr);
  37. first = i;
  38. return true;
  39. }
  40. return false;
  41. }
  42. template <typename Iterator, typename Context, typename RContext>
  43. bool parse(Iterator& first, Iterator const& last
  44. , Context const& context, RContext& rcontext, unused_type) const
  45. {
  46. return this->subject.parse(first, last, context, rcontext, unused);
  47. }
  48. };
  49. struct raw_gen
  50. {
  51. template <typename Subject>
  52. raw_directive<typename extension::as_parser<Subject>::value_type>
  53. operator[](Subject const& subject) const
  54. {
  55. return { as_parser(subject) };
  56. }
  57. };
  58. auto const raw = raw_gen{};
  59. }}}
  60. #endif