使用 alex/happy 与 Cabal
我正在为我正在学习的课程编写一个编译器。该类不是专门的 Haskell,但我正在使用 Haskell 来编写我的编译器和解释器。我有一个 cabal 包设置,希望能让我的教授轻松运行/编译。
我在两个可执行文件的 build-tools
字段中都有 happy 和 alex,但 Cabal 忽略了这一点,然后抱怨它找不到 Happy 和 Alex 应该生成的模块。
如果我手动运行:
alex LimpScanner.x
happy LimpParser.y
那么 cabal 运行完美。
我以为我早些时候已经让阴谋集团自动运行它们,但也许我记得不完整。
limp.cabal
的内容:
Name: limp
Version: 0.1
Synopsis: LIMP Compiler (Compiler Construction course project)
Homepage: http://www.cs.rit.edu/~eca7215/limp/
License: AllRightsReserved
License-file: LICENSE
Author: Edward Amsden
Maintainer: [email protected]
Category: Language
Build-type: Simple
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
I'm writing a compiler for a class I'm taking. The class isn't specifically Haskell but I'm using Haskell to write my compiler and interpreter. I have a cabal package setup to hopefully make it easy for my prof to run/compile.
I have happy and alex in the build-tools
field for both executables but Cabal ignores that and then complains that it cannot find the modules that Happy and Alex should be generating.
If I manually run:
alex LimpScanner.x
happy LimpParser.y
then cabal runs perfectly.
I thought I had cabal automatically running them earlier but perhaps I remember imperfectly.
Contents of limp.cabal
:
Name: limp
Version: 0.1
Synopsis: LIMP Compiler (Compiler Construction course project)
Homepage: http://www.cs.rit.edu/~eca7215/limp/
License: AllRightsReserved
License-file: LICENSE
Author: Edward Amsden
Maintainer: [email protected]
Category: Language
Build-type: Simple
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
Directory layout:
limp/
├── Setup.hs
├── limp.cabal
└── src/
├── Limp.hs
├── LimpInterpreter.hs
├── LimpParser.ly
├── LimpScanner.x
└── LimpToken.hs
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 Warren Harris 和其他像他(和我自己)一样的人来说,其他模块需要设置为模块名称列表(我猜?)预计将由构建工具中列出的工具构建。
因此,就我而言,.cabal 文件的相关部分最终如下所示:
For Warren Harris and others like him (and myself) that may come along later, other-modules needs to be set to a list of module names that (I guess?) are expected to be built by the tools listed in build-tools.
So, in my case, the relevant sections of my .cabal file ended up looking like this:
显然我缺少的实际上是“其他模块:”字段。添加后,阴谋集团很高兴(请原谅双关语)构建了我的解释器。
Apparently what I was missing was actually the Other-modules: field. Once this was added, cabal happily (pardon the pun) built my interpreter.