Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Parsec's left input

Tags:

haskell

parsec

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

like image 780
chamini2 Avatar asked Sep 27 '15 23:09

chamini2


2 Answers

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.

like image 194
Mark Karpov Avatar answered Nov 12 '22 15:11

Mark Karpov


You can use getInput, which is a parser that returns the remaining input.

like image 1
Daniel Wagner Avatar answered Nov 12 '22 15:11

Daniel Wagner