Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ build.ninja
.catleg_secrets.toml
*.tmp/
perf.data*
.DS_Store
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ The Catala language should be adapted to any legislative text that follows a
general-to-specifics statutes order. Therefore, there exists multiple versions
of the Catala surface syntax, adapted to the language of the legislative text.

Currently, Catala supports English, French and Polish legislative text via the
`--language=en`, `--language=fr` or `--language=pl` options.
Currently, Catala supports English, French, Polish and Romanian legislative text via the
`--language=en`, `--language=fr`, `--language=pl` or `--language=ro` options.

To add support for a new language:

Expand Down
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@ $(PY_VENV_DIR)/stamp: \
runtimes/python/pyproject.toml \
syntax_highlighting/en/pygments/pyproject.toml \
syntax_highlighting/fr/pygments/pyproject.toml \
syntax_highlighting/pl/pygments/pyproject.toml
syntax_highlighting/pl/pygments/pyproject.toml \
syntax_highlighting/ro/pygments/pyproject.toml
test -d $(PY_VENV_DIR) || python3 -m venv $(PY_VENV_DIR)
$(PY_VENV_ACTIVATE) python3 -m pip install -U pip
$(PY_VENV_ACTIVATE) python3 -m pip install -U \
-e deps/dates-calc/lib_python/ \
-e runtimes/python \
-e syntax_highlighting/en/pygments \
-e syntax_highlighting/fr/pygments \
-e syntax_highlighting/pl/pygments
-e syntax_highlighting/pl/pygments \
-e syntax_highlighting/ro/pygments
touch $@

dependencies-python: $(PY_VENV_DIR)
Expand Down Expand Up @@ -358,7 +360,7 @@ clean:
rm -rf artifacts

inspect:
gitinspector -f ml,mli,mly,iro,tex,catala,catala_en,catala_pl,catala_fr,md,fst,mld --grading
gitinspector -f ml,mli,mly,iro,tex,catala,catala_en,catala_pl,catala_fr,catala_ro,md,fst,mld --grading

#> help_clerk : Display the clerk man page
help_clerk:
Expand Down
8 changes: 5 additions & 3 deletions build_system/clerk_driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ let backend_src_extensions =
Clerk_rules.OCaml, ["ml"; "mli"];
Clerk_rules.Python, ["py"];
Clerk_rules.Java, ["java"];
Clerk_rules.Tests, ["catala_en"; "catala_fr"; "catala_pl"];
Clerk_rules.Tests, ["catala_en"; "catala_fr"; "catala_pl"; "catala_ro"];
]

let backend_obj_extensions =
Expand Down Expand Up @@ -627,7 +627,8 @@ let build_direct_targets
let is_module = ext = "" in
match List.assoc_opt ext extensions_backend, ext with
| Some bk, _ -> Left (ensure_target_dir (backend_subdir bk) t)
| None, ("catala_en" | "catala_fr" | "catala_pl") -> Left t
| None, ("catala_en" | "catala_fr" | "catala_pl" | "catala_ro") ->
Left t
| None, ("exe" | "jar") ->
let t, backend =
match ext, lastdirname t with
Expand Down Expand Up @@ -1050,7 +1051,7 @@ let typecheck_cmd =
Clerk_rules.run_ninja ~config ~enabled_backends:[Clerk_rules.Tests]
~autotest:false ~ninja_flags (fun nin_ppf items var_bindings ->
Nj.format_def nin_ppf
(Nj.Default (Nj.Default.make ["Stdlib_fr@src"; "Stdlib_en@src"]));
(Nj.Default (Nj.Default.make ["Stdlib_fr@src"; "Stdlib_en@src"; "Stdlib_ro@src"]));
items, var_bindings)
in
let catala_flags = get_var var_bindings Var.catala_flags in
Expand Down Expand Up @@ -1330,6 +1331,7 @@ let start_cmd =
"@runtime-ocaml";
"Stdlib_fr@ocaml-module";
"Stdlib_en@ocaml-module";
"Stdlib_ro@ocaml-module";
]));
0)
in
Expand Down
2 changes: 1 addition & 1 deletion build_system/dune
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
(run
sh
-c
"for page in '' $(%{bin:clerk} 2>&1 | sed -n \"s/\\(^\\|'\\)[^']*\\('\\|$\\)/ /gp;q\"); do\n echo '(rule (alias man) (action (with-stdout-to clerk'${page:+-$page}'.1 (run \%{bin:clerk} '$page' --help=groff))))'\n done"))))
"for page in '' $(%{bin:clerk} 2>&1 | sed -E \"s/[^']*'([^']*)'[^']*/\\1 /g\" | head -1); do\n echo '(rule (alias man) (action (with-stdout-to clerk'${page:+-$page}'.1 (run \%{bin:clerk} '$page' --help=groff))))'\n done"))))

