sequence.hpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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_SEQUENCE_JAN_06_2013_1015AM)
  7. #define BOOST_SPIRIT_X3_SEQUENCE_JAN_06_2013_1015AM
  8. #include <boost/spirit/home/x3/support/traits/attribute_of_binary.hpp>
  9. #include <boost/spirit/home/x3/core/parser.hpp>
  10. #include <boost/spirit/home/x3/operator/detail/sequence.hpp>
  11. #include <boost/spirit/home/x3/directive/expect.hpp>
  12. #include <boost/fusion/include/deque_fwd.hpp>
  13. namespace boost { namespace spirit { namespace x3
  14. {
  15. template <typename Left, typename Right>
  16. struct sequence : binary_parser<Left, Right, sequence<Left, Right>>
  17. {
  18. typedef binary_parser<Left, Right, sequence<Left, Right>> base_type;
  19. constexpr sequence(Left const& left, Right const& right)
  20. : base_type(left, right) {}
  21. template <typename Iterator, typename Context, typename RContext>
  22. bool parse(
  23. Iterator& first, Iterator const& last
  24. , Context const& context, RContext& rcontext, unused_type) const
  25. {
  26. Iterator save = first;
  27. if (this->left.parse(first, last, context, rcontext, unused)
  28. && this->right.parse(first, last, context, rcontext, unused))
  29. return true;
  30. first = save;
  31. return false;
  32. }
  33. template <typename Iterator, typename Context
  34. , typename RContext, typename Attribute>
  35. bool parse(
  36. Iterator& first, Iterator const& last
  37. , Context const& context, RContext& rcontext, Attribute& attr) const
  38. {
  39. return detail::parse_sequence(*this, first, last, context, rcontext, attr
  40. , typename traits::attribute_category<Attribute>::type());
  41. }
  42. };
  43. template <typename Left, typename Right>
  44. constexpr sequence<
  45. typename extension::as_parser<Left>::value_type
  46. , typename extension::as_parser<Right>::value_type>
  47. operator>>(Left const& left, Right const& right)
  48. {
  49. return { as_parser(left), as_parser(right) };
  50. }
  51. template <typename Left, typename Right>
  52. constexpr auto operator>(Left const& left, Right const& right)
  53. {
  54. return left >> expect[right];
  55. }
  56. }}}
  57. namespace boost { namespace spirit { namespace x3 { namespace traits
  58. {
  59. template <typename Left, typename Right, typename Context>
  60. struct attribute_of<x3::sequence<Left, Right>, Context>
  61. : x3::detail::attribute_of_binary<fusion::deque, x3::sequence, Left, Right, Context> {};
  62. }}}}
  63. #endif