I have an issue with a Boost Spirit Qi grammar that is emitting an undesired type, resulting in this compilation error:
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'
Here is the grammar that is causing the issue:
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')
);
This fails:
gr_label = gr_identifier
>> ':'
> gr_newline;
But the following all work:
// 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];
I don't understand why removing the character literal or omit[]ing it "fixes" the problem, but I don't want the grammar to be cluttered with that.
According the the compound attribute rules for >> and > found here, and character parser attributes here, gr_label should only emit 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.
However, somehow something is polluting the intended attribute, and resulting in the compiler error.
So my questions are where this grammar emits an undesired attribute, and how to get rid of it.