Processing Escapes using the Spirit Parser Framework
-
06-09-2019 - |
Question
I'm trying to parse a string similar to the following using a spirit parser:
<junk> -somearg#this is a string with a literal ## in it# <junk>
What I'm looking for is a grammar which can extract the portion inside the # marks, but is smart to skip over the double ## in the middle, which is an escape meaning a literal #.
This was what I had in mind:
confix_p(L'#', *anychar_p, L'#' >> ~ch_p(L'#'))
However this returns:
#this is a string with a literal ##
I'd like it to skip over the ##
characters .... is this possible?
Billy3
Solution
I solved this by adding a kleene star to the confix parser. Thanks anyway!
*confix_p(L'#', *anychar_p, L'#' >> ~ch_p(L'#'))
works as expected.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow