10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-11-14 01:53:39 +01:00
QCaml/top/install_printers.org

74 lines
1.9 KiB
Org Mode
Raw Normal View History

2020-12-29 00:39:12 +01:00
#+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
2021-01-01 17:05:25 +01:00
* Intall printers :noexport:
2020-12-29 00:39:12 +01:00
:PROPERTIES:
:header-args: :noweb yes :comments both
:END:
Installs printers in the top-level environment.
2021-01-01 17:05:25 +01:00
All printers are fetched automatically.
2020-12-29 00:39:12 +01:00
2021-01-01 12:52:50 +01:00
#+NAME: raw_printers
2021-01-01 17:05:25 +01:00
#+begin_src sh :results output raw :exports none
2020-12-29 00:39:12 +01:00
grep "val pp " ../*/*.org \
| grep -v docs \
| cut -d ":" -f 1 \
| sed 's|^../||' \
2021-01-01 12:52:50 +01:00
| sed 's|.org||' \
2020-12-29 00:39:12 +01:00
| sed 's|/| |' \
| sed 's/[^ ]*/\u&/g' \
| sed 's| |.|' \
2021-01-01 12:52:50 +01:00
| grep -v Top.Install_printers
#+end_src
#+NAME: printers
2021-01-01 17:05:25 +01:00
#+begin_src python :results output raw :var p=raw_printers :exports none
2021-01-01 12:52:50 +01:00
result = []
for l in p.split():
dir, module = l.split('.')
if dir == module:
e = f'"{module}.pp" ;'
else:
e = f'"{dir}.{module}.pp" ;'
result.append(e)
result = '\n'.join(result)
print(result)
2020-12-29 00:39:12 +01:00
#+end_src
2021-01-01 17:05:25 +01:00
2020-12-29 00:39:12 +01:00
#+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
2020-12-29 02:29:43 +01:00
| [] -> eval_exn "#require \"lacaml.top\";;"
2020-12-29 00:39:12 +01:00
| 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