solution or workarounds for haskell-src-exts parsing modules with CPP failing

◇◆丶佛笑我妖孽 提交于 2019-12-24 16:38:59

问题


I'm trying to do some parsing of a bunch of haskell source files using haskell-src-exts but ran into trouble in the first file I tested on. Here is the first bit:

{-# LANGUAGE CPP, MultiParamTypeClasses, ScopedTypeVariables #-}
{-# OPTIONS_GHC -Wall -fno-warn-orphans #-}
----------------------------------------------------------------------
-- |
-- Module      :  FRP.Reactive.Fun
-- Copyright   :  (c) Conal Elliott 2007
-- License     :  GNU AGPLv3 (see COPYING)
-- 
-- Maintainer  :  conal@conal.net
-- Stability   :  experimental
-- 
-- Functions, with constant functions optimized, with instances for many
-- standard classes.
----------------------------------------------------------------------

module FRP.Reactive.Fun (Fun, fun, apply, batch) where

import Prelude hiding
  ( zip, zipWith
#if __GLASGOW_HASKELL__ >= 609
                , (.), id
#endif
  )
#if __GLASGOW_HASKELL__ >= 609
import Control.Category
#endif

And the code I'm using to test:

*Search> f <- parseFile "/tmp/file.hs"
*Search> f
ParseFailed (SrcLoc {srcFilename = "/tmp/file.hs", srcLine = 19, srcColumn = 1}) "Parse error: ;"

The issue appears to be the CPP conditional sections, but it appears that CPP is a supported extenstion. I'm using haskell-src-exts-1.11.1 with ghc 7.0.4

I'm just trying to do some quick and dirty analysis, so I don't mind stripping out those sections before parsing if I have to, but better solutions would be welcomed.


回答1:


Possibly use cpphs to "evaluate" the pre-processor statements first?

Also, that is the known extension list copied (and extended) from Cabal; haskell-src-exts doesn't support CPP.



来源:https://stackoverflow.com/questions/9235688/solution-or-workarounds-for-haskell-src-exts-parsing-modules-with-cpp-failing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!