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