I have some problems writing a parser using Spirit :: Qi 2.4. I have a series of key-value pairs for parsing in the following format <key name>=<value> .
The key name can be [a-zA-Z0-9] , and it is always followed by the = sign without a space between the key name and the = sign. The key name must also always contain at least one space.
The value can be almost any C expression (spaces are also possible), with the exception of expressions containing = char and code blocks { } .
At the end of the sequence of key value pairs there is a { .
I am very struggling with writing a parser for this expression. Since the key name is always preceded by at least one space, and then = and does not contain spaces, I defined it as
KeyName %= [+char_("a-zA-Z0-9_") >> lit("=")] ;
The value can be almost anything, but it cannot contain the characters = and { , so I defined it as:
Value %= +(char_ - char_("{=")) ;
I was thinking about using look-ahead, like this, to catch the meaning:
ValueExpression %= ( Value >> *space >> &(KeyName | lit("{")) ) ;
But this will not work, for some reason (it seems that ValueExpression eagerly approaches the = sign and "does not know" what to do from there). I have limited knowledge of LL parsers, so I'm not quite sure what is cooking here. Is there any other way I could handle such a sequence?
Here is a sample series:
EXP1=FunctionCall(A, B, C) TEST="Example String" \ AnotherArg=__FILENAME__ - 'BlahBlah' EXP2= a+ b+* {
Additional information: since this is part of a much larger grammar, I cannot solve this problem other than using the Spirit.Qi parser (for example, splitting into '=' and doing some kind of custom parsing or something like that).
Edit:
I created a minimal working example here: http://ideone.com/kgYD8
(compiled in VS 2012 with an increase of 1.50, but it should be good on the old settings).