This question is related to both Parsec
and uu-parsinglib
. When we write parser combinators, they process characters streams from compiler. Is it somehow possible to parse a character and put it back (or return another character back) to the input stream?
I want for example to parse input "test + 5", parse the t
, e
, s
, t
and after recognition of test
pattern, put for example v
character back into the character stream, so while continuating the parsing process we are matching against v + 5
I do not want to use this in any particular case for now - I want to deeply learn the possibilities.
This is easily done in uu-parsinglib using the pSwitch function. But the question is why you want to do so? Because the v is missing from the input? In that case uu-parsinglib will perform error correction automatically so you do not need something like this. Otherwise you can write
It depends on your actual state type how the v is actually added, so you will have to define the function
yourself. I do not know e.g. how such an insertion would influence the current position in the file etc.Doaitse Swierstra