解决方案或haskell-src-exts解析CPP失败的模块的解决方法 [英] solution or workarounds for haskell-src-exts parsing modules with CPP failing

查看:88
本文介绍了解决方案或haskell-src-exts解析CPP失败的模块的解决方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 haskell-src-exts 来解析一堆haskell源文件,但在我测试的第一个文件中遇到了麻烦。这是第一位:

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: ;"

问题似乎是CPP条件部分,但看起来CPP是支持extenstion 。我使用 haskell-src-exts-1.11.1 与ghc 7.0.4

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.

推荐答案

可能使用 cpphs 先评估预处理器语句?

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

另外,这是从 Cabal 复制(和扩展)的已知扩展列表。 haskell-src-exts 不支持 CPP。

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

这篇关于解决方案或haskell-src-exts解析CPP失败的模块的解决方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