2013-08-21 98 views
4

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應該忽略代碼註釋中的引號符號?

回答

5

CamlP4不會「忽略」註釋引用。即使在評論中也必須保持平衡。

這就像OCaml需要在評論中平衡字符串引號一樣。例如:

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

被拒絕爲語法錯誤。這可能聽起來很奇怪,但很容易地註釋掉,如「*)」字符串有用:

(* " *) " *) <- a valid comment (the syntax highlight gone crazy though) 

在您的例子同樣的事情發生,但對於P4報價<:XXX< >>。修復很簡單。使用像下面這樣的空格:

(* @M <: v <: @A *) 
+0

謝謝!我閱讀了camlp4如何解析源代碼和評論:https://realworldocaml.org/beta3/en/html/the-compiler-frontend-parsing-and-type-checking.html#generating-documentation-from-interfaces。這就是ocamldoc如何從javadoc等註釋生成文檔。 –