10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-11-13 09:33:41 +01:00

Install printers

This commit is contained in:
Anthony Scemama 2020-12-29 00:39:12 +01:00
parent 56d151ea36
commit f23fbe8006
4 changed files with 147 additions and 0 deletions

43
top/README.org Normal file
View File

@ -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 = """
<<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

59
top/install_printers.org Normal file
View File

@ -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 =
[
<<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

13
top/lib/dune Normal file
View File

@ -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
)
)

View File

@ -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 *)