I was wondering if there's a way to get te remaining input from Parsec after it stops parsing, either if it was a successful or failed parse, maybe this signature:
parseRemaining :: Stream s Identity t => Parsec s () a -> SourceName -> s -> (s, Either ParseError a)
Where we get instead of an Either ParseError a
, we additionally get the remaining Stream s
Take a look at Megaparsec
— a modern fork of Parsec, beginning from version 4.2.0 it allows to supply
custom state at the beginning of parsing and extract parser state at the end (it
doesn't matter if parser succeeds or fails). This allows to partially parse
input, resume parsing, specify non-standard initial textual position,
etc. See
runParser'
and
runParserT'
.
Disclosure: I'm one of the authors of Megaparsec.
You can use getInput
, which is a parser that returns the remaining input.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With