no_case.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*=============================================================================
  2. Copyright (c) 2014 Thomas Bernard
  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(BOOST_SPIRIT_X3_NO_CASE_SEPT_16_2014_0912PM)
  7. #define BOOST_SPIRIT_X3_NO_CASE_SEPT_16_2014_0912PM
  8. #include <boost/spirit/home/x3/support/context.hpp>
  9. #include <boost/spirit/home/x3/support/unused.hpp>
  10. #include <boost/spirit/home/x3/support/no_case.hpp>
  11. #include <boost/spirit/home/x3/core/parser.hpp>
  12. namespace boost { namespace spirit { namespace x3
  13. {
  14. // propagate no_case information through the context
  15. template <typename Subject>
  16. struct no_case_directive : unary_parser<Subject, no_case_directive<Subject>>
  17. {
  18. typedef unary_parser<Subject, no_case_directive<Subject> > base_type;
  19. static bool const is_pass_through_unary = true;
  20. static bool const handles_container = Subject::handles_container;
  21. no_case_directive(Subject const& subject)
  22. : base_type(subject) {}
  23. template <typename Iterator, typename Context
  24. , typename RContext, typename Attribute>
  25. bool parse(Iterator& first, Iterator const& last
  26. , Context const& context, RContext& rcontext, Attribute& attr) const
  27. {
  28. return this->subject.parse(
  29. first, last
  30. , make_context<no_case_tag>(no_case_compare_, context)
  31. , rcontext
  32. , attr);
  33. }
  34. };
  35. struct no_case_gen
  36. {
  37. template <typename Subject>
  38. no_case_directive<typename extension::as_parser<Subject>::value_type>
  39. operator[](Subject const& subject) const
  40. {
  41. return { as_parser(subject) };
  42. }
  43. };
  44. auto const no_case = no_case_gen{};
  45. }}}
  46. #endif