我正在使用--compile-errors的menhir功能,我对此非常满意。我还使用ocamlbuild来管理我的项目的编译。由于该项目是相当基础的,因此到目前为止,构建基础设施仍然是微不足道的。
我在项目的根目录有一个_tags文件和一个简单的Makefile。我还没有myocamlbuild.ml文件。_tags文件只包含一行:
<src/*>: package(ppx_deriving.std)Makefile的相关部分是
all: src/ParsingErrors.ml
ocamlbuild $(OPTIONS) src/Main.native
src/ParsingErrors.ml: src/Handcrafted.messages src/Parser.mly
menhir --compile-errors src/Handcrafted.messages src/Parser.mly > src/ParsingErrors.ml
OPTIONS = -j 4 -use-menhir -use-ocamlfind -yaccflag --table -pkgs menhirLib,str,unixOCamlbuild和Menhir通常集成得很好,但是--compile-errors似乎是一个相当新的功能。我的设置并不理想,因为我不喜欢在源目录而不是构建目录中有一个自动生成的文件src/ParsingErrors.ml。向OCamlbuild解释我希望Menhir构建这个错误消息文件的最佳方式是什么?如果将我的文件的命名约定更改为src/Parser.messages和src/Parser.ml,如果它简化了的话,我就不会感到烦恼。
注:虽然我在其他项目中有myocamlbuild.ml文件,但我从在线来源复制了它们。我发现他们很难破译,我也不知道怎么写这些东西。
发布于 2016-11-16 09:41:40
寻找这个问题答案的最好地方是Menhir的发行版,因为menhir在自己的编译过程中使用了"menhir -编译-错误“和ocamlbuild。
要查找的文件是src/myocamlbuild.ml中的源球。
以下是一段相关的摘录:
(* This rule generates an .ml file [target] from an .mly file [grammar] and a
.messages file [messages]. *)
(* If the name of a witness file is passed, it is made an additional
dependency. This triggers a separate rule (see below) which performs a
completeness check, that is, which checks that the .messages file lists
every possible syntax error. *)
let compile_errors grammar messages (witness : string list) target =
rule
"menhir/compile_errors"
~prod:target
~deps:([ grammar; messages ] @ witness)
(fun env _ ->
let grammar = env grammar in
let tags = tags_of_pathname grammar ++ "ocaml" ++ "menhir" in
Cmd(S[
!Options.ocamlyacc; (* menhir *)
T tags;
P grammar;
A "--compile-errors"; P (env messages);
Sh ">"; Px (env target);
]))
(* A generic version of the above rule, with uniform naming. *)
let generic_compile_errors (check_completeness : bool) =
compile_errors
(* sources: *)
"%.mly" "%Messages.messages"
(* if present, this dependency forces a completeness check: *)
(if check_completeness then [ "%Messages.witness" ] else [])
(* target: *)
"%Messages.ml"我很乐意与ocamlbuild维护人员讨论一下,Menhir的myocamlbuild.ml的某些部分是否可以转移到ocamlbuild的标准规则中。(你好,加布里埃尔!)
发布于 2016-11-15 18:20:25
这个特性在当前的ocamlbuild版本中确实不受支持。要将它添加到您的myocamlbuild.ml插件中,您必须定义一个新的构建规则。如果您对myocamlbuild.ml内部的内容感到害怕,您可能会对新的建筑手册感兴趣,特别是插件一节。
我刚刚在ocamlbuild存储库上打开了一个发行报告#121来跟踪这个缺失的特性。您是否有兴趣了解关于ocamlbuild的足够多的知识,以便为此编写一条适当的规则并将其贡献给下一个ocamlbuild版本?如果是的话,欢迎访问github问题,并开始询问如何实现它,我很乐意提供帮助。如果没有,我会在有时间的时候自己实现它。
同时,请注意,为特定文件定义一次规则要比为泛型规则定义简单得多。如果您已经准备好对所使用的源代码文件进行硬编码,那么您可能有一些看起来非常类似于Makefile规则的东西。我今天没有时间写和检查这条规则,但如果其他人在这段时间里没有这样做,我会尽量明天再来。
https://stackoverflow.com/questions/40604749
复制相似问题