如何在 Emacs 中为 Ocaml 生成和设置注释?

发布于 2024-11-16 22:46:17 字数 691 浏览 2 评论 0原文

我正在使用 Emacs 用 Ocaml 编写编译器。我听说使用 -annot 可以在编译时生成文件 .annot,这可以帮助 Emacs 显示我的代码的类型。但奇怪的是,运行这个makefile后没有生成.annot。谁能告诉我这有什么问题吗?

另外,一旦我获得了 .annot,我是否需要设置任何内容(例如 .emacs?)以便我的 Emacs 读取它并显示我的代码类型?

非常感谢!

Edit1:在 make cleanmake 之后,我得到了 .annot...但我仍然不知道如何使用它Emacs 中的 .annot

Edit2:实际上有必要遵循这个链接,复制文件在本地文件夹中,然后更新 .emacs。然后,当在 Emacs 中编辑 .ml 时,Cc Ct 从 .annot 返回其类型。

I am writing a compiler in Ocaml with Emacs. I am told that with -annot a file .annot could be generated while compiling, which could help Emacs to show the type of my code. But it is odd that no .annot is generated after running this makefile. Could anyone tell me what is wrong with that?

Also, once i have got .annot, do I need to set up anything (for instance .emacs?) so that my Emacs read it and show the type of my code?

Thank you very much!

Edit1: after make clean and make, I have got the .annot... But I still do not know how to make use of this .annot in Emacs.

Edit2: actually it is necessary to follow this link, copy the files in a local folder, then update .emacs. Then when a .ml is edited in Emacs, C-c C-t returns its type from .annot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绮筵 2024-11-23 22:46:17

关于您的 emacs 查询——我不使用 emacs——,这是来自 ocamlc 的手册页

-annot 转储有关编译的详细信息(类型、绑定、尾部调用等)。文件 src.ml 的信息被放入文件 src.annot 中。如果出现类型错误,请转储类型检查器在错误发生之前推断出的所有信息。 src.annot 文件可以与 emacs/caml-types.el 中给出的 emacs 命令一起使用,以交互方式显示类型和其他注释。

线程中还有其他工具我之前提到过

至于 Makefile 没有创建 .annot 文件,我创建了一个模拟目录并成功创建了 .annot 文件。我也没有发现你的Makefile有什么问题。您可能想要清理目录并重试,或者切换到另一种方式来构建您的工具,例如 ocamlbuild ——这需要最少的设置,不过,我还没有将它与 menhir 一起使用

我还要指出 -annot 是新的自 OCaml 3.11.0 起,之前的标志为 -dtypes

Regarding your emacs inquiry --I don't use emacs--, this is from the man-pages for ocamlc,

-annot Dump detailed information about the compilation (types, bindings, tail-calls, etc). The information for file src.ml is put into file src.annot. In case of a type error, dump all the information inferred by the type-checker before the error. The src.annot file can be used with the emacs commands given in emacs/caml-types.el to display types and other annotations interactively.

There are also other tools from the thread I mentioned previously.

As for the Makefile not creating the .annot files, I made a mock directory and successfully had .annot files created. I also don't see anything wrong with your Makefile. You may want to clean the directory and try again, or switch to another way to build your tool like ocamlbuild --which would require minimal setup, although, I haven't used it with menhir.

I will also note that -annot is new since OCaml 3.11.0, and prior the flag was -dtypes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文