From f23fbe8006b3a9e3b946a6f8fd18b2c7af340ac6 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Tue, 29 Dec 2020 00:39:12 +0100 Subject: [PATCH] Install printers --- top/README.org | 43 +++++++++++++++++++++++++++ top/install_printers.org | 59 +++++++++++++++++++++++++++++++++++++ top/lib/dune | 13 ++++++++ top/lib/install_printers.ml | 32 ++++++++++++++++++++ 4 files changed, 147 insertions(+) create mode 100644 top/README.org create mode 100644 top/install_printers.org create mode 100644 top/lib/dune create mode 100644 top/lib/install_printers.ml diff --git a/top/README.org b/top/README.org new file mode 100644 index 0000000..a5483e7 --- /dev/null +++ b/top/README.org @@ -0,0 +1,43 @@ +#+TITLE: Top-level +#+SETUPFILE: https://fniessen.github.io/org-html-themes/org/theme-readtheorg.setup + + +#+name: synopsis +#+begin_src ocaml :export output raw +"Installs pretty printers for top-level." +#+end_src + +#+RESULTS: synopsis +: Installs pretty printers for top-level. + + +* Dune files :noexport: + +** Generate dune files + + Use [C-c C-c] on the code below to create the output for the dune files + + #+header: :noweb strip-export + #+header: :var name=(file-name-directory buffer-file-name) + #+header: :var dune="lib/dune" + #+header: :var dunetest="test/dune" + #+begin_src python :exports none :results output none +name = name.split('/')[-2] +synopsis = """ +<> +""" + +with open(dune,'w') as f: + f.write(f""" +(library + (name {name}) + (public_name qcaml.{name}) + (synopsis {synopsis} ) + (modes byte) + (libraries + compiler-libs.toplevel + qcaml + ) +) +""") + #+end_src diff --git a/top/install_printers.org b/top/install_printers.org new file mode 100644 index 0000000..e3c5ea5 --- /dev/null +++ b/top/install_printers.org @@ -0,0 +1,59 @@ +#+begin_src elisp tangle: no :results none :exports none +(setq pwd (file-name-directory buffer-file-name)) +(setq name (file-name-nondirectory (substring buffer-file-name 0 -4))) +(setq lib (concat pwd "lib/")) +(setq testdir (concat pwd "test/")) +(setq mli (concat lib name ".mli")) +(setq ml (concat lib name ".ml")) +(setq test-ml (concat testdir name ".ml")) +(org-babel-tangle) +#+end_src + +* Intall printers + :PROPERTIES: + :header-args: :noweb yes :comments both + :END: + + Installs printers in the top-level environment. + + All printers are fetched automatically using the following script: + + #+NAME: printers + #+begin_src sh :results output raw +grep "val pp " ../*/*.org \ + | grep -v docs \ + | cut -d ":" -f 1 \ + | sed 's|^../||' \ + | sed 's|.org|.pp" ;|' \ + | sed 's|/| |' \ + | sed 's/[^ ]*/\u&/g' \ + | sed 's| |.|' \ + | sed 's|^|"|' \ + | grep -v Top.Install_printers.pp + #+end_src + + + #+begin_src ocaml :tangle (eval ml) :exports none +let printers = + [ + <> + ] + +let eval_exn str = + let lexbuf = Lexing.from_string str in + let phrase = !Toploop.parse_toplevel_phrase lexbuf in + Toploop.execute_phrase false Format.err_formatter phrase + + +let rec install_printers = function + | [] -> true + | printer :: printers -> + let cmd = Printf.sprintf "#install_printer %s;;" printer in + eval_exn cmd && install_printers printers + +let () = + if not (install_printers printers) then + Format.eprintf "Problem installing QCaml-printers@." + + #+end_src + diff --git a/top/lib/dune b/top/lib/dune new file mode 100644 index 0000000..42a2295 --- /dev/null +++ b/top/lib/dune @@ -0,0 +1,13 @@ + +(library + (name top) + (public_name qcaml.top) + (synopsis +"Installs pretty printers for top-level." + ) + (modes byte) + (libraries + compiler-libs.toplevel + qcaml + ) +) diff --git a/top/lib/install_printers.ml b/top/lib/install_printers.ml new file mode 100644 index 0000000..06ebc29 --- /dev/null +++ b/top/lib/install_printers.ml @@ -0,0 +1,32 @@ +(* [[file:../install_printers.org::*Intall printers][Intall printers:2]] *) +let printers = + [ + "Common.Angular_momentum.pp" ; + "Common.Bitstring.pp" ; + "Common.Charge.pp" ; + "Common.Coordinate.pp" ; + "Common.Powers.pp" ; + "Common.Range.pp" ; + "Common.Spin.pp" ; + "Common.Zkey.pp" ; + "Particles.Electrons.pp" ; + "Particles.Element.pp" ; + + ] + +let eval_exn str = + let lexbuf = Lexing.from_string str in + let phrase = !Toploop.parse_toplevel_phrase lexbuf in + Toploop.execute_phrase false Format.err_formatter phrase + + +let rec install_printers = function + | [] -> true + | printer :: printers -> + let cmd = Printf.sprintf "#install_printer %s;;" printer in + eval_exn cmd && install_printers printers + +let () = + if not (install_printers printers) then + Format.eprintf "Problem installing QCaml-printers@." +(* Intall printers:2 ends here *)