package catala

  1. Overview
  2. Docs

Abstract syntax tree built by the Catala parser

Type definitions

type constructor = string

Constructors are CamelCase

type ident = string

Idents are snake_case

type qident = ident Utils.Pos.marked list
type primitive_typ =
  1. | Integer
  2. | Decimal
  3. | Boolean
  4. | Money
  5. | Duration
  6. | Text
  7. | Date
  8. | Named of constructor
type base_typ_data =
  1. | Primitive of primitive_typ
  2. | Collection of base_typ_data Utils.Pos.marked
type base_typ =
  1. | Condition
  2. | Data of base_typ_data
type func_typ = {
  1. arg_typ : base_typ Utils.Pos.marked;
  2. return_typ : base_typ Utils.Pos.marked;
}
type typ =
  1. | Base of base_typ
  2. | Func of func_typ
type struct_decl_field = {
  1. struct_decl_field_name : ident Utils.Pos.marked;
  2. struct_decl_field_typ : typ Utils.Pos.marked;
}
type struct_decl = {
  1. struct_decl_name : constructor Utils.Pos.marked;
  2. struct_decl_fields : struct_decl_field Utils.Pos.marked list;
}
type enum_decl_case = {
  1. enum_decl_case_name : constructor Utils.Pos.marked;
  2. enum_decl_case_typ : typ Utils.Pos.marked option;
}
type enum_decl = {
  1. enum_decl_name : constructor Utils.Pos.marked;
  2. enum_decl_cases : enum_decl_case Utils.Pos.marked list;
}
type match_case_pattern = (constructor Utils.Pos.marked option * constructor Utils.Pos.marked) list * ident Utils.Pos.marked option
type op_kind =
  1. | KInt
    (*

    No suffix

    *)
  2. | KDec
    (*

    Suffix: .

    *)
  3. | KMoney
    (*

    Suffix: $

    *)
  4. | KDate
    (*

    Suffix: @

    *)
  5. | KDuration
    (*

    Suffix: ^

    *)
type binop =
  1. | And
  2. | Or
  3. | Add of op_kind
  4. | Sub of op_kind
  5. | Mult of op_kind
  6. | Div of op_kind
  7. | Lt of op_kind
  8. | Lte of op_kind
  9. | Gt of op_kind
  10. | Gte of op_kind
  11. | Eq
  12. | Neq
type unop =
  1. | Not
  2. | Minus of op_kind
type builtin_expression =
  1. | Cardinal
  2. | IntToDec
  3. | GetDay
  4. | GetMonth
  5. | GetYear
type literal_date = {
  1. literal_date_day : int Utils.Pos.marked;
  2. literal_date_month : int Utils.Pos.marked;
  3. literal_date_year : int Utils.Pos.marked;
}
type literal_number =
  1. | Int of Runtime.integer
  2. | Dec of Runtime.integer * Runtime.integer
type literal_unit =
  1. | Percent
  2. | Year
  3. | Month
  4. | Day
type money_amount = {
  1. money_amount_units : Runtime.integer;
  2. money_amount_cents : Runtime.integer;
}
type literal =
  1. | LNumber of literal_number Utils.Pos.marked * literal_unit Utils.Pos.marked option
  2. | LBool of bool
  3. | LMoneyAmount of money_amount
  4. | LDate of literal_date
type aggregate_func =
  1. | AggregateSum of primitive_typ
  2. | AggregateCount
  3. | AggregateExtremum of bool * primitive_typ * expression Utils.Pos.marked
  4. | AggregateArgExtremum of bool * primitive_typ * expression Utils.Pos.marked
and collection_op =
  1. | Exists
  2. | Forall
  3. | Aggregate of aggregate_func
  4. | Map
  5. | Filter
and match_case = {
  1. match_case_pattern : match_case_pattern Utils.Pos.marked;
  2. match_case_expr : expression Utils.Pos.marked;
}
and match_cases = match_case Utils.Pos.marked list
type exception_to =
  1. | NotAnException
  2. | UnlabeledException
  3. | ExceptionToLabel of ident Utils.Pos.marked
type rule = {
  1. rule_label : ident Utils.Pos.marked option;
  2. rule_exception_to : exception_to;
  3. rule_parameter : ident Utils.Pos.marked option;
  4. rule_condition : expression Utils.Pos.marked option;
  5. rule_name : qident Utils.Pos.marked;
  6. rule_consequence : bool Utils.Pos.marked;
}
type definition = {
  1. definition_label : ident Utils.Pos.marked option;
  2. definition_exception_to : exception_to;
  3. definition_name : qident Utils.Pos.marked;
  4. definition_parameter : ident Utils.Pos.marked option;
  5. definition_condition : expression Utils.Pos.marked option;
  6. definition_expr : expression Utils.Pos.marked;
}
type variation_typ =
  1. | Increasing
  2. | Decreasing
type assertion = {
  1. assertion_condition : expression Utils.Pos.marked option;
  2. assertion_content : expression Utils.Pos.marked;
}
type scope_use_item =
  1. | Rule of rule
  2. | Definition of definition
  3. | Assertion of assertion
  4. | MetaAssertion of meta_assertion
type scope_use = {
  1. scope_use_condition : expression Utils.Pos.marked option;
  2. scope_use_name : constructor Utils.Pos.marked;
  3. scope_use_items : scope_use_item Utils.Pos.marked list;
}
type scope_decl_context_scope = {
  1. scope_decl_context_scope_name : ident Utils.Pos.marked;
  2. scope_decl_context_scope_sub_scope : constructor Utils.Pos.marked;
}
type scope_decl_context_data = {
  1. scope_decl_context_item_name : ident Utils.Pos.marked;
  2. scope_decl_context_item_typ : typ Utils.Pos.marked;
}
type scope_decl_context_item =
  1. | ContextData of scope_decl_context_data
  2. | ContextScope of scope_decl_context_scope
type scope_decl = {
  1. scope_decl_name : constructor Utils.Pos.marked;
  2. scope_decl_context : scope_decl_context_item Utils.Pos.marked list;
}
type code_item =
  1. | ScopeUse of scope_use
  2. | ScopeDecl of scope_decl
  3. | StructDecl of struct_decl
  4. | EnumDecl of enum_decl
type code_block = code_item Utils.Pos.marked list
type source_repr = string Utils.Pos.marked
type law_article = {
  1. law_article_name : string Utils.Pos.marked;
  2. law_article_id : string option;
  3. law_article_expiration_date : string option;
  4. law_article_precedence : int;
}
type law_include =
  1. | PdfFile of string Utils.Pos.marked * int option
  2. | CatalaFile of string Utils.Pos.marked
  3. | LegislativeText of string Utils.Pos.marked
type law_article_item =
  1. | LawText of string
  2. | CodeBlock of code_block * source_repr
type law_heading = {
  1. law_heading_name : string;
  2. law_heading_precedence : int;
}
type law_structure =
  1. | LawInclude of law_include
  2. | LawHeading of law_heading * law_structure list
  3. | LawArticle of law_article * law_article_item list
  4. | MetadataBlock of code_block * source_repr
  5. | IntermediateText of string
type program_item =
  1. | LawStructure of law_structure
type program = {
  1. program_items : program_item list;
  2. program_source_files : string list;
}
type source_file_or_master =
  1. | SourceFile of program_item list
  2. | MasterFile of string Utils.Pos.marked list

Visitor classes for programs

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.

Program map visitor

class virtual 'self program_map : object ... end

Program iter visitor

class virtual 'self program_iter : object ... end