package catala

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Abstract syntax tree built by the Catala parser

To allow for quick traversal and/or modification of this AST structure, we provide a visitor design pattern. This feature is implemented via François Pottier's OCaml visitors library.

Type definitions

type uident = string

Constructors are CamelCase

include sig ... end
class virtual +'a uident_map : object ... end
include sig ... end
class virtual +'a uident_iter : object ... end
type lident = string

Idents are snake_case

include sig ... end
class virtual +'a lident_map : object ... end
include sig ... end
class virtual +'a lident_iter : object ... end
include sig ... end
class virtual +'b path_map : object ... end
include sig ... end
class virtual +'b path_iter : object ... end
type scope_var = lident Catala_utils.Marked.pos list

foo.bar in binding position: used to specify variables of subscopes

include sig ... end
class virtual +'b scope_var_map : object ... end
include sig ... end
class virtual +'b scope_var_iter : object ... end
type primitive_typ =
  1. | Integer
  2. | Decimal
  3. | Boolean
  4. | Money
  5. | Duration
  6. | Text
  7. | Date
  8. | Named of path * uident Catala_utils.Marked.pos
include sig ... end
class virtual +'b primitive_typ_map : object ... end
include sig ... end
class virtual +'b primitive_typ_iter : object ... end
type base_typ_data =
  1. | Primitive of primitive_typ
  2. | Collection of base_typ_data Catala_utils.Marked.pos
include sig ... end
class virtual +'b base_typ_data_map : object ... end
include sig ... end
class virtual +'b base_typ_data_iter : object ... end
type base_typ =
  1. | Condition
  2. | Data of base_typ_data
include sig ... end
class virtual +'b base_typ_map : object ... end
include sig ... end
class virtual +'b base_typ_iter : object ... end
include sig ... end
class virtual +'b func_typ_map : object ... end
include sig ... end
class virtual +'b func_typ_iter : object ... end
and naked_typ =
  1. | Base of base_typ
  2. | Func of func_typ
include sig ... end
class virtual +'b typ_map : object ... end
include sig ... end
class virtual +'b typ_iter : object ... end
type struct_decl_field = {
  1. struct_decl_field_name : lident Catala_utils.Marked.pos;
  2. struct_decl_field_typ : typ;
}
include sig ... end
class virtual +'b struct_decl_field_map : object ... end
include sig ... end
class virtual +'b struct_decl_field_iter : object ... end
type struct_decl = {
  1. struct_decl_name : uident Catala_utils.Marked.pos;
  2. struct_decl_fields : struct_decl_field Catala_utils.Marked.pos list;
}
include sig ... end
class virtual +'b struct_decl_map : object ... end
include sig ... end
class virtual +'b struct_decl_iter : object ... end
type enum_decl_case = {
  1. enum_decl_case_name : uident Catala_utils.Marked.pos;
  2. enum_decl_case_typ : typ option;
}
include sig ... end
class virtual +'b enum_decl_case_map : object ... end
include sig ... end
class virtual +'b enum_decl_case_iter : object ... end
type enum_decl = {
  1. enum_decl_name : uident Catala_utils.Marked.pos;
  2. enum_decl_cases : enum_decl_case Catala_utils.Marked.pos list;
}
include sig ... end
class virtual +'b enum_decl_map : object ... end
include sig ... end
class virtual +'b enum_decl_iter : object ... end
include sig ... end
class virtual +'b match_case_pattern_map : object ... end
include sig ... end
class virtual +'b match_case_pattern_iter : object ... end
type op_kind =
  1. | KPoly
  2. | KInt
  3. | KDec
  4. | KMoney
  5. | KDate
  6. | KDuration
include sig ... end
class virtual +'a op_kind_map : object ... end
include sig ... end
class virtual +'a op_kind_iter : object ... end
type binop =
  1. | And
  2. | Or
  3. | Xor
  4. | Add of op_kind
  5. | Sub of op_kind
  6. | Mult of op_kind
  7. | Div of op_kind
  8. | Lt of op_kind
  9. | Lte of op_kind
  10. | Gt of op_kind
  11. | Gte of op_kind
  12. | Eq
  13. | Neq
  14. | Concat
include sig ... end
class virtual +'a binop_map : object ... end
include sig ... end
class virtual +'a binop_iter : object ... end
type unop =
  1. | Not
  2. | Minus of op_kind
include sig ... end
class virtual +'a unop_map : object ... end
include sig ... end
class virtual +'a unop_iter : object ... end
type builtin_expression =
  1. | Cardinal
  2. | ToDecimal
  3. | ToMoney
  4. | GetDay
  5. | GetMonth
  6. | GetYear
  7. | LastDayOfMonth
  8. | FirstDayOfMonth
  9. | Round
