I am trying to parse a Haskell source file into an AST. I'm new to parsers so I'm not sure how to make my own. I was just wondering if there is a function that takes a file and returns an AST. I also thought it might work to turn a file into a string using readFile and then parsing the string, but I still don't know where to go from there. Is there some well-known way to do this? If not, how can I do it myself?
1 Answer
Try Language.Haskell.Meta.Parse. In particular, parseHsModule will parse an entire module for you. There are also functions for parsing smaller chunks, such as parseExp which parses an expression.
haskell-src-extspackage. In particular, theLanguage.Haskell.Exts.Parsermodule contains parsers for many kinds of Haskell AST fragments.