eps.hpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*=============================================================================
  2. Copyright (c) 2001-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(BOOST_SPIRIT_X3_EPS_MARCH_23_2007_0454PM)
  7. #define BOOST_SPIRIT_X3_EPS_MARCH_23_2007_0454PM
  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/unused.hpp>
  11. namespace boost { namespace spirit { namespace x3
  12. {
  13. struct rule_context_tag;
  14. struct semantic_predicate : parser<semantic_predicate>
  15. {
  16. typedef unused_type attribute_type;
  17. static bool const has_attribute = false;
  18. semantic_predicate(bool predicate)
  19. : predicate(predicate) {}
  20. template <typename Iterator, typename Context, typename Attribute>
  21. bool parse(Iterator& first, Iterator const& last
  22. , Context const& context, unused_type, Attribute&) const
  23. {
  24. x3::skip_over(first, last, context);
  25. return predicate;
  26. }
  27. bool predicate;
  28. };
  29. template <typename F>
  30. struct lazy_semantic_predicate : parser<lazy_semantic_predicate<F>>
  31. {
  32. typedef unused_type attribute_type;
  33. static bool const has_attribute = false;
  34. lazy_semantic_predicate(F f)
  35. : f(f) {}
  36. template <typename Iterator, typename Context, typename Attribute>
  37. bool parse(Iterator& first, Iterator const& last
  38. , Context const& context, unused_type, Attribute& /* attr */) const
  39. {
  40. x3::skip_over(first, last, context);
  41. return f(x3::get<rule_context_tag>(context));
  42. }
  43. F f;
  44. };
  45. struct eps_parser : parser<eps_parser>
  46. {
  47. typedef unused_type attribute_type;
  48. static bool const has_attribute = false;
  49. template <typename Iterator, typename Context
  50. , typename RuleContext, typename Attribute>
  51. bool parse(Iterator& first, Iterator const& last
  52. , Context const& context, RuleContext&, Attribute&) const
  53. {
  54. x3::skip_over(first, last, context);
  55. return true;
  56. }
  57. inline semantic_predicate operator()(bool predicate) const
  58. {
  59. return { predicate };
  60. }
  61. template <typename F>
  62. lazy_semantic_predicate<F> operator()(F f) const
  63. {
  64. return { f };
  65. }
  66. };
  67. auto const eps = eps_parser{};
  68. }}}
  69. #endif