Home > Blockchain >  Checking corectness of parsers in Haskell
Checking corectness of parsers in Haskell

Time:12-03

For a uni assignment I need to write parsers in Haskell, right now I have the following parser i think is correct:

parseYear :: Parser Char Year
parseYear = Year <$> ...

I want to check if it works, for example with > parseYear "2004" in ghci. this command is not valid, but i there another way to quickly check if a parser I'm writing is correct?

Edit: Example, for the parser:nesting :: Parser Char Int, this would be what i want enter image description here

CodePudding user response:

From your comment responses, I understand that you're using the uu-tc library, but your Parser type does not come from ParseLib.Simple, because it's not a function.

This means your Parser type must come either from ParseLib.Parallel or from ParseLib.Abstract. Both of those modules define their Parser type as data, and both expose a parse function - here's the one from ParseLib.Abstract and here's the one from ParseLib.Parallel.

Both these parse functions have the same shape: they take a Parser as first parameter and an input list as second. So that's how you would call it:

import ParseLib.(either Parallel or Abstract).Core (parse)

> parse parseYear "2004"
  • Related