2020-04-16 18:47:35 +03:00
# Catala
2019-09-04 11:32:33 +03:00
2020-04-17 17:22:20 +03:00
Catala is a domain-specific language for deriving
faithful-by-construction algorithms from legislative texts.
2019-09-04 11:32:33 +03:00
2020-04-17 17:22:20 +03:00
## Concepts
Catala is a programming language adapted for socio-fiscal legislative literate programming. By annotating each line of the
legislative text with its meaning in terms of code, one can derive
an implementation of complex socio-fiscal mechanisms that enjoys
a high level of assurance regarding the code-law faithfulness.
Concretely, you have to first gather all the laws, executive orders, previous cases, etc. that contain information about the
socio-fiscal mechanism that you want to implement. Then, you can
proceed to annotate the text article by article, in your favorite
text editor :
2020-04-17 18:37:34 +03:00
![Screenshot ](https://github.com/CatalaLang/catala/raw/master/doc/ScreenShotAtom.png )
2020-04-17 17:22:20 +03:00
Once your code is complete and tested, you can use the Catala
compiler to produce a lawyer-readable PDF version of your
implementation. The Catala language has been specially designed
in collaboration with law professionals to ensure that the code
can be reviewed and certified correct by the domain experts, which
are in this case lawyers and not programmers.
2020-04-17 18:37:34 +03:00
![Screenshot ](https://github.com/CatalaLang/catala/raw/master/doc/CatalaScreenShot.png )
2020-04-17 17:22:20 +03:00
The Catala language is special because its logical structure mimics
the logical structure of the law. Indeed, the core concept of
"definition-under-conditions" that builds on default logic has been formalized by Professor of Law Sarah Lawsky in her article [A Logic for Statutes ](https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3088206 ). The Catala language is the only
programming language to our knowledge that embeds default logic
as a first-class feature, which is why it is the only language
perfectly adapted to literate legislative programming.
## Catala motivating example : French "allocations familiales"
In the `example/allocations_familiales` folder, you will find the
`allocations_familiales.catala` file which contains the
algorithm computing French family benefits. The algorithm consists of annotations to the legislative
texts that define the family benetifs, using the literate programming paradigm. The Catala
compiler can extract from the `.catala` file a lawyer-readable version of the annotated text.
Currently, this lawyer-readable version comes in the form of a LaTeX document.
You will need to have a standard LaTeX distribution installed as well as the
`latexmk` build tool in order to enjoy the automated document generation process.
To get that lawyer-readable version (which is a LaTeX-created) PDF, simply use
2020-04-20 10:05:40 +03:00
make allocations_familiales
2020-04-17 17:22:20 +03:00
from the repository root, once you have managed to install the
2020-04-19 16:53:35 +03:00
compiler (see below). You can then open `examples/allocations_familiales/allocations_familiales.pdf`
2020-04-17 17:22:20 +03:00
2020-04-27 11:04:13 +03:00
## Languages
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 lefislative text.
2020-05-06 11:37:00 +03:00
Currently, Catala supports English and French legislations via the `--language=en` or `--language=fr` option. Contact the authors
2020-04-27 11:04:13 +03:00
if you are interested in adding support for another language.
2020-04-17 17:22:20 +03:00
## Limitations and disclaimer
### Early stage project
Catala is a research project from Inria, the French National
Research Institute for Computer Science. The compiler is yet very
unstable and lacks most of its features. Currently, it only
parses the surface language to producde the lawyer-readable PDF,
no interpreter or compiler backend is provided.
However, the language is bound to have a complete formal semantics
in the near future. This semantics will guide the compiler
implementation.
## The Catala compiler
### OCaml requirements
2020-04-17 14:02:15 +03:00
The Catala compiler is written using OCaml. To install OCaml on your machine and
if you're running Linux ou MacOS, open a terminal and enter :
./install_opam.sh
2020-04-17 17:30:23 +03:00
This will install `opam` , the OCaml dependency manager and the
base OCaml compiler. If you're on Windows, the simplest solution
would be to use Cygwin or the Windows Subsystem for Linux.
2020-04-17 14:02:15 +03:00
Next, install all the build dependencies with
make install-dependencies
This should ensure everything is set up for developping on Catala !
### Installation
2019-09-04 11:32:33 +03:00
The project is distributed as a Dune artifact. Use standard dune commands to build
2020-05-13 11:25:39 +03:00
and install the library. Makefile aliases are here to help you: running
make build
builds the compiler from its OCaml sources.
#### Generating website assets
The Catala website features assets generated by the Catala compiler. They are
needed to build the website. To produce them, simply run from this repository's
root directory
./generate_website_assets.sh < path-to-catala-website > /assets
#### Opam package
If you want to install the library as an opam
2019-09-04 12:02:49 +03:00
package, use the following command at the root of the repository:
opam install ./
2020-04-16 18:47:35 +03:00
You can then can the compiler using the `catala` command.
2020-03-08 08:54:35 +03:00
2020-04-17 14:02:15 +03:00
### Usage
2020-03-08 08:54:35 +03:00
2020-04-16 18:47:35 +03:00
Use `catala --help` to get more information about the command line options available.
2020-03-08 08:54:35 +03:00
2020-04-17 14:02:15 +03:00
## Syntax highlighting
The Catala language also comes with syntax highlighting to
ease program development. The syntax highlighting is done
with the [Iro ](https://eeyo.io/iro/ ) compiler that allows
writing the syntax only once, and then export it to formats
understood by various IDE. Currently, two syntax
highlighting plugins are under version control.
### Atom
To get Catala syntax highlighting in Atom, simply enter from
2020-04-27 11:04:13 +03:00
the root of the repository, depending on the language you want to use :
make atom_fr
or
2020-04-17 14:02:15 +03:00
2020-04-27 11:04:13 +03:00
make atom_en
2020-03-08 08:54:35 +03:00
2020-04-17 14:02:15 +03:00
You can now reload Atom and check that you have syntax highlighting on any `.catala` file.
### Pygments
Pygments is a Python-based versatile lexer for various
programming languages. To use a version of Pygments
2020-04-27 11:04:13 +03:00
augmented with the Catala plugin, you need to enter from the root of the repository
2020-04-17 14:02:15 +03:00
2020-04-27 11:04:13 +03:00
make pygments
This will execute the
script `syntax_highlighting/fr/pygments/set_up_pygments.sh` and `syntax_highlighting/en/pygments/set_up_pygments.sh` .
These scripts assumes a `python3` executable on tour machine,
2020-04-17 14:02:15 +03:00
as well as the `virtualenv` package which you can install
using `python3 -m pip install virtualenv` .
2020-04-27 11:04:13 +03:00
The scripts set up a virtual environement in `syntax_highlighting/fr/pygments/pygments/env` or `syntax_highlighting/en/pygments/pygments/env` , which will
2020-04-17 14:02:15 +03:00
contain the modified version of Pygments that has Catala
support. You can use this virtual environnement with
2020-04-27 11:04:13 +03:00
source syntax_highlighting/fr/pygments/pygments/env/bin/activate
or
source syntax_highlighting/en/pygments/pygments/env/bin/activate
2020-04-17 14:02:15 +03:00
2020-04-17 16:28:34 +03:00
The `pigmentize` executable, used for instance by the `minted` LaTeX package,
will now point to the Catala-enabled version inside the virtual environment.
2020-04-17 17:22:20 +03:00
## Contributing
2020-04-17 14:02:15 +03:00
2020-04-17 17:22:20 +03:00
The project accepts pull requests. Please email the authors
if you are interested, whether you are a law professional, a
computer scientist or a developer. Please use this email address :
2020-04-17 14:02:15 +03:00
2020-04-17 17:22:20 +03:00
denis DOT merigoux AT inria DOT fr
2020-04-17 14:02:15 +03:00
2020-04-17 17:22:20 +03:00
Please note that the copyright of this code is owned by Inria;
by contributing, you disclaim all copyright interests in favor of Inria.
2019-09-04 11:32:33 +03:00
## License
The library is released under the Apache license (version 2).
2020-04-16 19:58:05 +03:00
## Pierre Catala
The language is named after Pierre Catala, a professor of law who
pionneered the French legaltech by creating a computer database of law cases,
Juris-Data. The research group that he led in the late 1960s, the
Centre d’ études et de traitement de l’ information juridique (CETIJ),
has also influenced the creation by state conselor Lucien Mehl of the
Centre de recherches et développement en informatique juridique (CENIJ),
which eventually transformed into the entity managing the LegiFrance website,
2020-04-17 14:02:15 +03:00
acting as the public service of legislative documentation.