include sig ... end
class virtual +'a builtin_expression_map : object ... end
include sig ... end
class virtual +'a builtin_expression_iter : object ... end
type literal_date = {
  1. literal_date_day : int;
  2. literal_date_month : int;
  3. literal_date_year : int;
}
include sig ... end
class virtual +'b literal_date_map : object ... end
include sig ... end
class virtual +'b literal_date_iter : object ... end
type literal_number =
  1. | Int of string
  2. | Dec of string * string
include sig ... end
class virtual +'a literal_number_map : object ... end
include sig ... end
class virtual +'a literal_number_iter : object ... end
type literal_unit =
  1. | Percent
  2. | Year
  3. | Month
  4. | Day
include sig ... end
class virtual +'a literal_unit_map : object ... end
include sig ... end
class virtual +'a literal_unit_iter : object ... end
type money_amount = {
  1. money_amount_units : string;
  2. money_amount_cents : string;
}
include sig ... end
class virtual +'a money_amount_map : object ... end
include sig ... end
class virtual +'a money_amount_iter : object ... end
type literal =
  1. | LNumber of literal_number Catala_utils.Marked.pos * literal_unit Catala_utils.Marked.pos option
  2. | LBool of bool
  3. | LMoneyAmount of money_amount
  4. | LDate of literal_date
include sig ... end
class virtual +'b literal_map : object ... end
include sig ... end
class virtual +'b literal_iter : object ... end
type collection_op =
  1. | Exists of {
    1. predicate : lident Catala_utils.Marked.pos * expression;
    }
  2. | Forall of {
    1. predicate : lident Catala_utils.Marked.pos * expression;
    }
  3. | Map of {
    1. f : lident Catala_utils.Marked.pos * expression;
    }
  4. | Filter of {
    1. f : lident Catala_utils.Marked.pos * expression;
    }
  5. | AggregateSum of {
    1. typ : primitive_typ;
    }
  6. | AggregateExtremum of {
    1. max : bool;
    2. default : expression;
    }
  7. | AggregateArgExtremum of {
    1. max : bool;
    2. default : expression;
    3. f : lident Catala_utils.Marked.pos * expression;
    }
and explicit_match_case = {
  1. match_case_pattern : match_case_pattern Catala_utils.Marked.pos;
  2. match_case_expr : expression;
}
and match_case =
  1. | WildCard of expression
  2. | MatchCase of explicit_match_case
and match_cases = match_case Catala_utils.Marked.pos list
include sig ... end
class virtual +'b expression_map : object ... end
include sig ... end
class virtual +'b expression_iter : object ... end
type exception_to =
  1. | NotAnException
  2. | UnlabeledException
  3. | ExceptionToLabel of lident Catala_utils.Marked.pos
include sig ... end
class virtual +'b exception_to_map : object ... end
include sig ... end
class virtual +'b exception_to_iter : object ... end
type rule = {
  1. rule_label : lident Catala_utils.Marked.pos option;
  2. rule_exception_to : exception_to;
  3. rule_parameter : lident Catala_utils.Marked.pos list Catala_utils.Marked.pos option;
  4. rule_condition : expression option;
  5. rule_name : scope_var Catala_utils.Marked.pos;
  6. rule_id : Shared_ast.RuleName.t;
  7. rule_consequence : bool Catala_utils.Marked.pos;
  8. rule_state : lident Catala_utils.Marked.pos option;
}
include sig ... end
class virtual +'b rule_map : object ... end
include sig ... end
class virtual +'b rule_iter : object ... end
type definition = {
  1. definition_label : lident Catala_utils.Marked.pos option;
  2. definition_exception_to : exception_to;
  3. definition_name : scope_var Catala_utils.Marked.pos;
  4. definition_parameter : lident Catala_utils.Marked.pos list Catala_utils.Marked.pos option;
  5. definition_condition : expression option;
  6. definition_id : Shared_ast.RuleName.t;
  7. definition_expr : expression;
  8. definition_state : lident Catala_utils.Marked.pos option;
}
include sig ... end
class virtual +'b definition_map : object ... end
include sig ... end
class virtual +'b definition_iter : object ... end
type variation_typ =
  1. | Increasing
  2. | Decreasing
include sig ... end
class virtual +'a variation_typ_map : object ... end
include sig ... end
class virtual +'a variation_typ_iter : object ... end
include sig ... end
class virtual +'b meta_assertion_map : object ... end
include sig ... end
class virtual +'b meta_assertion_iter : object ... end
type assertion = {
  1. assertion_condition : expression option;
  2. assertion_content : expression;
}
include sig ... end
class virtual +'b assertion_map : object ... end
include sig ... end
class virtual +'b assertion_iter : object ... end
type scope_use_item =
  1. | Rule of rule
  2. | Definition of definition
  3. | Assertion of assertion
  4. | MetaAssertion of meta_assertion
include sig ... end
class virtual +'b scope_use_item_map : object ... end
include sig ... end
class virtual +'b scope_use_item_iter : object ... end
type scope_use = {
  1. scope_use_condition : expression option;
  2. scope_use_name : uident Catala_utils.Marked.pos;
  3. scope_use_items : scope_use_item Catala_utils.Marked.pos list;
}
include sig ... end
class virtual +'b scope_use_map : object ... end
include sig ... end
class virtual +'b scope_use_iter : object ... end
type io_input =
  1. | Input
  2. | Context
  3. | Internal
