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

and lident = string

Idents are snake_case

and scope_var = lident Catala_utils.Mark.pos list

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

and primitive_typ =
  1. | Integer
  2. | Decimal
  3. | Boolean
  4. | Money
  5. | Duration
  6. | Text
  7. | Date
  8. | Named of path * uident Catala_utils.Mark.pos
and base_typ_data =
  1. | Primitive of primitive_typ
  2. | Collection of base_typ_data Catala_utils.Mark.pos
  3. | TTuple of base_typ_data Catala_utils.Mark.pos list
and base_typ =
  1. | Condition
  2. | Data of base_typ_data
and naked_typ =
  1. | Base of base_typ
  2. | Func of func_typ
and struct_decl_field = {
  1. struct_decl_field_name : lident Catala_utils.Mark.pos;
  2. struct_decl_field_typ : typ;
}
and struct_decl = {
  1. struct_decl_name : uident Catala_utils.Mark.pos;
  2. struct_decl_fields : struct_decl_field Catala_utils.Mark.pos list;
}
and enum_decl_case = {
  1. enum_decl_case_name : uident Catala_utils.Mark.pos;
  2. enum_decl_case_typ : typ option;
}
and enum_decl = {
  1. enum_decl_name : uident Catala_utils.Mark.pos;
  2. enum_decl_cases : enum_decl_case Catala_utils.Mark.pos list;
}
and op_kind =
  1. | KPoly
  2. | KInt
  3. | KDec
  4. | KMoney
  5. | KDate
  6. | KDuration
and 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
and unop =
  1. | Not
  2. | Minus of op_kind
and builtin_expression =
  1. | Cardinal
  2. | ToDecimal
  3. | ToMoney
  4. | GetDay
  5. | GetMonth
  6. | GetYear
  7. | LastDayOfMonth
  8. | FirstDayOfMonth
  9. | Round
and literal_date = {
  1. literal_date_day : int;
  2. literal_date_month : int;
  3. literal_date_year : int;
}
and literal_number =
  1. | Int of string
  2. | Dec of string * string
and literal_unit =
  1. | Percent
  2. | Year
  3. | Month
  4. | Day
and money_amount = {
  1. money_amount_units : string;
  2. money_amount_cents : string;
}
and literal =
  1. | LNumber of literal_number Catala_utils.Mark.pos * literal_unit Catala_utils.Mark.pos option
  2. | LBool of bool
  3. | LMoneyAmount of money_amount
  4. | LDate of literal_date
and collection_op =
  1. | Exists of {
    1. predicate : lident Catala_utils.Mark.pos * expression;
    }
  2. | Forall of {
    1. predicate : lident Catala_utils.Mark.pos * expression;
    }
  3. | Map of {
    1. f : lident Catala_utils.Mark.pos * expression;
    }
  4. | Filter of {
    1. f : lident Catala_utils.Mark.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.Mark.pos * expression;
    }
