matches.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*=============================================================================
  2. Copyright (c) 2015 Mario Lang
  3. Copyright (c) 2001-2011 Hartmut Kaiser
  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_HOME_X3_EXTENSIONS_MATCHES_HPP)
  8. #define BOOST_SPIRIT_HOME_X3_EXTENSIONS_MATCHES_HPP
  9. #include <boost/spirit/home/x3/core/parser.hpp>
  10. #include <boost/spirit/home/x3/support/traits/move_to.hpp>
  11. #include <boost/spirit/home/x3/support/unused.hpp>
  12. namespace boost { namespace spirit { namespace x3
  13. {
  14. template <typename Subject>
  15. struct matches_directive : unary_parser<Subject, matches_directive<Subject>>
  16. {
  17. using base_type = unary_parser<Subject, matches_directive<Subject>>;
  18. static bool const has_attribute = true;
  19. using attribute_type = bool;
  20. matches_directive(Subject const& subject) : base_type(subject) {}
  21. template <typename Iterator, typename Context
  22. , typename RContext, typename Attribute>
  23. bool parse(Iterator& first, Iterator const& last
  24. , Context const& context, RContext& rcontext, Attribute& attr) const
  25. {
  26. bool const result = this->subject.parse(
  27. first, last, context, rcontext, unused);
  28. traits::move_to(result, attr);
  29. return true;
  30. }
  31. };
  32. struct matches_gen
  33. {
  34. template <typename Subject>
  35. matches_directive<typename extension::as_parser<Subject>::value_type>
  36. operator[](Subject const& subject) const
  37. {
  38. return { as_parser(subject) };
  39. }
  40. };
  41. auto const matches = matches_gen{};
  42. }}}
  43. #endif