package catala

  1. Overview
  2. Docs
Compiler and library for the literate programming language for tax code specification

Install

dune-project
 Dependency

Authors

Maintainers

Sources

1.0.0-alpha.tar.gz
md5=2615968670ac21b1d00386a9b04b3843
sha512=eff292fdd75012f26ce7b17020f5a8374eef37cd4dd6ba60338dfbe89fbcad3443d1b409e44c182b740da9f58dff7e76dcb8ddefe47f9b2b160666d1c6930143

doc/surface.html

Catala surface representation

This representation is the first in the compilation chain (see Architecture). Its purpose is to host the output of the Catala parser, before any transformations have been made.

The module describing the abstract syntax tree is:

  • Surface.Ast Abstract syntax tree built by the Catala parser

This representation can also be weaved into literate programming outputs using the literate programming modules.

Lexing

The lexing in the Catala compiler is done using sedlex, the modern OCaml lexer that offers full support for UTF-8. This support enables users of non-English languages to use their favorite diacritics and symbols in their code.

While the parser of Catala is unique, the lexer has a general structure in lexer.cppo.ml that is parametrised with the cppo macros defined for English, French and Polish in the respective lexer_*.cppo.ml.

Relevant modules:

Note that an additional, simplified "line-lexer" is also provided alongside the main one: it is faster and more resilient, and used by the build system to gather dependency and test information.

Parsing

The Catala compiler uses Menhir to perform its parsing.

Surface.Parser is the main file where the parser tokens and the grammar is declared. It is automatically translated into its parsing automata equivalent by Menhir.

In order to provide decent syntax error messages, the Catala compiler uses the novel error handling provided by Menhir and detailed in Section 11 of the Menhir manual.

A parser.messages source file has been manually annotated with custom error message for every potential erroneous state of the parser, and Menhir automatically generated the Surface.Parser_errors module containing the function linking the erroneous parser states to the custom error message.

To wrap it up, Surface.Parser_driver glues all the parsing and lexing together to perform the translation from source code to abstract syntax tree, with meaningful error messages.

Relevant modules:

On This Page
  1. Lexing
  2. Parsing