c++boostboost-spiritboost-spirit-x3

The Problem of Boost Spirit AST Recursive Dependency


**

It's strange that the following error occurred during compilation. Can anyone tell me why。

As there are still many errors, I don't know if it was caused by this error。Due to the deep recursion, I am unable to paste all the code

**

namespace  test {

struct last;
struct pre{
    std::vector<char> cs;
    double first;
    std::vector<x3::forward_ast<last>> second;
};
struct last : x3::variant<boost::recursive_wrapper<pre>,intmax_t>{
    using base_type::base_type;
    using base_type::operator=;
};

}

BOOST_FUSION_ADAPT_STRUCT(test::pre,cs,first,second);

test code:

 std::string input = R"(
    123,xxxxxx|456.00,45645,ffffffff|33.22
)";


std::vector<test::last> out;
bool r = x3::phrase_parse(input.begin(), input.end(),  ((*x3::char_ >> '|' >> x3::double_) | x3::int_) % ',', x3::ascii::space, out);
if(r && (g_iter == g_end)){
    std::cout << "parse success!" << std::endl;
}else{
    std::cerr << "parse fail!" << std::endl;
}

compile error log:

I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/support/ast/variant.hpp(184): error C2679: 二元“=”: 没有找到接受“_Ty”类型的右操作数的运算符(或没有可接受的转换)
        with
        [
            _Ty=boost::fusion::deque<std::basic_string<char,std::char_traits<char>,std::allocator<char>>,double>
        ]
