package catala

  1. Overview
  2. Docs

Translation from Desugared.Ast to Scopelang.Ast

module Pos = Utils.Pos
module Errors = Utils.Errors
module Cli = Utils.Cli

Rule tree construction

type rule_tree =
  1. | Leaf of Ast.rule
  2. | Node of rule_tree list * Ast.rule
val def_map_to_tree : Ast.ScopeDef.t -> Scopelang.Ast.typ Pos.marked option -> Ast.rule Desugared.Ast.RuleMap.t -> rule_tree list

Transforms a flat list of rules into a tree, taking into account the priorities declared between rules

Invariant: there are no exceptions cycles

Invariant: there are no dandling exception pointers in the rules

val rule_tree_to_expr : toplevel:bool -> Scopelang.Ast.Var.t option -> rule_tree -> Scopelang.Ast.expr Pos.marked Bindlib.box

From the rule_tree, builds an Dcalc.Ast.EDefault expression in the scope language. The ~toplevel parameter is used to know when to place the toplevel binding in the case of functions.

AST translation

val translate_def : Ast.ScopeDef.t -> Ast.rule Desugared.Ast.RuleMap.t -> Scopelang.Ast.typ Pos.marked -> Scopelang.Ast.expr Pos.marked

Translates a definition inside a scope, the resulting expression should be an Dcalc.Ast.EDefault

val translate_scope : Ast.scope -> Scopelang.Ast.scope_decl

Translates a scope

API

val translate_program : Ast.program -> Scopelang.Ast.program