提升::精神(经典):|和^之间的区别?

boost::spirit (classic): difference between | and ^?

本文关键字:之间 区别 精神 经典 提升      更新时间:2023-10-16

Doc 说(精神经典(:

a | b, Union, Match a or b. Also referred to as alternative

a ^ b, XOR, Match a or b, but not both.

当它很重要时,谁能给我举个实际的例子?

编辑:请给我实际的例子。创建规则,使用一些Actor,解析一些东西并向我展示差异。我知道OR和XOR是什么,但我看不出提升::精神结果之间有任何区别|和^。

std::string t; boost::spirit::classic::rule<> r = ( ch_p( 'a' ) ^ ch_p( 'b' ) )[ assign_a( t ) ]; //boost::spirit::classic::rule<> r = ( ch_p( 'a' ) | ch_p( 'b' ) )[ assign_a( t ) ]; boost::spirit::classic::parse( "when it matters?", r );

boost::spirit中的运算符^(XOR(创建解析器的"独占或"组合。我没有得到它,因为我将主题放入 str_p/ch_p 解析器中。

感谢我从谁那里得到最好的例子@llonesmiz:

parse( "Z", alpha_p ^ xdigit_p );