Module Surface.Ast

Abstract syntax tree built by the Catala parser

Type definitions

type uident = string

Constructors are CamelCase

type lident = string

Idents are snake_case

type path = uident Catala_utils.Mark.pos list
type scope_var = lident Catala_utils.Mark.pos list

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

type 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
type 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
type base_typ =
  1. | Condition
  2. | Data of base_typ_data
and naked_typ =
  1. | Base of base_typ
  2. | Func of func_typ
type struct_decl_field = {
  1. struct_decl_field_name : lident Catala_utils.Mark.pos;
  2. struct_decl_field_typ : typ;
}
type struct_decl = {
  1. struct_decl_name : uident Catala_utils.Mark.pos;
  2. struct_decl_fields : struct_decl_field Catala_utils.Mark.pos list;
}
type enum_decl_case = {
  1. enum_decl_case_name : uident Catala_utils.Mark.pos;
  2. enum_decl_case_typ : typ option;
}
type enum_decl = {
  1. enum_decl_name : uident Catala_utils.Mark.pos;
  2. enum_decl_cases : enum_decl_case Catala_utils.Mark.pos list;
}
type op_kind =
  1. | KPoly
  2. | KInt
  3. | KDec
  4. | KMoney
  5. | KDate
  6. | KDuration
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
type unop =
  1. | Not
  2. | Minus of op_kind
type builtin_expression =
  1. | Cardinal
  2. | ToInteger
  3. | ToDecimal
  4. | ToMoney
  5. | GetDay
  6. | GetMonth
  7. | GetYear
  8. | LastDayOfMonth
  9. | FirstDayOfMonth
  10. | Round
type literal_date = {
  1. literal_date_day : int;
  2. literal_date_month : int;
  3. literal_date_year : int;
}
type literal_number =
  1. | Int of string
  2. | Dec of string * string
type literal_unit =
  1. | Percent
  2. | Year
  3. | Month
  4. | Day
type money_amount = {
  1. money_amount_units : string;
  2. money_amount_cents : string;
}
type 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
type collection_op =
  1. | Member of {
    1. element : expression;
    }
  2. | Exists of {
    1. predicate : lident Catala_utils.Mark.pos list * expression;
    }
  3. | Forall of {
    1. predicate : lident Catala_utils.Mark.pos list * expression;
    }
  4. | Map of {
    1. f : lident Catala_utils.Mark.pos list * expression;
    }
  5. | Filter of {
    1. f : lident Catala_utils.Mark.pos list * expression;
    }
  6. | AggregateSum of {
    1. typ : primitive_typ;
    }
  7. | AggregateExtremum of {
    1. max : bool;
    2. default : expression option;
    }
  8. | AggregateArgExtremum of {
    1. max : bool;
    2. default : expression option;
    3. f : lident Catala_utils.Mark.pos list * expression;
    }
  9. | Fold of {
    1. f : lident Catala_utils.Mark.pos list * lident Catala_utils.Mark.pos list * expression;
    2. init : 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
type exception_to =
  1. | NotAnException
  2. | UnlabeledException
  3. | ExceptionToLabel of lident Catala_utils.Mark.pos
type 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;
}
type 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;
}
type variation_typ =
  1. | Increasing
  2. | Decreasing
type assertion = {
  1. assertion_condition : expression option;
  2. assertion_content : expression;
}
type 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
type 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;
}
type io_input =
  1. | Input
  2. | Context
  3. | Internal
type 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;
}
type 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;
}
type 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;
}
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 : uident Catala_utils.Mark.pos;
  2. scope_decl_context : scope_decl_context_item Catala_utils.Mark.pos list;
}
type 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;
}
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
type code_block = code_item Catala_utils.Mark.pos list
type source_repr = string Catala_utils.Mark.pos
type 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;
}
type 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
type 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
type module_use = {
  1. mod_use_name : uident Catala_utils.Mark.pos;
  2. mod_use_alias : uident Catala_utils.Mark.pos;
}
type program_module = {
  1. module_name : uident Catala_utils.Mark.pos;
  2. module_external : bool;
}
type program = {
  1. program_module : program_module 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.Global.backend_lang;
}
type source_file = law_structure list
type Shared_ast.attr_value +=
  1. | Expression of expression
type module_items =
  1. | Code of law_structure list
    (*

    Used in whole-program to gather all module code

    *)
  2. | Interface of code_block
    (*

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

    *)
type module_content = {
  1. module_modname : program_module;
  2. module_items : module_items;
  3. module_submodules : module_use list;
}