I:\boost_1_83_0\build\debug\include\boost/variant/variant.hpp(2172): note: 可能是“boost::variant<boost::recursive_wrapper<test::pre>,intmax_t> &boost::variant<boost::recursive_wrapper<test::pre>,intmax_t>::operator =(boost::variant<boost::recursive_wrapper<test::pre>,intmax_t> &&) noexcept(false)”
I:\boost_1_83_0\build\debug\include\boost/variant/variant.hpp(2165): note: 或    “boost::variant<boost::recursive_wrapper<test::pre>,intmax_t> &boost::variant<boost::recursive_wrapper<test::pre>,intmax_t>::operator =(const boost::variant<boost::recursive_wrapper<test::pre>,intmax_t> &)”
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/support/ast/variant.hpp(183): note: 尝试匹配参数列表“(boost::variant<boost::recursive_wrapper<test::pre>,intmax_t>, _Ty)”时
        with
        [
            _Ty=boost::fusion::deque<std::basic_string<char,std::char_traits<char>,std::allocator<char>>,double>
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/support/traits/move_to.hpp(115): note: 查看对正在编译的函数 模板 实例化“boost::spirit::x3::variant<boost::recursive_wrapper<test::pre>,intmax_t> &boost::spirit::x3::variant<boost::recursive_wrapper<test::pre>,intmax_t>::operator =<boost::fusion::deque<Attribute,double>,void>(T &&) noexcept(false)”的引用
        with
        [
            Attribute=std::basic_string<char,std::char_traits<char>,std::allocator<char>>,
            T=boost::fusion::deque<std::basic_string<char,std::char_traits<char>,std::allocator<char>>,double>
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/support/traits/move_to.hpp(115): note: 查看对正在编译的函数 模板 实例化“boost::spirit::x3::variant<boost::recursive_wrapper<test::pre>,intmax_t> &boost::spirit::x3::variant<boost::recursive_wrapper<test::pre>,intmax_t>::operator =<boost::fusion::deque<Attribute,double>,void>(T &&) noexcept(false)”的引用
        with
        [
            Attribute=std::basic_string<char,std::char_traits<char>,std::allocator<char>>,
            T=boost::fusion::deque<std::basic_string<char,std::char_traits<char>,std::allocator<char>>,double>
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/support/traits/move_to.hpp(152): note: 查看对正在编译的函数 模板 实例化“void boost::spirit::x3::traits::detail::move_to<Source,Dest>(Source &,Dest &,boost::spirit::x3::traits::variant_attribute,boost::mpl::false_)”的引用
        with
        [
            Source=boost::fusion::deque<std::basic_string<char,std::char_traits<char>,std::allocator<char>>,double>,
            Dest=value_type
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/support/traits/move_to.hpp(196): note: 查看对正在编译的函数 模板 实例化“void boost::spirit::x3::traits::detail::move_to<T1,Dest>(Source &,Dest &,boost::spirit::x3::traits::variant_attribute)”的引用
        with
        [
            T1=boost::fusion::deque<std::basic_string<char,std::char_traits<char>,std::allocator<char>>,double>,
            Dest=value_type,
            Source=boost::fusion::deque<std::basic_string<char,std::char_traits<char>,std::allocator<char>>,double>
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/operator/detail/alternative.hpp(175): note: 查看对正在编译的函数 模板 实例化“void boost::spirit::x3::traits::move_to<T1&,T2>(Source,Dest &)”的引用     
        with
        [
            T1=boost::fusion::deque<std::basic_string<char,std::char_traits<char>,std::allocator<char>>,double>,
            T2=value_type,
            Source=boost::fusion::deque<std::basic_string<char,std::char_traits<char>,std::allocator<char>>,double> &,
            Dest=value_type
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/operator/detail/alternative.hpp(191): note: 查看对正在编译的函数 模板 实例化“void boost::spirit::x3::detail::move_if<true>::call<boost::fusion::deque<Attribute,double>,test::last>(T1 &,T2 &)”的引用
        with
        [
            Attribute=std::basic_string<char,std::char_traits<char>,std::allocator<char>>,
            T1=boost::fusion::deque<std::basic_string<char,std::char_traits<char>,std::allocator<char>>,double>,
            T2=value_type
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/operator/detail/alternative.hpp(209): note: 查看对正在编译的函数 模板 实例化“bool boost::spirit::x3::detail::parse_alternative<Subject,Iterator,Context,RContext,Attribute>(const Parser &,Iterator &,const Iterator &,const Context &,RContext &,Attribute &)”的引用
        with
        [
            Subject=boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>,
            Iterator=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,
            Context=boost::spirit::x3::context<boost::spirit::x3::skipper_tag,const boost::spirit::x3::ascii::space_type,boost::spirit::x3::unused_type>,
            RContext=const boost::spirit::x3::unused_type,
            Attribute=value_type,
            Parser=boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/core/detail/parse_into_container.hpp(97): note: 查看对正在编译的函数 模板 实例化“bool boost::spirit::x3::detail::alternative_helper<Left>::parse<Iterator,Context,RContext,value_type>(Iterator &,const Iterator &,const Context &,RContext &,Attribute &) const”的引用
        with
        [
            Left=boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>,
            Iterator=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,
            Context=boost::spirit::x3::context<boost::spirit::x3::skipper_tag,const boost::spirit::x3::ascii::space_type,boost::spirit::x3::unused_type>,
            RContext=const boost::spirit::x3::unused_type,
            Attribute=value_type
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/core/detail/parse_into_container.hpp(97): note: 查看对正在编译的函数 模板 实例化“bool boost::spirit::x3::detail::alternative_helper<Left>::parse<Iterator,Context,RContext,value_type>(Iterator &,const Iterator &,const Context &,RContext &,Attribute &) const”的引用
        with
        [
            Left=boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>,
            Iterator=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,
            Context=boost::spirit::x3::context<boost::spirit::x3::skipper_tag,const boost::spirit::x3::ascii::space_type,boost::spirit::x3::unused_type>,
            RContext=const boost::spirit::x3::unused_type,
            Attribute=value_type
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/core/detail/parse_into_container.hpp(129): note: 查看对正在编译的函数 模板 实例化“bool boost::spirit::x3::detail::parse_into_container_base_impl<Parser>::call_synthesize_x<Iterator,Context,RContext,Attribute>(const Parser &,Iterator &,const Iterator &,const Context &,RContext &,Attribute &,boost::mpl::false_)”的引用
        with
        [
            Parser=boost::spirit::x3::detail::alternative_helper<boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>>,
            Iterator=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,
            Context=boost::spirit::x3::context<boost::spirit::x3::skipper_tag,const boost::spirit::x3::ascii::space_type,boost::spirit::x3::unused_type>,
            RContext=const boost::spirit::x3::unused_type,
            Attribute=std::vector<test::last,std::allocator<test::last>>
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/core/detail/parse_into_container.hpp(128): note: 查看对正在编译的函数 模板 实例化“bool boost::spirit::x3::detail::parse_into_container_base_impl<Parser>::call_synthesize_x<Iterator,Context,RContext,Attribute>(const Parser &,Iterator &,const Iterator &,const Context &,RContext &,Attribute &,boost::mpl::false_)”的引用
        with
        [
            Parser=boost::spirit::x3::detail::alternative_helper<boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>>,
            Iterator=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,
            Context=boost::spirit::x3::context<boost::spirit::x3::skipper_tag,const boost::spirit::x3::ascii::space_type,boost::spirit::x3::unused_type>,
            RContext=const boost::spirit::x3::unused_type,
            Attribute=std::vector<test::last,std::allocator<test::last>>
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/core/detail/parse_into_container.hpp(183): note: 查看对正在编译的函数 模板 实例化“bool boost::spirit::x3::detail::parse_into_container_base_impl<Parser>::call_synthesize<Iterator,Context,RContext,Attribute>(const Parser &,Iterator &,const Iterator &,const Context &,RContext &,Attribute &)”的引用
        with
        [
            Parser=boost::spirit::x3::detail::alternative_helper<boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>>,
            Iterator=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,
            Context=boost::spirit::x3::context<boost::spirit::x3::skipper_tag,const boost::spirit::x3::ascii::space_type,boost::spirit::x3::unused_type>,
            RContext=const boost::spirit::x3::unused_type,
            Attribute=std::vector<test::last,std::allocator<test::last>>
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/core/detail/parse_into_container.hpp(183): note: 查看对正在编译的函数 模板 实例化“bool boost::spirit::x3::detail::parse_into_container_base_impl<Parser>::call_synthesize<Iterator,Context,RContext,Attribute>(const Parser &,Iterator &,const Iterator &,const Context &,RContext &,Attribute &)”的引用
        with
        [
            Parser=boost::spirit::x3::detail::alternative_helper<boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>>,
            Iterator=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,
            Context=boost::spirit::x3::context<boost::spirit::x3::skipper_tag,const boost::spirit::x3::ascii::space_type,boost::spirit::x3::unused_type>,
            RContext=const boost::spirit::x3::unused_type,
            Attribute=std::vector<test::last,std::allocator<test::last>>
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/core/detail/parse_into_container.hpp(193): note: 查看对正在编译的函数 模板 实例化“bool boost::spirit::x3::detail::parse_into_container_base_impl<Parser>::call_synthesize_dispatch_by_seq<Iterator,Context,RContext,Attribute>(const Parser &,Iterator &,const Iterator &,const Context &,RContext &,Attribute &,boost::mpl::false_)”的引用
        with
        [
            Parser=boost::spirit::x3::detail::alternative_helper<boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>>,
            Iterator=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,
            Context=boost::spirit::x3::context<boost::spirit::x3::skipper_tag,const boost::spirit::x3::ascii::space_type,boost::spirit::x3::unused_type>,
            RContext=const boost::spirit::x3::unused_type,
            Attribute=std::vector<test::last,std::allocator<test::last>>
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/core/detail/parse_into_container.hpp(192): note: 查看对正在编译的函数 模板 实例化“bool boost::spirit::x3::detail::parse_into_container_base_impl<Parser>::call_synthesize_dispatch_by_seq<Iterator,Context,RContext,Attribute>(const Parser &,Iterator &,const Iterator &,const Context &,RContext &,Attribute &,boost::mpl::false_)”的引用
        with
        [
            Parser=boost::spirit::x3::detail::alternative_helper<boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>>,
            Iterator=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,
            Context=boost::spirit::x3::context<boost::spirit::x3::skipper_tag,const boost::spirit::x3::ascii::space_type,boost::spirit::x3::unused_type>,
            RContext=const boost::spirit::x3::unused_type,
            Attribute=std::vector<test::last,std::allocator<test::last>>
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/core/detail/parse_into_container.hpp(215): note: 查看对正在编译的函数 模板 实例化“bool boost::spirit::x3::detail::parse_into_container_base_impl<Parser>::call<Iterator,Context,RContext,Attribute>(const Parser &,Iterator &,const Iterator &,const Context &,RContext &,Attribute &,boost::mpl::true_)”的引用
        with
        [
            Parser=boost::spirit::x3::detail::alternative_helper<boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>>,
            Iterator=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,
            Context=boost::spirit::x3::context<boost::spirit::x3::skipper_tag,const boost::spirit::x3::ascii::space_type,boost::spirit::x3::unused_type>,
            RContext=const boost::spirit::x3::unused_type,
            Attribute=std::vector<test::last,std::allocator<test::last>>
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/core/detail/parse_into_container.hpp(214): note: 查看对正在编译的函数 模板 实例化“bool boost::spirit::x3::detail::parse_into_container_base_impl<Parser>::call<Iterator,Context,RContext,Attribute>(const Parser &,Iterator &,const Iterator &,const Context &,RContext &,Attribute &,boost::mpl::true_)”的引用
        with
        [
            Parser=boost::spirit::x3::detail::alternative_helper<boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>>,
            Iterator=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,
            Context=boost::spirit::x3::context<boost::spirit::x3::skipper_tag,const boost::spirit::x3::ascii::space_type,boost::spirit::x3::unused_type>,
            RContext=const boost::spirit::x3::unused_type,
            Attribute=std::vector<test::last,std::allocator<test::last>>
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/core/detail/parse_into_container.hpp(304): note: 查看对正在编译的函数 模板 实例化“bool boost::spirit::x3::detail::parse_into_container_base_impl<Parser>::call<Iterator,Context,RContext,Attribute>(const Parser &,Iterator &,const Iterator &,const Context &,RContext &,Attribute &)”的引用
        with
        [
            Parser=boost::spirit::x3::detail::alternative_helper<boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>>,
            Iterator=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,
            Context=boost::spirit::x3::context<boost::spirit::x3::skipper_tag,const boost::spirit::x3::ascii::space_type,boost::spirit::x3::unused_type>,
            RContext=const boost::spirit::x3::unused_type,
            Attribute=std::vector<test::last,std::allocator<test::last>>
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/core/detail/parse_into_container.hpp(303): note: 查看对正在编译的函数 模板 实例化“bool boost::spirit::x3::detail::parse_into_container_base_impl<Parser>::call<Iterator,Context,RContext,Attribute>(const Parser &,Iterator &,const Iterator &,const Context &,RContext &,Attribute &)”的引用
        with
        [
            Parser=boost::spirit::x3::detail::alternative_helper<boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>>,
            Iterator=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,
            Context=boost::spirit::x3::context<boost::spirit::x3::skipper_tag,const boost::spirit::x3::ascii::space_type,boost::spirit::x3::unused_type>,
            RContext=const boost::spirit::x3::unused_type,
            Attribute=std::vector<test::last,std::allocator<test::last>>
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/operator/detail/alternative.hpp(234): note: 查看对正在编译的函数 模板 实例化“bool boost::spirit::x3::detail::parse_into_container<boost::spirit::x3::detail::alternative_helper<Left>,Iterator,Context,RContext,Attribute>(const Parser &,Iterator &,const Iterator &,const Context &,RContext &,Attribute &)”的引用
        with
        [
            Left=boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>,
            Iterator=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,
            Context=boost::spirit::x3::context<boost::spirit::x3::skipper_tag,const boost::spirit::x3::ascii::space_type,boost::spirit::x3::unused_type>,
            RContext=const boost::spirit::x3::unused_type,
            Attribute=std::vector<test::last,std::allocator<test::last>>,
            Parser=boost::spirit::x3::detail::alternative_helper<boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>>
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/operator/detail/alternative.hpp(245): note: 查看对正在编译的函数 模板 实例化“bool boost::spirit::x3::detail::parse_into_container_impl<Parser,Context,RContext,void>::call<Iterator,Attribute>(const boost::spirit::x3::alternative<Derived,boost::spirit::x3::int_parser<int,10,1,-1>> &,Iterator &,const Iterator &,const Context &,RContext &,Attribute &,boost::mpl::true_)”的引用
        with
        [
            Parser=boost::spirit::x3::alternative<boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>,boost::spirit::x3::int_type>,
            Context=boost::spirit::x3::context<boost::spirit::x3::skipper_tag,const boost::spirit::x3::ascii::space_type,boost::spirit::x3::unused_type>,
            RContext=const boost::spirit::x3::unused_type,
            Iterator=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,
            Attribute=std::vector<test::last,std::allocator<test::last>>,
            Derived=boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/operator/detail/alternative.hpp(244): note: 查看对正在编译的函数 模板 实例化“bool boost::spirit::x3::detail::parse_into_container_impl<Parser,Context,RContext,void>::call<Iterator,Attribute>(const boost::spirit::x3::alternative<Derived,boost::spirit::x3::int_parser<int,10,1,-1>> &,Iterator &,const Iterator &,const Context &,RContext &,Attribute &,boost::mpl::true_)”的引用
        with
        [
            Parser=boost::spirit::x3::alternative<boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>,boost::spirit::x3::int_type>,
            Context=boost::spirit::x3::context<boost::spirit::x3::skipper_tag,const boost::spirit::x3::ascii::space_type,boost::spirit::x3::unused_type>,
            RContext=const boost::spirit::x3::unused_type,
            Iterator=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,
            Attribute=std::vector<test::last,std::allocator<test::last>>,
            Derived=boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/core/detail/parse_into_container.hpp(304): note: 查看对正在编译的函数 模板 实例化“bool boost::spirit::x3::detail::parse_into_container_impl<Parser,Context,RContext,void>::call<Iterator,Attribute>(const boost::spirit::x3::alternative<Derived,boost::spirit::x3::int_parser<int,10,1,-1>> &,Iterator &,const Iterator &,const Context &,RContext &,Attribute &)”的引
用
        with
        [
            Parser=boost::spirit::x3::alternative<boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>,boost::spirit::x3::int_type>,
            Context=boost::spirit::x3::context<boost::spirit::x3::skipper_tag,const boost::spirit::x3::ascii::space_type,boost::spirit::x3::unused_type>,
            RContext=const boost::spirit::x3::unused_type,
            Iterator=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,
            Attribute=std::vector<test::last,std::allocator<test::last>>,
            Derived=boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/core/detail/parse_into_container.hpp(303): note: 查看对正在编译的函数 模板 实例化“bool boost::spirit::x3::detail::parse_into_container_impl<Parser,Context,RContext,void>::call<Iterator,Attribute>(const boost::spirit::x3::alternative<Derived,boost::spirit::x3::int_parser<int,10,1,-1>> &,Iterator &,const Iterator &,const Context &,RContext &,Attribute &)”的引
用
        with
        [
            Parser=boost::spirit::x3::alternative<boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>,boost::spirit::x3::int_type>,
            Context=boost::spirit::x3::context<boost::spirit::x3::skipper_tag,const boost::spirit::x3::ascii::space_type,boost::spirit::x3::unused_type>,
            RContext=const boost::spirit::x3::unused_type,
            Iterator=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,
            Attribute=std::vector<test::last,std::allocator<test::last>>,
            Derived=boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/operator/list.hpp(34): note: 查看对正在编译的函数 模板 实例化“bool boost::spirit::x3::detail::parse_into_container<Left,Iterator,Context,RContext,Attribute>(const Parser &,Iterator &,const Iterator &,const Context &,RContext &,Attribute &)”的引用
        with
        [
            Left=boost::spirit::x3::alternative<boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>,boost::spirit::x3::int_type>,
            Iterator=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,
            Context=boost::spirit::x3::context<boost::spirit::x3::skipper_tag,const boost::spirit::x3::ascii::space_type,boost::spirit::x3::unused_type>,
            RContext=const boost::spirit::x3::unused_type,
            Attribute=std::vector<test::last,std::allocator<test::last>>,
            Parser=boost::spirit::x3::alternative<boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>,boost::spirit::x3::int_type>
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/core/parse.hpp(119): note: 查看对正在编译的函数 模板 实例化“bool boost::spirit::x3::list<Derived,boost::spirit::x3::extension::as_parser<char,void>::type>::parse<Iterator,boost::spirit::x3::context<boost::spirit::x3::skipper_tag,const boost::spirit::x3::char_class<boost::spirit::char_encoding::ascii,boost::spirit::x3::space_tag>,boost::spirit::x3::unused_type>,const boost::spirit::x3::unused_type,Attribute>(Iterator &,const Iterator &,const Context &,RContext &,Attribute &) const”的引用
        with
        [
            Derived=boost::spirit::x3::alternative<boost::spirit::x3::sequence<boost::spirit::x3::sequence<boost::spirit::x3::kleene<boost::spirit::x3::standard::char_type>,boost::spirit::x3::extension::as_parser<char,void>::type>,boost::spirit::x3::double_type>,boost::spirit::x3::int_type>,
            Iterator=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,
            Attribute=std::vector<test::last,std::allocator<test::last>>,
            Context=boost::spirit::x3::context<boost::spirit::x3::skipper_tag,const boost::spirit::x3::ascii::space_type,boost::spirit::x3::unused_type>,
            RContext=const boost::spirit::x3::unused_type
        ]
I:\boost_1_83_0\build\debug\include\boost/spirit/home/x3/core/parse.hpp(119): note: 查看对正在编译的函数 模板 实例化“bool
            
 

**

Who can point out where the mistake is, or tell me the detailed reason.

I would greatly appreciate it

**

update Even if I modify the following code according to your reply Compilation still reports errors, never before has there been such confusion

namespace  test {

struct last;
struct pre{
    std::vector<char> cs;
    double first;
    std::vector<x3::forward_ast<last>> second;
};
struct last : x3::variant<boost::recursive_wrapper<pre>,intmax_t>{
    using base_type::base_type;
    using base_type::operator=;
};

}
BOOST_FUSION_ADAPT_STRUCT(test::pre,cs,first);


std::string input = R"(
        123,xxxxxx|456.00,45645,ffffffff|33.22
    )";


    std::vector<test::last> out;
    bool r = x3::phrase_parse(input.begin(), input.end(),  (( (!x3::int_ >> *~x3::char_("|")) >> '|' >> x3::double_) | x3::int_) % ',' >> x3::eoi, x3::ascii::space, out);
    if(r && (g_iter == g_end)){
        std::cout << "parse success!" << std::endl;
    }else{
        std::cerr << "parse fail!" << std::endl;
    }

Solution

  • It's unclear to me what you wanted to parse.

    I commented out second and fixed up the rules to avoid the problems listed above. As always, being specific helps:

    auto pre = x3::rule<struct pre, AST::pre>{"pre"} = //
        (*~x3::char_("|") >> '|' >> x3::double_);
    auto last = x3::rule<struct last, AST::last>{"last"} = //
        !x3::int_ >> pre | x3::int_;
    

    Now you can parse with

    bool r = phrase_parse(          //
        input.begin(), input.end(), //
        last % ',' >> x3::eoi,      //
        x3::space, out);
    

    Live Demo

    Live On Coliru

    #define BOOST_SPIRIT_X3_DEBUG
    #include <boost/fusion/adapted.hpp>
    #include <boost/spirit/home/x3.hpp>
    #include <boost/spirit/home/x3/support/ast/variant.hpp>
    #include <iostream>
    
    namespace x3  = boost::spirit::x3;
    namespace AST {
        struct last;
        struct pre {
            std::vector<char>                  cs;
            double                             first;
            std::vector<x3::forward_ast<last>> second;
        };
        struct last : x3::variant<boost::recursive_wrapper<pre>, intmax_t> {
            using base_type::base_type;
            using base_type::operator=;
        };
    } // namespace AST
    
    BOOST_FUSION_ADAPT_STRUCT(AST::pre, cs, first/*, second*/)
    
    int main() {
        for (std::string const input :
             {
                 R"(123,xxxxxx|456.00,45645,ffffffff|33.22)",
             }) //
        {
    
            std::vector<AST::last> out;
    
            auto pre = x3::rule<struct pre, AST::pre>{"pre"} = //
                (*~x3::char_("|") >> '|' >> x3::double_);
            auto last = x3::rule<struct last, AST::last>{"last"} = //
                !x3::int_ >> pre | x3::int_;
    
            bool r = phrase_parse(          //
                input.begin(), input.end(), //
                last % ',' >> x3::eoi,      //
                x3::space, out);
    
            if (r) {
                std::cout << "parse success!" << std::endl;
            } else {
                std::cerr << "parse fail!" << std::endl;
            }
        }
    }
    

    Prints

    parse success!
    

    With debug output:

    <last>
      <try>123,xxxxxx|456.00,45</try>
      <success>,xxxxxx|456.00,45645</success>
      <attributes>123</attributes>
    </last>
    <last>
      <try>xxxxxx|456.00,45645,</try>
      <pre>
        <try>xxxxxx|456.00,45645,</try>
        <success>,45645,ffffffff|33.2</success>
        <attributes>[[x, x, x, x, x, x], 456]</attributes>
      </pre>
      <success>,45645,ffffffff|33.2</success>
      <attributes>[[x, x, x, x, x, x], 456]</attributes>
    </last>
    <last>
      <try>45645,ffffffff|33.22</try>
      <success>,ffffffff|33.22</success>
      <attributes>45645</attributes>
    </last>
    <last>
      <try>ffffffff|33.22</try>
      <pre>
        <try>ffffffff|33.22</try>
        <success></success>
        <attributes>[[f, f, f, f, f, f, f, f], 33.22]</attributes>
      </pre>
      <success></success>
      <attributes>[[f, f, f, f, f, f, f, f], 33.22]</attributes>
    </last>