Parsec question: how to access parser state

Hi, I am trying to develop a parser with the Parsec library. At some point I need to do something with parser state, say, convert it to a string. I declared the type for the parser: type TParser a = GenParser Token (FiniteMap String Declaration) a The FiniteMap (which is the user state) is expected to be updated during parsing whus building some internal lookup table. and in one of the parsing functions I want to call show getState assuming it will apply show to the FiniteMap and return some string of characters. During compliation, I get: No instance for (Show (GenParser tok st st)) arising from use of `show' at (file location) In the first argument of `xxxx', namely `(show getState)' But GenParser is a newtype, not a data constructor, so attempt to write instance Show (GenParser tok st t) results in error message about missing constructor GenParser. How could I extract actual user state from the result of getState? The parser itself works as needed, but dealing with user state gets me in trouble. Dimitry Golubovsky Middletown, CT

On Sun, Mar 20, 2005 at 03:32:38PM -0500, Dimitry Golubovsky wrote:
type TParser a = GenParser Token (FiniteMap String Declaration) a
The FiniteMap (which is the user state) is expected to be updated during parsing whus building some internal lookup table.
and in one of the parsing functions I want to call
show getState
assuming it will apply show to the FiniteMap and return some string of characters.
During compliation, I get:
No instance for (Show (GenParser tok st st)) arising from use of `show' at (file location) In the first argument of `xxxx', namely `(show getState)'
This is a good clue--you don't want to show a parser, you want to show the state. Look at the type of getState and think monadic thoughts. There is in fact an example of its use in the Parsec documentation. Andrew
participants (2)
-
Andrew Pimlott
-
Dimitry Golubovsky