/*============================================================================= Copyright (c) 2001-2015 Joel de Guzman Copyright (c) 2025 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) =============================================================================*/ #include "test.hpp" #include #include #include #include #include #include #include TEST_CASE("rule1") { using namespace x4::standard; using x4::rule; using x4::lit; using x4::int_; using x4::phrase_parse; using x4::root_skipper_flag; #ifdef BOOST_SPIRIT_X4_NO_RTTI BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(rule{}); #endif BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(rule{"r"}); BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(rule{"r"} = 'x'); // check attribute advertising static_assert( x4::has_attribute_v>); static_assert(!x4::has_attribute_v>); static_assert( x4::has_attribute_v{} = int_)>); static_assert(!x4::has_attribute_v{} = int_)>); { // basic tests constexpr auto a = lit('a'); constexpr auto b = lit('b'); constexpr auto c = lit('c'); constexpr rule r("rule"); CHECK(parse("abcabcacb", *(a | b | c))); { constexpr auto start = r = (a | b) >> (r | b); CHECK(parse("aaaabababaaabbb", start)); CHECK(parse("aaaabababaaabba", start).is_partial_match()); // ignore the skipper! CHECK(parse("aaaabababaaabba", start, space).is_partial_match()); } } { // basic tests w/ skipper constexpr auto a = lit('a'); constexpr auto b = lit('b'); constexpr auto c = lit('c'); constexpr rule r("rule"); CHECK(parse(" a b c a b c a c b ", *(a | b | c), space)); { constexpr auto start = r = (a | b) >> (r | b); CHECK(parse(" a a a a b a b a b a a a b b b ", start, space)); CHECK(parse(" a a a a b a b a b a a a b b a ", start, space).is_partial_match()); } } { // basic tests w/ skipper but no final post-skip constexpr auto a = rule("a") = lit('a'); constexpr auto b = rule("b") = lit('b'); constexpr auto c = rule("c") = lit('c'); { constexpr auto start = rule("start") = *(a | b) >> c; auto const res = parse(" a b a a b b a c ... ", start, space, root_skipper_flag::dont_post_skip); REQUIRE(res.ok); CHECK(res.remainder.size() == 5); } { constexpr rule start("start"); constexpr auto p = start = (a | b) >> (start | c); CHECK(parse(" a a a a b a b a b a a a b b b c ", p, space, root_skipper_flag::do_post_skip)); { auto const res = parse(" a a a a b a b a b a a a b b b c ", p, space, root_skipper_flag::dont_post_skip); REQUIRE(res.ok); CHECK(res.remainder.size() == 1); } } } }