From 385a9c3f06dbba5a22676fb678e4b44eb8ff5e0c Mon Sep 17 00:00:00 2001 From: Nana Sakisaka <1901813+saki7@users.noreply.github.com> Date: Sat, 13 Sep 2025 08:56:56 +0900 Subject: [PATCH] Revert "Merge pull request #820 from saki7/modernize-expect" This reverts commit 70f968ef6cda4295d65421068457eef3b4308882, reversing changes made to b6acdc57d36615393c0528e6b0b5adb32058f7d2. --- .../boost/spirit/home/x3/directive/expect.hpp | 88 ++++++++----------- test/x3/expect.ipp | 13 ++- 2 files changed, 40 insertions(+), 61 deletions(-) diff --git a/include/boost/spirit/home/x3/directive/expect.hpp b/include/boost/spirit/home/x3/directive/expect.hpp index b96103792..c0f8ecb6f 100644 --- a/include/boost/spirit/home/x3/directive/expect.hpp +++ b/include/boost/spirit/home/x3/directive/expect.hpp @@ -1,7 +1,7 @@ /*============================================================================= Copyright (c) 2001-2014 Joel de Guzman Copyright (c) 2017 wanghan02 - Copyright (c) 2024-2025 Nana Sakisaka + Copyright (c) 2024 Nana Sakisaka Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -14,30 +14,21 @@ #include #include -#include -#include -#include - -namespace boost::spirit::x3 +namespace boost { namespace spirit { namespace x3 { template struct expect_directive : unary_parser> { - using base_type = unary_parser>; - static constexpr bool is_pass_through_unary = true; + typedef unary_parser > base_type; + static bool const is_pass_through_unary = true; - template - requires std::is_constructible_v - constexpr expect_directive(SubjectT&& subject) - noexcept(std::is_nothrow_constructible_v) - : base_type(std::forward(subject)) - {} + constexpr expect_directive(Subject const& subject) + : base_type(subject) {} - template Se, typename Context, typename RContext, typename Attribute> - [[nodiscard]] constexpr bool - parse( - It& first, Se const& last, Context const& context, RContext& rcontext, Attribute& attr - ) const // never noexcept; expectation failure requires construction of debug information + template + bool parse(Iterator& first, Iterator const& last + , Context const& context, RContext& rcontext, Attribute& attr) const { bool const r = this->subject.parse(first, last, context, rcontext, attr); @@ -45,12 +36,12 @@ namespace boost::spirit::x3 { #if BOOST_SPIRIT_X3_THROW_EXPECTATION_FAILURE boost::throw_exception( - expectation_failure( - first, x3::what(this->subject))); + expectation_failure( + first, what(this->subject))); #else - if (!x3::has_expectation_failure(context)) + if (!has_expectation_failure(context)) { - x3::set_expectation_failure(first, this->subject, context); + set_expectation_failure(first, this->subject, context); } #endif } @@ -58,59 +49,50 @@ namespace boost::spirit::x3 } }; - namespace detail + struct expect_gen { - struct expect_gen + template + constexpr expect_directive::value_type> + operator[](Subject const& subject) const { - template - [[nodiscard]] constexpr expect_directive> - operator[](Subject&& subject) const - noexcept(is_parser_nothrow_constructible_v>, Subject>) - { - return { as_parser(std::forward(subject)) }; - } - }; - } // detail + return { as_parser(subject) }; + } + }; - inline namespace cpos - { - inline constexpr detail::expect_gen expect{}; - } // cpos + constexpr auto expect = expect_gen{}; +}}} -} // boost::spirit::x3 - -namespace boost::spirit::x3::detail +namespace boost { namespace spirit { namespace x3 { namespace detail { // Special case handling for expect expressions. template struct parse_into_container_impl, Context, RContext> { - template Se, typename Attribute> - [[nodiscard]] static constexpr bool - call( - expect_directive const& parser, - It& first, Se const& last, Context const& context, RContext& rcontext, Attribute& attr - ) // never noexcept; expectation failure requires construction of debug information + template + static bool call( + expect_directive const& parser + , Iterator& first, Iterator const& last + , Context const& context, RContext& rcontext, Attribute& attr) { - bool const r = detail::parse_into_container( + bool const r = parse_into_container( parser.subject, first, last, context, rcontext, attr); if (!r) { #if BOOST_SPIRIT_X3_THROW_EXPECTATION_FAILURE boost::throw_exception( - expectation_failure( - first, x3::what(parser.subject))); + expectation_failure( + first, what(parser.subject))); #else - if (!x3::has_expectation_failure(context)) + if (!has_expectation_failure(context)) { - x3::set_expectation_failure(first, parser.subject, context); + set_expectation_failure(first, parser.subject, context); } #endif } return r; } }; -} // boost::spirit::x3::detail +}}}} #endif diff --git a/test/x3/expect.ipp b/test/x3/expect.ipp index ad1b9219f..72fc28b95 100644 --- a/test/x3/expect.ipp +++ b/test/x3/expect.ipp @@ -1,14 +1,11 @@ /*============================================================================= Copyright (c) 2001-2013 Joel de Guzman Copyright (c) 2017 wanghan02 - Copyright (c) 2024-2025 Nana Sakisaka + Copyright (c) 2024 Nana Sakisaka Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ -#define BOOST_SPIRIT_X3_USE_BOOST_OPTIONAL 0 -#define BOOST_SPIRIT_X3_NO_BOOST_ITERATOR_RANGE - #include #include #include @@ -265,10 +262,10 @@ int TEST_MAIN_FUNC() using x3::eps; using x3::eoi; using x3::eol; - //using x3::attr; + using x3::attr; using x3::dword; using x3::int_; - using x3::shared_symbols; + using x3::symbols; using x3::confix; using x3::with; using x3::expectation_failure; @@ -491,7 +488,7 @@ int TEST_MAIN_FUNC() }); int n = 0; - TEST_ATTR_SUCCESS_PASS("abc", lit("abc") > x3::attr(12) > eoi, n); + TEST_ATTR_SUCCESS_PASS("abc", lit("abc") > attr(12) > eoi, n); BOOST_TEST(n == 12); } @@ -512,7 +509,7 @@ int TEST_MAIN_FUNC() BOOST_TEST(x.where() == "a"sv); }); - shared_symbols<> s; + symbols<> s; s.add("cat"); TEST_SUCCESS_PASS("12cat", +digit > s); TEST_FAILURE("12dog", +digit > s, {