(install
(section man)
Expand Down
5 changes: 3 additions & 2 deletions compiler/catala_utils/cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module G = Global
(* Manipulation of types used by flags & options *)

(** Associates a {!type: Global.backend_lang} with its string represtation. *)
let languages = ["en", En; "fr", Fr; "pl", Pl]
let languages = ["en", En; "fr", Fr; "pl", Pl; "ro", Ro]

let language_code =
let rl = List.map (fun (a, b) -> b, a) languages in
Expand All @@ -43,7 +43,8 @@ let raw_file =

(* Some helpers for catala sources *)

let extensions = [".catala_fr", Fr; ".catala_en", En; ".catala_pl", Pl]
let extensions =
[".catala_fr", Fr; ".catala_en", En; ".catala_pl", Pl; ".catala_ro", Ro]

let file_lang filename =
List.assoc_opt (Filename.extension filename) extensions
Expand Down
4 changes: 2 additions & 2 deletions compiler/catala_utils/global.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

type file = string
type raw_file = file
type backend_lang = En | Fr | Pl
type backend_lang = En | Fr | Pl | Ro
type when_enum = Auto | Always | Never
type message_format_enum = Human | GNU | Lsp
type trace_format_enum = Human | JSON
Expand Down Expand Up @@ -113,4 +113,4 @@ let enforce_options

let input_src_file = function FileName f | Contents (_, f) | Stdin f -> f
let raw_file f = f
let has_localised_stdlib = function En | Fr -> true | _ -> false
let has_localised_stdlib = function En | Fr | Ro -> true | _ -> false
2 changes: 1 addition & 1 deletion compiler/catala_utils/global.mli
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type raw_file = private file
(** A file name that has not yet been resolved, [options.path_rewrite] must be
called on it *)

type backend_lang = En | Fr | Pl
type backend_lang = En | Fr | Pl | Ro

(** The usual auto/always/never option argument *)
type when_enum = Auto | Always | Never
Expand Down
12 changes: 10 additions & 2 deletions compiler/desugared/name_resolution.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1331,12 +1331,20 @@ let process_use_item

(** {1 API} *)

let empty_module_ctxt _lang =
let empty_module_ctxt lang =
{
current_revpath = [];
typedefs = Ident.Map.empty;
field_idmap = Ident.Map.empty;
constructor_idmap = Ident.Map.empty;
constructor_idmap =
(let present = EnumName.Map.singleton Expr.option_enum Expr.some_constr in
let absent = EnumName.Map.singleton Expr.option_enum Expr.none_constr in
Ident.Map.of_list
(match lang with
| Global.En -> ["Present", present; "Absent", absent]
| Global.Fr -> ["Présent", present; "Absent", absent]
| Global.Pl -> ["Obecny", present; "Nieobecny", absent]
| Global.Ro -> ["Prezent", present; "Absent", absent]));
topdefs = Ident.Map.empty;
used_modules = Ident.Map.empty;
is_external = false;
Expand Down
8 changes: 7 additions & 1 deletion compiler/driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ open Shared_ast

(** Associates a file extension with its corresponding
{!type: Global.backend_lang} string representation. *)
let extensions = [".catala_fr", "fr"; ".catala_en", "en"; ".catala_pl", "pl"]
let extensions =
[
".catala_fr", "fr";
".catala_en", "en";
".catala_pl", "pl";
".catala_ro", "ro";
]

let load_modules
options
Expand Down
1 change: 1 addition & 0 deletions compiler/literate/html.ml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ let ast_to_html
| C.Fr -> "Sommaire"
| C.En -> "Table of contents"
| C.Pl -> "Spis treści."
| C.Ro -> "Cuprins"
in

Format.fprintf fmt
Expand Down
10 changes: 8 additions & 2 deletions compiler/literate/latex.ml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ codes={\catcode`\$=3\catcode`\^=7}
\[\star\star\star\]
\clearpage
|latex}
(match language with Fr -> "french" | En -> "english" | Pl -> "polish")
(match language with
| Fr -> "french"
| En -> "english"
| Pl -> "polish"
| Ro -> "romanian")
(match language with Fr -> "\\setmainfont{Marianne}" | _ -> "")
(* for France, we use the official font of the French state design system
https://gouvfr.atlassian.net/wiki/spaces/DB/pages/223019527/Typographie+-+Typography *)
Expand All @@ -172,7 +176,8 @@ codes={\catcode`\$=3\catcode`\^=7}
(pre_latexify (literal_disclaimer_and_link language))
(literal_source_files language)
(String.concat
((match language with Fr -> " ;" | En -> ";" | Pl -> ";") ^ "\n")
((match language with Fr -> " ;" | En -> ";" | Pl -> ";" | Ro -> ";")
^ "\n")
(List.map
(fun filename ->
let mtime = (Unix.stat filename).Unix.st_mtime in
Expand Down Expand Up @@ -308,6 +313,7 @@ let rec law_structure_to_latex
| Fr -> "Métadonnées"
| En -> "Metadata"
| Pl -> "Metadane"
| Ro -> "Metadate"
in
let start_line = Pos.get_start_line (Mark.get c) + 1 in
let filename = Pos.get_file (Mark.get c) in
Expand Down
11 changes: 11 additions & 0 deletions compiler/literate/literate_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@ let literal_title = function
| En -> "Legislative text implementation"
| Fr -> "Implémentation de texte législatif"
| Pl -> "Implementacja tekstów legislacyjnych"
| Ro -> "Implementarea textului legislativ"

let literal_generated_by = function
| En -> "Document generated by"
| Fr -> "Document généré par"
| Pl -> "Dokument wygenerowany przez"
| Ro -> "Document generat de"

let literal_source_files = function
| En -> "Source files weaved in this document"
| Fr -> "Fichiers sources tissés dans ce document"
| Pl -> "Pliki źródłowe w tym dokumencie"
| Ro -> "Fișiere sursă integrate în acest document"

let literal_disclaimer_and_link = function
| En ->
Expand All @@ -52,16 +55,24 @@ let literal_disclaimer_and_link = function
legislacyjny z kodem komputerowym, który go tłumaczy. Więcej informacji \
na temat metodologii i sposobu odczytywania kodu można znaleźć na stronie \
[https://catala-lang.org](https://catala-lang.org)"
| Ro ->
"Acest document a fost produs dintr-un set de fișiere sursă scrise în \
limbajul de programare Catala, care combină textul legislativ cu codul \
informatic care îl traduce. Pentru mai multe informații despre \
metodologie și despre cum să citiți codul, vă rugăm să vizitați \
[https://catala-lang.org](https://catala-lang.org)."

let literal_last_modification = function
| En -> "last modification"
| Fr -> "dernière modification le"
| Pl -> "ostatnia modyfikacja"
| Ro -> "ultima modificare"

let get_language_extension = function
| Fr -> "catala_fr"
| En -> "catala_en"
| Pl -> "catala_pl"
| Ro -> "catala_ro"

let raise_failed_pandoc (command : string) (error_code : int) : 'a =
Message.error
Expand Down
1 change: 1 addition & 0 deletions compiler/literate/pygmentize.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ let lang_of_ext s =
| "catala_en" -> Some Global.En
| "catala_fr" -> Some Global.Fr
| "catala_pl" -> Some Global.Pl
| "catala_ro" -> Some Global.Ro
| _ -> failwith "Unknown Catala dialect"
else None

Expand Down
8 changes: 6 additions & 2 deletions compiler/plugins/explain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1210,8 +1210,12 @@ let expr_to_dot_label0 :
(a, 't) gexpr ->
unit =
fun lang ctx env ->
let xlang ~en ?(pl = en) ~fr () =
match lang with Global.Fr -> fr | Global.En -> en | Global.Pl -> pl
let xlang ~en ?(pl = en) ?(ro = en) ~fr () =
match lang with
| Global.Fr -> fr
| Global.En -> en
| Global.Pl -> pl
| Global.Ro -> ro
in
let rec aux_value : type a t. Format.formatter -> (a, t) gexpr -> unit =
fun ppf e -> Print.UserFacing.value ~fallback lang ppf e
Expand Down
17 changes: 12 additions & 5 deletions compiler/shared_ast/print.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1005,10 +1005,10 @@ module UserFacing = struct
https://en.wikipedia.org/wiki/Wikipedia:Manual_of_Style/Dates_and_numbers#Grouping_of_digits
https://fr.wikipedia.org/wiki/Wikip%C3%A9dia:Conventions_concernant_les_nombres#Pour_un_comptage_ou_une_mesure *)
let bigsep (lang : Global.backend_lang) =
match lang with En -> ",", 3 | Fr -> " ", 3 | Pl -> ",", 3
match lang with En -> ",", 3 | Fr -> " ", 3 | Pl -> ",", 3 | Ro -> ".", 3

let decsep (lang : Global.backend_lang) =
match lang with En -> "." | Fr -> "," | Pl -> "."
match lang with En -> "." | Fr -> "," | Pl -> "." | Ro -> ","

let unit (_lang : Global.backend_lang) ppf () =
Format.pp_print_string ppf "()"
Expand All @@ -1022,6 +1022,8 @@ module UserFacing = struct
| Fr, false -> "faux"
| Pl, true -> "prawda"
| Pl, false -> "falsz"
| Ro, true -> "adevărat"
| Ro, false -> "fals"
in
Format.pp_print_string ppf s

Expand All @@ -1042,14 +1044,17 @@ module UserFacing = struct
let num = Z.abs n in
let units, cents = Z.div_rem num (Z.of_int 100) in
if Z.sign n < 0 then Format.pp_print_char ppf '-';
(match lang with En -> Format.pp_print_string ppf "$" | Fr | Pl -> ());
(match lang with
| En -> Format.pp_print_string ppf "$"
| Fr | Pl | Ro -> ());
integer lang ppf units;
Format.pp_print_string ppf (decsep lang);
Format.fprintf ppf "%02d" (Z.to_int (Z.abs cents));
match lang with
| En -> ()
| Fr -> Format.pp_print_string ppf " €"
| Pl -> Format.pp_print_string ppf " PLN"
| Ro -> Format.pp_print_string ppf " RON"

let decimal (lang : Global.backend_lang) ppf r =
let den = Q.den r in
Expand Down Expand Up @@ -1094,7 +1099,7 @@ module UserFacing = struct
let y, m, d = Catala_runtime.date_to_years_months_days d in
match lang with
| En | Pl -> Format.fprintf ppf "%04d-%02d-%02d" y m d
| Fr -> Format.fprintf ppf "%02d/%02d/%04d" d m y
| Fr | Ro -> Format.fprintf ppf "%02d/%02d/%04d" d m y

let duration (lang : Global.backend_lang) ppf dr =
let y, m, d = Catala_runtime.duration_to_years_months_days dr in
Expand All @@ -1104,11 +1109,13 @@ module UserFacing = struct
| [] -> []
in
let splur n s = if abs n > 1 then n, s ^ "s" else n, s in
let ro_plur n s_sing s_plur = if abs n > 1 then n, s_plur else n, s_sing in
Format.pp_print_char ppf '[';
(match lang with
| En -> [splur y "year"; splur m "month"; splur d "day"]
| Fr -> [splur y "an"; m, "mois"; splur d "jour"]
| Pl -> [y, "rok"; m, "miesiac"; d, "dzien"])
| Pl -> [y, "rok"; m, "miesiac"; d, "dzien"]
| Ro -> [ro_plur y "an" "ani"; ro_plur m "lună" "luni"; ro_plur d "zi" "zile"])
|> filter0
|> Format.pp_print_list
~pp_sep:(fun ppf () -> Format.pp_print_string ppf ", ")
Expand Down
8 changes: 7 additions & 1 deletion compiler/surface/dune
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
((pps sedlex.ppx)
lexer_en
lexer_fr
lexer_pl))))
lexer_pl
lexer_ro))))

(rule
(copy ast.mli ast.ml))
Expand All @@ -27,6 +28,11 @@
lexer_pl.ml
(run %{bin:cppo} %{dep:lexer_pl.cppo.ml} %{dep:lexer.cppo.ml})))

(rule
(with-stdout-to
lexer_ro.ml
(run %{bin:cppo} %{dep:lexer_ro.cppo.ml} %{dep:lexer.cppo.ml})))

(menhir
(modules tokens)
(explain false)
Expand Down
Loading
Loading