我遇到了一个 Boost Spirit Qi 语法问题,它发出了不需要的类型,导致了这个编译错误:
error C2664: 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::insert(unsigned int,const std::basic_string<_Elem,_Traits,_Ax> &)' : cannot convert parameter 1 from 'std::_String_iterator<_Elem,_Traits,_Alloc>' to 'unsigned int'
这是导致问题的语法:
qi::rule<Iterator, qi::unused_type()> gr_newline;
// asmast::label() just contains an identifier struct that is properly emitted from gr_identifier
qi::rule<Iterator, asmast::label(), skipper<Iterator> > gr_label;
gr_newline = +( char_('\r')
|char_('\n')
);
这失败了:
gr_label = gr_identifier
>> ':'
> gr_newline;
但以下所有工作:
// This parses OK
gr_label = gr_identifier
> gr_newline;
// This also parses OK
gr_label = gr_identifier
> ':'
> gr_newline;
// This also parses OK
// **Why does this work when parenthesized?**
gr_label = gr_identifier
>> (':'
> skip_grammar.gr_newline
);
// This also parses OK
gr_label = gr_identifier
>> omit[':'
> gr_newline];
我不明白为什么要删除字符文字或省略 [] 来“解决”问题,但我不希望语法因此而杂乱无章。
根据此处找到的 >> 和 > 的复合属性规则以及此处的字符解析器属性, gr_label 应该只发出 asmast::label
a: A, b: B --> (a >> b): tuple<A, B>
a: A, b: Unused --> (a >> b): A <---- This one here is the one that should match so far as I understand
a: Unused, b: B --> (a >> b): B
a: Unused, b: Unused --> (a >> b): Unused
Expression Attribute
c unused or if c is a Lazy Argument, the character type returned by invoking it.
但是,不知何故,某些东西污染了预期的属性,并导致编译器错误。
所以我的问题是这个语法在哪里发出了不需要的属性,以及如何摆脱它。