Reputation: 164
I want to make a parser combinator for regular expressions in Haskell. So I defined my own data type and made a match function for this type. I recently discovered about Text.ParserCombinators. If I use parseTest
function the result type is IO
. So how do I use Text.ParserCombinators to return the type of my created data? Below is my code.
data Reg = Eps
|Sym Char --caracter
|Alt Reg Reg --a sau b a|b
|Seq Reg Reg -- secventa ab sau chiar paranteza
|Rep (Int, Maybe Int) Reg --Star repet on or more time
|Dif Reg --not
deriving (Show)
--match function
accept :: Reg -> String ->Bool
accept ( parse term "abcd") "abcd"
ERROR - Type error in application
*** Expression : accept (parse term "abcd") "abcd"
*** Term : parse term "abcd"
*** Type : [Char] -> Either ParseError Reg
*** Does not match : Reg
--term is the Parser function where the grammars is defined
term :: Parser Reg
term = buildExpressionParser ops atom where
Upvotes: 0
Views: 189
Reputation: 38901
As sdcvvc notes in the comments, parse
isn't applied to enough arguments.
Upvotes: 1