PDF now shows file location

This commit is contained in:
Denis Merigoux 2020-04-19 19:04:11 +02:00
parent b57bb05325
commit 0977ae326e
10 changed files with 23 additions and 16 deletions

View File

@ -39,7 +39,7 @@ SRC_DIR=${CURDIR}/examples/allocations_familiales
SRC = $(SRC_DIR)/allocations_familiales.catala
%.tex: %.catala %.d
%.tex: %.catala
dune exec src/main.exe -- Makefile $<
dune exec src/main.exe --\
--debug \

View File

@ -1,9 +1,9 @@
@@Fichier maître@@
@@Inclusion: metadata.catala@@
@@Inclusion: M.catala@@
@@Inclusion: law.catala@@
@@Inclusion: L.catala@@
@@Inclusion: state_council_decrees.catala@@
@@Inclusion: R.catala@@
@@Inclusion: simple_decrees.catala@@
@@Inclusion: D.catala@@

View File

@ -53,8 +53,7 @@ let pygmentize_loc =
~doc:"Location of a custom pygmentize executable for LaTeX source code highlighting")
let catala_t f =
Term.(
const f $ file $ debug $ wrap_latex_output $ pygmentize_loc $ backend $ output)
Term.(const f $ file $ debug $ wrap_latex_output $ pygmentize_loc $ backend $ output)
let info =
let doc =
@ -64,7 +63,8 @@ let info =
[
`S Manpage.s_description;
`P
"Catala is a domain-specific language for deriving faithful-by-construction algorithms from legislative texts.";
"Catala is a domain-specific language for deriving faithful-by-construction algorithms \
from legislative texts.";
`S Manpage.s_authors;
`P "Denis Merigoux <denis.merigoux@inria.fr>";
`S Manpage.s_examples;

View File

@ -16,8 +16,7 @@ module I = Ir
(** Entry function for the executable. Returns a negative number in case of error. *)
let driver (source_file : string) (debug : bool) (wrap_latex_output : bool)
(pygmentize_loc : string option) (backend : string) (output_file : string option)
: int =
(pygmentize_loc : string option) (backend : string) (output_file : string option) : int =
Cli.debug_flag := debug;
Cli.debug_print "Reading files...";
if Filename.extension source_file <> ".catala" then begin
@ -31,15 +30,17 @@ let driver (source_file : string) (debug : bool) (wrap_latex_output : bool)
match output_file with Some f -> f | None -> Filename.remove_extension source_file ^ ".d"
in
let oc = open_out output_file in
Printf.fprintf oc "%s:\\\n%s"
Printf.fprintf oc "%s:\\\n%s\n%s:"
(String.concat "\\\n"
( output_file
:: List.map
(fun ext -> Filename.remove_extension source_file ^ ext)
backend_extensions_list ))
(String.concat "\\\n" program.program_source_files)
(String.concat "\\\n" program.program_source_files);
0
end else if backend = "LaTeX" then begin
0
end
else if backend = "LaTeX" then begin
Cli.debug_print (Printf.sprintf "Weaving literate program into LaTeX");
let weaved_output = Weave.ast_to_latex program in
let weaved_output =

View File

@ -45,8 +45,10 @@ let wrap_latex (code : string) (source_files : string list) (custom_pygments : s
\\fvset{\n\
commandchars=\\\\\\{\\},\n\
numbers=left,\n\
framesep=3mm,\n\
frame=leftline,\n\
%,framesep=3mm,\n\
%,frame=leftline,\n\
frame=lines,\n\
rulecolor=\\color{gray!70},\n\
firstnumber=last,\n\
codes={\\catcode`\\$=3\\catcode`\\^=7}\n\
}\n\n\
@ -93,7 +95,9 @@ let program_item_to_latex (i : A.program_item) : string =
| A.LawText t -> pre_latexify t
| A.LawArticle a -> P.sprintf "\\paragraph{%s}" (pre_latexify a)
| A.CodeBlock (_, c) ->
P.sprintf "\\begin{minted}[firstnumber=%d]{catala}%s\\end{minted}"
P.sprintf
"\\begin{minted}[label={\\hspace*{\\fill}\\texttt{%s}},firstnumber=%d]{catala}%s\\end{minted}"
(pre_latexify (Filename.basename (Pos.get_file (Pos.get_position c))))
(Pos.get_start_line (Pos.get_position c) + 1)
(Pos.unmark c)
| A.MetadataBlock (_, c) ->

View File

@ -35,6 +35,8 @@ let get_start_line (pos : t) : int =
let s, _ = pos.pos_loc in
s.Lexing.pos_lnum
let get_file (pos : t) : string = pos.pos_filename
type 'a marked = 'a * t
(** Everything related to the source code should keep its position stored, to improve error messages *)