I am using Parsec with a custom Stream type. This stream is essentially a String , but sometimes it extends the input that it finds in a string to other strings (I think the alias extension). For example, given "Β§4.1 ΒΆ3", it can pass "Section 4.1, paragraph 3" to the parser.
Everything works. My types look like this:
data DealiasingStream = ... instance (Monad m) => Stream DealiasingStream m Char where ... type ShellParser = Parsec DealiasingStream ()
Note that the dependent type of DealiasingStream is just Char . This allows my parsers (well, my ShellParser use all standard character parsers.
My question is to get Parsec to report positions in terms of the original input to my stream. The documentation for Stream states:
A Stream instance is responsible for maintaining the "position in the stream" in the state of stream s . This is trivial unless you use the monad in a non-trivial way.
In fact, my stream type knows what position it wants to report at any moment ... but I donβt understand how to get Parsec to use it! Parsec seems to support its own SourcePos as part of its internal State . And that seems to be being updated by various token primitives and therefore standard Char parsers, out of my control.
How can I do that?
source share