GHC ParseTree Module

Jane Ren j2ren at ucsd.edu
Mon Jan 3 18:51:49 CET 2011


Hi,

I think I figured out what code I need to write to get the AST of a haskell module (pasted below).  Basically, I need to get the typed parsetrees of all Haskell base libraries to do some analysis.  But the that "parse" function seems to produce a "parse error" for each one of the base libraries.  In fact, it only works ok if I use a simple test file which contains "n = 3".  Any ideas?

parse :: String -> HsModule
parse syntax = 
  case parseModule syntax of 
    (ParseOk ast)          -> ast
    (ParseFailed loc msg)  -> error $ (show loc)

main = do
   file_content <- readFile targetFile
   let ast = parse file_content
   print ast

Thanks.
________________________________________
From: Malcolm Wallace [malcolm.wallace at me.com]
Sent: Monday, January 03, 2011 12:44 AM
To: Jane Ren; GHC-users List
Cc: haskell-cafe at haskell.org
Subject: Re: GHC ParseTree Module

You will be more likely to get an answer on the ghc-users mailing list
(cc'ed).  The ghc developers rarely follow -cafe.

On 1 Jan 2011, at 20:36, Jane Ren wrote:

> Hi,
>
> Does anyone know what GHC module gets the AST and type info of some
> source code?  This is the GHC module that converts all of Haskell
> into an AST with a small number of pattern cases, where each AST
> node is annotated with the Haskell type.
>
> Thanks
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe




More information about the Glasgow-haskell-users mailing list