2

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?

3
  • What syntax are you supposed to be parsing? Haskell? Something else? Commented Jul 29, 2013 at 22:50
  • Haskell. Sorry I forgot to be specific. Commented Jul 29, 2013 at 22:55
  • 6
    Have you looked at the haskell-src-exts package. In particular, the Language.Haskell.Exts.Parser module contains parsers for many kinds of Haskell AST fragments. Commented Jul 30, 2013 at 1:03

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.