AlanKim Zimmerman | 10 Sep 22:03 2013
Picon

GHC API question: Getting access to cpp processed source

Hi Cafe

I have just discovered that GHC.getTokenStream fails if it is used on a module with CPP directives in it.

Is there an easy way to get access to the pre-processed source, without having to explicitly write it to an output file in a temporary location?

In other words an equivalent to getModuleSourceAndFlags that does the right thing.

This currently prevents HaRe from processing files with preprocessor directives in them, I would like to come up with a workaround for current GHC versions, rather than having to wait for a future one.

Regards
  Alan
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Carter Schonwald | 11 Sep 00:06 2013
Picon

Re: GHC API question: Getting access to cpp processed source

you need to run a preprocessor on it to remove the directives


On Tue, Sep 10, 2013 at 4:03 PM, AlanKim Zimmerman <alan.zimm <at> gmail.com> wrote:
Hi Cafe

I have just discovered that GHC.getTokenStream fails if it is used on a module with CPP directives in it.

Is there an easy way to get access to the pre-processed source, without having to explicitly write it to an output file in a temporary location?

In other words an equivalent to getModuleSourceAndFlags that does the right thing.

This currently prevents HaRe from processing files with preprocessor directives in them, I would like to come up with a workaround for current GHC versions, rather than having to wait for a future one.

Regards
  Alan

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Henk-Jan van Tuyl | 11 Sep 00:54 2013
Picon

Re: GHC API question: Getting access to cpp processed source

On Tue, 10 Sep 2013 22:03:16 +0200, AlanKim Zimmerman  
<alan.zimm <at> gmail.com> wrote:

> Is there an easy way to get access to the pre-processed source, without
> having to explicitly write it to an output file in a temporary location?

You can run cpp with function readProcess, as done in function  
readHeaderFile in
https://github.com/wxHaskell/wxHaskell/blob/master/wxdirect/src/ParseC.hs

Windows does not come with cpp; one can install MinGW for this purpose.

Another option could be the cpphs package; the documentation has  
disappeared from haskell.org, but can be found in the Web Archive[0].

Regards,
Henk-Jan van Tuyl

[0] http://web.archive.org/web/20100620174616/http://haskell.org/cpphs/

--

-- 
Folding <at> home
What if you could share your unused computer power to help find a cure? In  
just 5 minutes you can join the world's biggest networked computer and get  
us closer sooner. Watch the video.
http://folding.stanford.edu/

http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
Haskell programming
--
Henk-Jan van Tuyl | 11 Sep 00:56 2013
Picon

Re: GHC API question: Getting access to cpp processed source

On Wed, 11 Sep 2013 00:54:07 +0200, Henk-Jan van Tuyl <hjgtuyl <at> chello.nl>  
wrote:

> Another option could be the cpphs package; the documentation has  
> disappeared from haskell.org, but can be found in the Web Archive[0].

I just found the latest documentation at
http://code.haskell.org/cpphs/docs/

Regards,
Henk-Jan van Tuyl

--

-- 
Folding <at> home
What if you could share your unused computer power to help find a cure? In  
just 5 minutes you can join the world's biggest networked computer and get  
us closer sooner. Watch the video.
http://folding.stanford.edu/

http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
Haskell programming
--
AlanKim Zimmerman | 11 Sep 08:35 2013
Picon

Re: GHC API question: Getting access to cpp processed source

Thanks for the reference, but GHC already invokes the CPP.

I think I am going to have to invoke a load of the module with ghc flags set to keep the output of the CPP phase, and then re-invoke it on that output to get the tokens.

My question is more whether this CPP output can be kept in the GHC session for re-use, or whether I will have to mess around on the file system.

Alan


On Wed, Sep 11, 2013 at 12:56 AM, Henk-Jan van Tuyl <hjgtuyl <at> chello.nl> wrote:
On Wed, 11 Sep 2013 00:54:07 +0200, Henk-Jan van Tuyl <hjgtuyl <at> chello.nl> wrote:

Another option could be the cpphs package; the documentation has disappeared from haskell.org, but can be found in the Web Archive[0].

I just found the latest documentation at
http://code.haskell.org/cpphs/docs/

Regards,
Henk-Jan van Tuyl



--
Folding <at> home
What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video.
http://folding.stanford.edu/


http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
Haskell programming
--

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Gmane