除了不祥的暗示之外,我找不到任何关于这方面的信息,这可能是完全不可能的,但我不想简单地相信它,因为在这种情况下,惰性解析器似乎毫无用处。我想要做的是在解析时根据之前的一些非终端的结果选择一个解析器。它本质上可以归结为:
static rule<Constant *(Scope &)> &get_constant_parser(Typename type);
rule<Constant *(Scope &, Typename)> constant {
lazy(phoenix::bind(&get_constant_parser, _r2))(_r1)
};
Run Code Online (Sandbox Code Playgroud)
因此get_constant_parser返回适合给定类型名称的解析器,但是该解析器需要类型的参数Scope &。直观上,我会像上面那样写下来,将参数添加到惰性解析器中。然而,这给了我一个无效的表达式:
/usr/include/boost/spirit/home/qi/nonterminal/rule.hpp:177:13: error: static assertion failed: error_invalid_expression
BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr);
^~~~~~~~~~~~~~~~~~~~~~~~~
Run Code Online (Sandbox Code Playgroud)
那么如何向惰性解析器提供参数呢?如果确实不可能,那么有人知道为什么吗?
抱歉,这不是一个合适的 MWE,现在我希望有人以前做过并且知道答案。如果您想积极调查并需要 MWE,请告诉我;-)
我有一个boost::spirit解析器,它应该简单地分配一个指向其属性的指针:
rule<CompoundExpression *(Scope &)> var_ref = var<CompoundExpression>()(_r1) [
_val = new_<Reference<Variable<CompoundExpression>>>(_1)
];
Run Code Online (Sandbox Code Playgroud)
wherevar<CompoundExpression>()是一个 just 函数,它返回对执行实际解析的静态规则的引用。我Reference<Variable<T>>在整个代码中对模板的其他实例使用相同的赋值操作,这很好,除了使用CompoundExpression参数的那个。
字面 GCC 错误是这样的:
In file included from /usr/include/boost/phoenix/core/actor.hpp:20,
from /usr/include/boost/phoenix/core.hpp:12,
from /usr/include/boost/spirit/include/phoenix_core.hpp:11,
from /usr/include/boost/spirit/home/support/argument.hpp:18,
from /usr/include/boost/spirit/home/qi/nonterminal/rule.hpp:29,
from /usr/include/boost/spirit/home/qi/nonterminal.hpp:14,
from /usr/include/boost/spirit/include/qi_nonterminal.hpp:16,
from /home/ich/sync/ConTrAkt/gologpp/src/parser/utilities.h:7,
from /home/ich/sync/ConTrAkt/gologpp/src/parser/compound_expression.h:4,
from /home/ich/sync/ConTrAkt/gologpp/src/parser/compound_expression.cpp:1:
/usr/include/boost/phoenix/core/is_nullary.hpp: In instantiation of ‘struct boost::phoenix::result_of::is_nullary<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::assign, boost::proto::argsns_::list2<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::spirit::attribute<0> >, 0>, boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::phoenix::tag::new_, boost::proto::argsns_::list2<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::phoenix::detail::target<gologpp::Reference<gologpp::Variable<gologpp::TypedExpression<gologpp::CompoundType> > > > >, 0>, boost::phoenix::actor<boost::spirit::argument<0> > >, 2> > >, 2>, void>’:
/usr/include/boost/phoenix/core/actor.hpp:178:13: required from ‘struct boost::phoenix::result_of::actor<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::assign, …Run Code Online (Sandbox Code Playgroud)