mirror of
https://github.com/CatalaLang/catala.git
synced 2024-09-20 00:41:05 +03:00
feat(compiler): annotate the NoValueProvided exception with location
This commit is contained in:
parent
95dc816070
commit
5042a00620
@ -24,7 +24,7 @@ type lit =
|
||||
| LDate of Runtime.date
|
||||
| LDuration of Runtime.duration
|
||||
|
||||
type except = ConflictError | EmptyError | NoValueProvided | Crash
|
||||
type except = ConflictError | EmptyError | NoValueProvided of Dcalc.Ast.expr Pos.marked | Crash
|
||||
|
||||
type expr =
|
||||
| EVar of expr Bindlib.var Pos.marked
|
||||
|
@ -30,7 +30,7 @@ type lit =
|
||||
| LDate of Runtime.date
|
||||
| LDuration of Runtime.duration
|
||||
|
||||
type except = ConflictError | EmptyError | NoValueProvided | Crash
|
||||
type except = ConflictError | EmptyError | NoValueProvided of Dcalc.Ast.expr Pos.marked | Crash
|
||||
|
||||
type expr =
|
||||
| EVar of expr Bindlib.var Pos.marked
|
||||
|
@ -90,7 +90,7 @@ and translate_expr (ctx : ctx) (e : D.expr Pos.marked) : A.expr Pos.marked Bindl
|
||||
Bindlib.box_apply
|
||||
(fun arg ->
|
||||
Pos.same_pos_as
|
||||
(A.ECatch (arg, A.EmptyError, Pos.same_pos_as (A.ERaise A.NoValueProvided) e))
|
||||
(A.ECatch (arg, A.EmptyError, Pos.same_pos_as (A.ERaise (A.NoValueProvided e)) e))
|
||||
e)
|
||||
(translate_expr ctx arg)
|
||||
| D.EApp (e1, args) ->
|
||||
|
@ -221,20 +221,26 @@ let needs_parens (e : expr Pos.marked) : bool =
|
||||
| EApp ((EAbs (_, _), _), _) | ELit (LBool _ | LUnit) | EVar _ | ETuple _ | EOp _ -> false
|
||||
| _ -> true
|
||||
|
||||
let format_exception (fmt : Format.formatter) (exc : except) : unit =
|
||||
match exc with
|
||||
| ConflictError -> Format.fprintf fmt "ConflictError"
|
||||
| EmptyError -> Format.fprintf fmt "EmptyError"
|
||||
| Crash -> Format.fprintf fmt "Crash"
|
||||
| NoValueProvided -> Format.fprintf fmt "NoValueProvided"
|
||||
|
||||
let rec format_expr (ctx : Dcalc.Ast.decl_ctx) (fmt : Format.formatter) (e : expr Pos.marked) : unit
|
||||
=
|
||||
let format_expr = format_expr ctx in
|
||||
(* @note: (EmileRolley) is [fmt] really needed? *)
|
||||
let format_with_parens (fmt : Format.formatter) (e : expr Pos.marked) =
|
||||
if needs_parens e then Format.fprintf fmt "(%a)" format_expr e
|
||||
else Format.fprintf fmt "%a" format_expr e
|
||||
in
|
||||
let format_exception (fmt : Format.formatter) (exc : except) : unit =
|
||||
match exc with
|
||||
| ConflictError -> Format.fprintf fmt "ConflictError"
|
||||
| EmptyError -> Format.fprintf fmt "EmptyError"
|
||||
| Crash -> Format.fprintf fmt "Crash"
|
||||
| NoValueProvided (_, pos) ->
|
||||
Format.fprintf fmt
|
||||
"(NoValueProvided@ @[<hov 2>{filename = \"%s\";@ start_line=%d;@ start_column=%d;@ \
|
||||
end_line=%d; end_column=%d;@ law_headings=%a}@])"
|
||||
(Pos.get_file pos) (Pos.get_start_line pos) (Pos.get_start_column pos)
|
||||
(Pos.get_end_line pos) (Pos.get_end_column pos) format_string_list (Pos.get_law_info pos)
|
||||
in
|
||||
match Pos.unmark e with
|
||||
| EVar v -> Format.fprintf fmt "%a" format_var (Pos.unmark v)
|
||||
| ETuple (es, None) ->
|
||||
|
@ -24,8 +24,6 @@ type duration = CalendarLib.Date.Period.t
|
||||
|
||||
exception EmptyError
|
||||
|
||||
exception NoValueProvided
|
||||
|
||||
exception AssertionFailed
|
||||
|
||||
exception ConflictError
|
||||
@ -76,6 +74,8 @@ type source_position = {
|
||||
law_headings : string list;
|
||||
}
|
||||
|
||||
exception NoValueProvided of source_position
|
||||
|
||||
type event =
|
||||
| BeginCall of string list
|
||||
| EndCall of string list
|
||||
|
@ -38,8 +38,6 @@ exception IndivisableDurations
|
||||
|
||||
exception ImpossibleDate
|
||||
|
||||
exception NoValueProvided
|
||||
|
||||
(** {1 Value Embedding} *)
|
||||
|
||||
type runtime_value =
|
||||
@ -84,6 +82,8 @@ type source_position = {
|
||||
law_headings : string list;
|
||||
}
|
||||
|
||||
exception NoValueProvided of source_position
|
||||
|
||||
type event =
|
||||
| BeginCall of string list
|
||||
| EndCall of string list
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user