and explicit_match_case = {
  1. match_case_pattern : match_case_pattern Catala_utils.Mark.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.Mark.pos list
and naked_expression =
  1. | Paren of expression
  2. | MatchWith of expression * match_cases Catala_utils.Mark.pos
  3. | IfThenElse of expression * expression * expression
  4. | Binop of binop Catala_utils.Mark.pos * expression * expression
  5. | Unop of unop Catala_utils.Mark.pos * expression
  6. | CollectionOp of collection_op * expression
  7. | MemCollection of expression * expression
  8. | TestMatchCase of expression * match_case_pattern Catala_utils.Mark.pos
  9. | FunCall of expression * expression list
  10. | ScopeCall of (path * uident Catala_utils.Mark.pos) Catala_utils.Mark.pos * (lident Catala_utils.Mark.pos * expression) list
  11. | LetIn of lident Catala_utils.Mark.pos list * expression * expression
  12. | Builtin of builtin_expression
  13. | Literal of literal
  14. | EnumInject of (path * uident Catala_utils.Mark.pos) Catala_utils.Mark.pos * expression option
  15. | StructLit of (path * uident Catala_utils.Mark.pos) Catala_utils.Mark.pos * (lident Catala_utils.Mark.pos * expression) list
  16. | ArrayLit of expression list
  17. | Tuple of expression list
  18. | Ident of path * lident Catala_utils.Mark.pos
  19. | Dotted of expression * (path * lident Catala_utils.Mark.pos) Catala_utils.Mark.pos
    (*

    Dotted is for both struct field projection and sub-scope variables

    *)
and exception_to =
  1. | NotAnException
  2. | UnlabeledException
  3. | ExceptionToLabel of lident Catala_utils.Mark.pos
and rule = {
  1. rule_label : lident Catala_utils.Mark.pos option;
  2. rule_exception_to : exception_to;
  3. rule_parameter : lident Catala_utils.Mark.pos list Catala_utils.Mark.pos option;
  4. rule_condition : expression option;
  5. rule_name : scope_var Catala_utils.Mark.pos;
  6. rule_id : Shared_ast.RuleName.t;
  7. rule_consequence : bool Catala_utils.Mark.pos;
  8. rule_state : lident Catala_utils.Mark.pos option;
}
and definition = {
  1. definition_label : lident Catala_utils.Mark.pos option;
  2. definition_exception_to : exception_to;
  3. definition_name : scope_var Catala_utils.Mark.pos;
  4. definition_parameter : lident Catala_utils.Mark.pos list Catala_utils.Mark.pos option;
  5. definition_condition : expression option;
  6. definition_id : Shared_ast.RuleName.t;
  7. definition_expr : expression;
  8. definition_state : lident Catala_utils.Mark.pos option;
}
and variation_typ =
  1. | Increasing
  2. | Decreasing
and assertion = {
  1. assertion_condition : expression option;
  2. assertion_content : expression;
}
and scope_use_item =
  1. | Rule of rule
  2. | Definition of definition
  3. | Assertion of assertion
  4. | MetaAssertion of meta_assertion
  5. | DateRounding of variation_typ Catala_utils.Mark.pos
and scope_use = {
  1. scope_use_condition : expression option;
  2. scope_use_name : uident Catala_utils.Mark.pos;
  3. scope_use_items : scope_use_item Catala_utils.Mark.pos list;
}
and io_input =
  1. | Input
  2. | Context
  3. | Internal
and scope_decl_context_io = {
  1. scope_decl_context_io_input : io_input Catala_utils.Mark.pos;
  2. scope_decl_context_io_output : bool Catala_utils.Mark.pos;
}
and scope_decl_context_scope = {
  1. scope_decl_context_scope_name : lident Catala_utils.Mark.pos;
  2. scope_decl_context_scope_sub_scope : (path * uident Catala_utils.Mark.pos) Catala_utils.Mark.pos;
  3. scope_decl_context_scope_attribute : scope_decl_context_io;
}
and scope_decl_context_data = {
  1. scope_decl_context_item_name : lident Catala_utils.Mark.pos;
  2. scope_decl_context_item_typ : typ;
  3. scope_decl_context_item_parameters : (lident Catala_utils.Mark.pos * typ) list Catala_utils.Mark.pos option;
  4. scope_decl_context_item_attribute : scope_decl_context_io;
  5. scope_decl_context_item_states : lident Catala_utils.Mark.pos list;
}
and scope_decl_context_item =
  1. | ContextData of scope_decl_context_data
  2. | ContextScope of scope_decl_context_scope
and scope_decl = {
  1. scope_decl_name : uident Catala_utils.Mark.pos;
  2. scope_decl_context : scope_decl_context_item Catala_utils.Mark.pos list;
}
and top_def = {
  1. topdef_name : lident Catala_utils.Mark.pos;
  2. topdef_args : (lident Catala_utils.Mark.pos * base_typ Catala_utils.Mark.pos) list Catala_utils.Mark.pos option;
    (*

    Empty list if this is not a function

    *)
  3. topdef_type : typ;
  4. topdef_expr : expression option;
}
and 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
and code_block = code_item Catala_utils.Mark.pos list
and source_repr = string Catala_utils.Mark.pos
and law_heading = {
  1. law_heading_name : string Catala_utils.Mark.pos;
  2. law_heading_id : string option;
  3. law_heading_is_archive : bool;
  4. law_heading_precedence : int;
}
and law_include =
  1. | PdfFile of string Catala_utils.Mark.pos * int option
  2. | CatalaFile of string Catala_utils.Mark.pos
  3. | LegislativeText of string Catala_utils.Mark.pos
and law_structure =
  1. | LawInclude of law_include
  2. | ModuleDef of uident Catala_utils.Mark.pos * bool
  3. | ModuleUse of uident Catala_utils.Mark.pos * uident Catala_utils.Mark.pos option
  4. | LawHeading of law_heading * law_structure list
  5. | LawText of string
  6. | CodeBlock of code_block * source_repr * bool
and interface = {
  1. intf_modname : uident Catala_utils.Mark.pos;
  2. intf_code : code_block;
    (*

    Invariant: an interface shall only contain *Decl elements, or Topdef elements with topdef_expr = None

    *)
  3. intf_submodules : module_use list;
}
and module_use = {
  1. mod_use_name : uident Catala_utils.Mark.pos;
  2. mod_use_alias : uident Catala_utils.Mark.pos;
}
and program = {
  1. program_module_name : uident Catala_utils.Mark.pos option;
  2. program_items : law_structure list;
  3. program_source_files : string list;
  4. program_used_modules : module_use list;
  5. program_lang : Catala_utils.Cli.backend_lang;
}
and source_file = law_structure list
include sig ... end
class virtual +'b map : object ... end

Helpers

val rule_to_def : rule -> definition

Translates a rule into the corresponding definition