utils.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*=============================================================================
  2. Copyright (c) 2019 Nikita Kniazev
  3. Use, modification and distribution is subject to the Boost Software
  4. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt)
  6. =============================================================================*/
  7. #if !defined(BOOST_SPIRIT_TEST_X3_UTILS_HPP)
  8. #define BOOST_SPIRIT_TEST_X3_UTILS_HPP
  9. #include <boost/spirit/home/x3/core/parser.hpp>
  10. struct move_only
  11. {
  12. move_only() = default;
  13. move_only(move_only&&) = default;
  14. move_only& operator=(move_only&&) = default;
  15. };
  16. template <typename T>
  17. struct synth_parser : boost::spirit::x3::parser<synth_parser<T>>
  18. {
  19. typedef T attribute_type;
  20. static bool const has_attribute = true;
  21. static bool const handles_container = false;
  22. template <typename Iterator, typename Context,
  23. typename RuleContext, typename Attribute>
  24. bool parse(Iterator& iter, Iterator const& last, Context const&,
  25. RuleContext&, Attribute& attr) const
  26. {
  27. if (iter != last && *iter == 's') {
  28. ++iter;
  29. boost::spirit::x3::traits::move_to(attribute_type{}, attr);
  30. return true;
  31. }
  32. return false;
  33. }
  34. };
  35. template <typename T>
  36. synth_parser<T> synth{};
  37. synth_parser<move_only> const synth_move_only{};
  38. #endif