ocaml - 代码注释中的预处理错误

标签 ocaml camlp4

使用 corebuild 编译我的代码时出现此错误:

~/project $ corebuild debug.byte
ocamlfind ocamldep -syntax camlp4o -package bin_prot.syntax -package sexplib.syntax,comparelib.syntax,fieldslib.syntax,variantslib.syntax -package core -modules globals.ml > globals.ml.depends
+ ocamlfind ocamldep -syntax camlp4o -package bin_prot.syntax -package sexplib.syntax,comparelib.syntax,fieldslib.syntax,variantslib.syntax -package core -modules globals.ml > globals.ml.depends
File "globals.ml", line 744, characters 57-17803 (end at line 1402, character 0):
Quotation not terminated
Preprocessing error on file globals.ml
Error while running external preprocessor
Command line: camlp4 '-I' '/Users/mapleleaf/.opam/4.01.0dev+trunk/lib/ocaml/camlp4' '-I' '/Users/mapleleaf/.opam/4.01.0dev+trunk/lib/type_conv' '-I' '/Users/mapleleaf/.opam/4.01.0dev+trunk/lib/ocaml' '-I\
' '/Users/mapleleaf/.opam/4.01.0dev+trunk/lib/ocaml' '-I' '/Users/mapleleaf/.opam/4.01.0dev+trunk/lib/bin_prot' '-I' '/Users/mapleleaf/.opam/4.01.0dev+trunk/lib/bin_prot' '-I' '/Users/mapleleaf/.opam/4.0\
1.0dev+trunk/lib/ocaml' '-I' '/Users/mapleleaf/.opam/4.01.0dev+trunk/lib/num' '-I' '/Users/mapleleaf/.opam/4.01.0dev+trunk/lib/sexplib' '-I' '/Users/mapleleaf/.opam/4.01.0dev+trunk/lib/sexplib' '-I' '/Us\
ers/mapleleaf/.opam/4.01.0dev+trunk/lib/comparelib' '-I' '/Users/mapleleaf/.opam/4.01.0dev+trunk/lib/comparelib' '-I' '/Users/mapleleaf/.opam/4.01.0dev+trunk/lib/fieldslib' '-I' '/Users/mapleleaf/.opam/4\
.01.0dev+trunk/lib/fieldslib' '-I' '/Users/mapleleaf/.opam/4.01.0dev+trunk/lib/variantslib' '-I

违规行是这样的:
let allow_imm_inv = ref true (* imm inv to add of form @M<:v<:@A *)

这怎么可能?我认为camlp4应该忽略代码注释中的引号?

最佳答案

CamlP4 不会“忽略”注释引用。即使在评论中,它们也必须保持平衡。

就像 OCaml 需要在注释中平衡字符串引号一样。例如:

(* " *)        <-  rejected as a syntax error

被拒绝为语法错误。这听起来可能很奇怪,但很容易注释掉像“*)”这样的字符串:
(* " *) " *)   <-  a valid comment (the syntax highlight gone crazy though)

在你的例子中,同样的事情发生了,但对于 P4 报价 <:XXX< >> .修复很容易。使用空格,如:
(* @M <: v <: @A *)

关于ocaml - 代码注释中的预处理错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18351085/

相关文章:

ocaml - 用于处理常规树状结构匹配的代码生成?

ubuntu - 如何在 emacs、ubuntu 上包含camlp4

ocaml - 是否有可能获得 OCaml 程序的 AST?

list - 如何在 OCaml 中取两个列表的乘积?

带有链接 C 库的 OCaml native 可执行文件

functional-programming - `[< >]` 在 OCaml 中是什么意思?

ocaml - camlp4 语法扩展,解析器错误

types - OCAML 如何找到变体的下一个元素

list - OCaml:交换列表中的元素

ocaml - 在 Ocaml 中测试异常引发