seek.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*=============================================================================
  2. Copyright (c) 2011 Jamboree
  3. Copyright (c) 2014 Lee Clagett
  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. ==============================================================================*/
  7. #if !defined(BOOST_SPIRIT_X3_SEEK_APRIL_13_2014_1920PM)
  8. #define BOOST_SPIRIT_X3_SEEK_APRIL_13_2014_1920PM
  9. #include <boost/spirit/home/x3/core/parser.hpp>
  10. namespace boost { namespace spirit { namespace x3
  11. {
  12. template<typename Subject>
  13. struct seek_directive : unary_parser<Subject, seek_directive<Subject>>
  14. {
  15. typedef unary_parser<Subject, seek_directive<Subject>> base_type;
  16. static bool const is_pass_through_unary = true;
  17. static bool const handles_container = Subject::handles_container;
  18. constexpr seek_directive(Subject const& subject) :
  19. base_type(subject) {}
  20. template<typename Iterator, typename Context
  21. , typename RContext, typename Attribute>
  22. bool parse(
  23. Iterator& first, Iterator const& last
  24. , Context const& context, RContext& rcontext, Attribute& attr) const
  25. {
  26. Iterator current(first);
  27. for (/**/; current != last; ++current)
  28. {
  29. if (this->subject.parse(current, last, context, rcontext, attr))
  30. {
  31. first = current;
  32. return true;
  33. }
  34. }
  35. // Test for when subjects match on input empty. Example:
  36. // comment = "//" >> seek[eol | eoi]
  37. if (this->subject.parse(current, last, context, rcontext, attr))
  38. {
  39. first = current;
  40. return true;
  41. }
  42. return false;
  43. }
  44. };
  45. struct seek_gen
  46. {
  47. template<typename Subject>
  48. constexpr seek_directive<typename extension::as_parser<Subject>::value_type>
  49. operator[](Subject const& subject) const
  50. {
  51. return { as_parser(subject) };
  52. }
  53. };
  54. constexpr auto seek = seek_gen{};
  55. }}}
  56. #endif