Weaving to LaTeX

This commit is contained in:
Denis Merigoux 2020-03-07 18:20:04 -08:00
parent 56bc45db9d
commit c6a9b0b8f9
6 changed files with 29 additions and 8 deletions

5
.ocamlformat Normal file
View File

@ -0,0 +1,5 @@
profile = default
margin = 100
exp-grouping = preserve
wrap-comments
parse-docstrings

View File

@ -22,10 +22,10 @@ open Cli
let driver
(source_files : string list)
(debug: bool)
(_backend: string)
(_output_file : string)
(backend: string)
(output_file : string)
: int =
Cli.debug_flag := debug;
Cli.debug_flag := debug;
Cli.debug_print "Reading files...";
let program = ref [] in
List.iter (fun source_file ->
@ -47,7 +47,19 @@ Cli.debug_flag := debug;
exit (-1)
end
) source_files;
exit 0
if backend = "LaTeX" then
let weaved_output =
String.concat "\n\n" (List.map (fun file -> Weave.ast_to_latex file) !program)
in
Cli.debug_print (Printf.sprintf "Writing to %s" output_file);
let oc = open_out output_file in
Printf.fprintf oc "%s" weaved_output;
close_out oc;
0
else begin
Cli.error_print (Printf.sprintf "Unkown backend: %s" backend);
1
end
let main () =
Cmdliner.Term.exit @@ Cmdliner.Term.eval (Cli.lawspec_t driver, Cli.info)

View File

@ -5,3 +5,6 @@
(libraries ANSITerminal sedlex menhirLib re cmdliner dune-build-info)
(preprocess (pps sedlex.ppx))
)
(documentation
(package lawspec))

View File

@ -29,7 +29,7 @@ let source_file_item_to_latex (i: A.source_file_item) : string =
| A.LawCode c -> P.sprintf "\\subsection{%s}" c
| A.LawText t -> t
| A.LawArticle a -> P.sprintf "\\paragraph{%s}" a
| A.CodeBlock -> "code"
| A.CodeBlock -> P.sprintf "\\begin{lstlisting}\n%s\n\\end{lstlisting}" "code"
let ast_to_latex (file : A.source_file) : string =
String.concat "\n\n" (List.map (fun i ->

1
test/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.tex

View File

@ -1,6 +1,6 @@
@@ Code de la sécurité sociale @@
@@Code de la sécurité sociale@@
@ Article L521-3 @
@Article L521-3@
Blablabla, etc
@ -14,4 +14,4 @@ code
*/
@ Article L522-3 @
@Article L522-3@