代码注释中的预处理错误

Jas*_*Yeo 4 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
Run Code Online (Sandbox Code Playgroud)

违规行是这样的:

let allow_imm_inv = ref true (* imm inv to add of form @M<:v<:@A *)
Run Code Online (Sandbox Code Playgroud)

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

cam*_*ter 5

CamlP4不会"忽略"评论引文.即使在评论中也必须保持平衡.

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

(* " *)        <-  rejected as a syntax error
Run Code Online (Sandbox Code Playgroud)

被拒绝作为语法错误.这可能听起来很奇怪,但很容易注释掉像"*)"这样的字符串:

(* " *) " *)   <-  a valid comment (the syntax highlight gone crazy though)
Run Code Online (Sandbox Code Playgroud)

在你的例子中,同样的事情发生了但是对于P4报价<:XXX< >>.修复很容易.使用白色空间,如:

(* @M <: v <: @A *)
Run Code Online (Sandbox Code Playgroud)