Boost 语义动作中的异常处理
考虑以下解析器:Boost 语义动作中的异常处理,boost,boost-spirit,boost-spirit-qi,Boost,Boost Spirit,Boost Spirit Qi,考虑以下解析器: class test { public: static test from_string(const string &str); //throws! }; template <typename Iterator = string::const_iterator> struct test_parser : grammar<Iterator, test(), blank_type> { test_parser() : test_parser
class test
{
public:
static test from_string(const string &str); //throws!
};
template <typename Iterator = string::const_iterator>
struct test_parser : grammar<Iterator, test(), blank_type>
{
test_parser() : test_parser::base_type(query)
{
query = id[_val = phx::bind(&test::from_string, qi::_1)];
id = lexeme[*char_("a-zA-Z_0-9")];
}
rule<Iterator, test(), blank_type> query;
rule<Iterator, string(), blank_type> id;
};
正如评论员所说,使用
query = id[
phx::try_ [
qi::_val = phx::bind(&test::from_string, qi::_1)
].catch_all [
qi::_pass = false
]
];
查看它
query = id[
phx::try_ [
qi::_val = phx::bind(&test::from_string, qi::_1)
].catch_all [
qi::_pass = false
],
qi::_pass = qi::_pass // to appease the spirit expression compilation gods
];
即使使用了BOOST\u SPIRIT\u USE\u PHOENIX\u V3也可以编译的版本
:
query = id[
phx::try_ [
qi::_val = phx::bind(&test::from_string, qi::_1)
].catch_all [
qi::_pass = false
],
qi::_pass = qi::_pass // to appease the spirit expression compilation gods
];
正如您在中所看到的,您需要使用
boost::fusion::at_c(context.attributes)=t代码>。我认为另一个可行的方法是使用query=id[phx::try][u val=phx::bind(&test::from_string,qi::_1)]
。phx::try_[]。catch_all[]
替代方案似乎只适用于phoenix v2。@cv_和_他可能。。。我们应该考虑在这里归档bug。我不明白为什么它不起作用,really@sehe如果你把try\u catch
放在一个序列中,例如添加std::cout@cv\u和他做得很好,我在我的答案中添加了一个变通方法。你愿意在名单上报告这件事吗?这可能只是try\u catch
表达式模板缺少的一个“语句”特性,我想我已经迁移到V3了,结果发现上面的解决方法不起作用:语义操作根本没有被调用。@IgorR。您是否忘记包含相关标题?听起来像是一个标准的逗号运算符行为(也称为coma运算符)