feat(compiler): annotate the NoValueProvided exception with location

This commit is contained in:
EmileRolley 2021-06-08 15:06:07 +02:00
parent 95dc816070
commit 5042a00620
7 changed files with 848 additions and 88 deletions

View File

@ -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

View File

@ -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

View File

@ -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) ->

View File

@ -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) ->

View File

@ -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

View File

@ -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