I’m new to boost::spirit. I’ve stumbled over a simple thing. Given a string like this:
Optional text KEYWORD further text
I need to parse it into a string like this:
T KEYWORD further text
where ‘T’ appears only if optional text exists. What I’ve come to was this rule:
start = (+(char_ - "KEYWORD")) [_val += 'T'] | eps
>> "KEYWORD" [_val += _1]
>> *char_ [_val += _1];
But it fails. Could anyone help me, please?
It heavily depends on the target types you are assigning the attributes to, and (to a lesser extent) what the whitespace policy is, i.e. whether your grammar uses a skipper or not.
For now, here’s what I’d write:
Ouput: