camlp5 †

  • http://pauillac.inria.fr/~ddr/camlp5/
  • OCaml 3.09 までの camlp4 が名前をcamlp5と名前を変えて配布されている
    • OCaml 3.10 以降の camlp4 はそれまでの camlp4 と全く互換性がないため
    • Coq 等で使われている
    • 現行の camlp4 は undocumentedな部分が多いため camlp4 の代わりにこちらを使うのがよいかもしれない
    • 旧camlp4を使っているレガシーコードを新camlp5に移行するなど

チュートリアル †

とりあえず使ってみる †

  • hello.ml を構文解析して、そのままpretty printする
    camlp5 pr_o.cmo pa_o.cmo hello.ml
    • pr_* は pretty printer, pa_* は パーザ
    • *_o は original syntax, *_r は revised syntax

q_MLast.cmo †

ML構文のquotationを有効にする構文拡張?

camlp5 q_MLast.cmo pr_o.cmo pa_o.cmo test.ml

メモ †

パス式の扱いの違いについて †

  • 次の2つの場合でパス式C.cの表現が異なる
    • C.c x (xへの関数C.cの適用)
    • new C.c (クラスC.cのnew)
  • それぞれ次のようになる:
    MLast.ExAcc (loc, MLast.ExUid (loc, "F"), MLast.ExLid (loc, "f"))
    MLast.ExNew (loc, ["C"; "c"])
    • 前者は ExAcc? で UidとLidを結合, 後者は string list なぜ?
  • 他にもあるかも

旧camlp4 (3.08) からの移植 †

  • どうもocaml 3.08あたりまでのcamlp4は antiquote の $lid: .. $ 内に任意の式を許していたようだ。この性質を使ったコードは camlp5では許されない (もちろん現camlp4でも許されない。)
  • 同じく3.08あたりのcamlp4と antiquotationの種類が異なるようだ。
    inherit $lid: str$
    などとすると
    Parse error: illegal begin of class_expr_eoi
    と怒られる。 strの内容にもよるが
    inherit $Grammar.Entry.parse Pcaml.class_expr (Stream.of_string str)$
    とするか、
    inherit $list: [str]$
    とする(後者はcamlp5 6系でエラー).
  • 3.08 ではpr_o.cmoがデフォルトで標準出力に出力したようだがcamlp5はそうではない…ように見える??
    • ファイル名が空と判定されて
      Fatal error: exception Sys_error(": No such file or directory")
      と言われて落ちる。
      Pcaml.input_file := "-";
      とすれば標準出力に出るようになった。
  • ここまで調べたことを使って O'Jacare を camlp5 に移植した。 https://sites.google.com/site/keigoattic/o-jacare-camlp5-patch

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2011-01-02 (日) 07:33:36 (4862d)