我在使用我的camlp4解析器中的deriving-ocsigen語法擴展時遇到問題。我的解析器被稱爲pa_debug.ml
使用ocamlbuild在Camlp4中使用OCaml語法擴展
這裏的標籤文件:
<pa_debug.ml>: pp(camlp4orf.opt), package(deriving-ocsigen.syntax), syntax(camlp4o)
當
ocamlbuild -libs dynlink,camlp4lib,deriving -cflags -I,+camlp4,-dtypes -lflags -I,+camlp4,-dtypes -use-ocamlfind pa_debug.cmo
編譯我收到以下錯誤:
Warning: -pp overrides the effect of -syntax partly
File "pa_debug.ml", line 103, characters 66-67:
While expanding quotation "expr" in a position of "expr":
Parse error: [expr] expected after [infix operator (level 0) (comparison operators, and some others)] (in [expr])
在第二齣現的錯誤這段代碼的一行:
...
let fun_id = get_fun_id bi in
let app = <:expr< Debug.ho_1 $str:fun_id$ (Show.show<int>) (Show.show<int>) >> in
let debug_fun_body = mk_appln _loc app new_patts in
...
在代碼中,我輸入要在引號中使用派生語法。但似乎預處理器並不瞭解引用中存在「<」和「>」比較運算符。如果我在不帶引號的其他文件中使用Show.show<int>
語法,它將編譯時不會出錯。
我見過solution修復-pp overrides the effect of -syntax
問題,但我不明白。有人可以向我解釋或建議一些其他方法來解決它嗎?
如果我們有權訪問'pa_debug.ml'文件,試圖查看哪些編譯行實際工作,那將會更容易。我可以先看看說的是,你的'使用ocamlbuild'是不尋常的:它應該是一個高層次的彙編管理器,和你的'-cflags -I ...使用'看起來像你想*不*使用'ocamlbuild'。我懷疑這會更好地工作,如果被移動到這些低級別的選項的笨工具(亦即。'ocamlfind'),或使用ocamlbuild'的'標籤化能力以更自然的方式。 – gasche 2013-05-14 08:28:14
@gasche我不確定ocamlbuild是如何工作的。你是說我應該刪除整個'-cflags ...'選項嗎? – 2013-05-15 17:15:19
我認爲有更好的方法來做你的'-clfags'做的事情;參見[這篇博客文章(http://gallium.inria.fr/blog/quick-tip-the-ocamlbuild-documentation-option/)如何摸透'ocamlbuild'標籤來代替使用。不過,我並不是說你應該盲目刪除它們。 – gasche 2013-05-15 17:53:50