include sig ... end
class virtual +'a io_input_map : object ... end
include sig ... end
class virtual +'a io_input_iter : object ... end
type scope_decl_context_io = {
  1. scope_decl_context_io_input : io_input Catala_utils.Marked.pos;
  2. scope_decl_context_io_output : bool Catala_utils.Marked.pos;
}
include sig ... end
class virtual +'b scope_decl_context_io_map : object ... end
include sig ... end
class virtual +'b scope_decl_context_io_iter : object ... end
type scope_decl_context_scope = {
  1. scope_decl_context_scope_name : lident Catala_utils.Marked.pos;
  2. scope_decl_context_scope_sub_scope : uident Catala_utils.Marked.pos;
  3. scope_decl_context_scope_attribute : scope_decl_context_io;
}
include sig ... end
class virtual +'b scope_decl_context_scope_map : object ... end
include sig ... end
class virtual +'b scope_decl_context_scope_iter : object ... end
type scope_decl_context_data = {
  1. scope_decl_context_item_name : lident Catala_utils.Marked.pos;
  2. scope_decl_context_item_typ : typ;
  3. scope_decl_context_item_parameters : (lident Catala_utils.Marked.pos * typ) list Catala_utils.Marked.pos option;
  4. scope_decl_context_item_attribute : scope_decl_context_io;
  5. scope_decl_context_item_states : lident Catala_utils.Marked.pos list;
}
include sig ... end
class virtual +'b scope_decl_context_data_map : object ... end
include sig ... end
class virtual +'b scope_decl_context_data_iter : object ... end
type scope_decl_context_item =
  1. | ContextData of scope_decl_context_data
  2. | ContextScope of scope_decl_context_scope
include sig ... end
class virtual +'b scope_decl_context_item_map : object ... end
include sig ... end
class virtual +'b scope_decl_context_item_iter : object ... end
type scope_decl = {
  1. scope_decl_name : uident Catala_utils.Marked.pos;
  2. scope_decl_context : scope_decl_context_item Catala_utils.Marked.pos list;
}
include sig ... end
class virtual +'b scope_decl_map : object ... end
include sig ... end
class virtual +'b scope_decl_iter : object ... end
type top_def = {
  1. topdef_name : lident Catala_utils.Marked.pos;
  2. topdef_args : (lident Catala_utils.Marked.pos * base_typ Catala_utils.Marked.pos) list Catala_utils.Marked.pos option;
    (*

    Empty list if this is not a function

    *)
  3. topdef_type : typ;
  4. topdef_expr : expression;
}
include sig ... end
class virtual +'b top_def_map : object ... end
include sig ... end
class virtual +'b top_def_iter : object ... end
type code_item =
  1. | ScopeUse of scope_use
  2. | ScopeDecl of scope_decl
  3. | StructDecl of struct_decl
  4. | EnumDecl of enum_decl
  5. | Topdef of top_def
include sig ... end
class virtual +'b code_item_map : object ... end
include sig ... end
class virtual +'b code_item_iter : object ... end
type code_block = code_item Catala_utils.Marked.pos list
include sig ... end
class virtual +'b code_block_map : object ... end
include sig ... end
class virtual +'b code_block_iter : object ... end
type source_repr = string Catala_utils.Marked.pos
include sig ... end
class virtual +'b source_repr_map : object ... end
include sig ... end
class virtual +'b source_repr_iter : object ... end
type law_heading = {
  1. law_heading_name : string Catala_utils.Marked.pos;
  2. law_heading_id : string option;
  3. law_heading_is_archive : bool;
  4. law_heading_precedence : int;
}
include sig ... end
class virtual +'b law_heading_map : object ... end
include sig ... end
class virtual +'b law_heading_iter : object ... end
type law_include =
  1. | PdfFile of string Catala_utils.Marked.pos * int option
  2. | CatalaFile of string Catala_utils.Marked.pos
  3. | LegislativeText of string Catala_utils.Marked.pos
include sig ... end
class virtual +'b law_include_map : object ... end
include sig ... end
class virtual +'b law_include_iter : object ... end
type law_structure =
  1. | LawInclude of law_include
  2. | LawHeading of law_heading * law_structure list
  3. | LawText of string
  4. | CodeBlock of code_block * source_repr * bool
include sig ... end
class virtual +'b law_structure_map : object ... end
include sig ... end
class virtual +'b law_structure_iter : object ... end
type program = {
  1. program_items : law_structure list;
  2. program_source_files : string list;
}
include sig ... end
class virtual +'b program_map : object ... end
include sig ... end
class virtual +'b program_iter : object ... end
type source_file = law_structure list

Helpers

val rule_to_def : rule -> definition

Translates a rule into the corresponding definition

OCaml

Innovation. Community. Security.