使用alex / happy with Cabal

时间:2010-12-16 21:45:34

标签: haskell cabal happy alex

我正在为我正在学习的课程编写一个编译器。该类不是专门的Haskell,而是我使用Haskell编写我的编译器和解释器。我有一个cabal包设置,希望我的教授可以轻松运行/编译。我对构建工具字段中的两个可执行文件感到高兴和alex,但是Cabal忽略了这一点,然后抱怨它无法找到Happy和Alex应该生成的模块。如果我手动运行:

alex LimpScanner.x
happy LimpParser.y
然后,cabal完美运行。

我以为我早些时候让cabal自动运行它们,但也许我记得不完美。

limp.cabal:

-- limp.cabal auto-generated by cabal init. For additional options,
-- see
-- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr.
-- The name of the package.
Name:                limp

-- The package version. See the Haskell package versioning policy
-- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for
-- standards guiding when and how versions should be incremented.
Version:             0.1

-- A short (one-line) description of the package.
Synopsis:            LIMP Compiler (Compiler Construction course project)

-- A longer description of the package.
-- Description:         

-- URL for the project homepage or repository.
Homepage:            http://www.cs.rit.edu/~eca7215/limp/

-- The license under which the package is released.
License:             AllRightsReserved

-- The file containing the license text.
License-file:        LICENSE

-- The package author(s).
Author:              Edward Amsden

-- An email address to which users can send suggestions, bug reports,
-- and patches.
Maintainer:          eca7215@cs.rit.edu

-- A copyright notice.
-- Copyright:           

Category:            Language

Build-type:          Simple

-- Extra files to be distributed with the package, such as examples or
-- a README.
-- Extra-source-files:  

-- Constraint on the version of Cabal needed to build this package.
Cabal-version:       >=1.2


Executable limp
  -- .hs or .lhs file containing the Main module.
  Main-is: Limp.hs

  hs-source-dirs: src     

  -- Packages needed in order to build this package.
  Build-depends: base, array, haskell98     

  -- Modules not exported by this package.
  -- Other-modules:       

  -- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source.
  Build-tools:         alex, happy
Executable limpi
  Main-is: LimpInterpreter.hs
  hs-source-dirs: src
  Build-depends: base, array, haskell98
  Build-tools: alex, happy

目录布局:

limp/
├── Setup.hs
├── limp.cabal
└── src/
    ├── Limp.hs
    ├── LimpInterpreter.hs
    ├── LimpParser.ly
    ├── LimpScanner.x
    └── LimpToken.hs

2 个答案:

答案 0 :(得分:15)

对于Warren Harris和其他像他(和我自己)可能会出现的其他模块,其他模块需要设置为模块名称列表(我猜?)预计将由构建中列出的工具构建-tools。

所以,就我而言,我的.cabal文件的相关部分最终看起来像这样:

build-tools:         alex, happy
other-modules:       Language.Heidi.Parser,
                     Language.Heidi.Lexer

答案 1 :(得分:10)

显然我缺少的实际上是Other-modules:字段。一旦这个被添加,cabal愉快地(原谅双关语)建立了我的翻译。