Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metaquot: Embed errors in the AST instead of raising #397

Merged
merged 10 commits into from Mar 22, 2023
17 changes: 13 additions & 4 deletions metaquot/ppxlib_metaquot.ml
Expand Up @@ -108,7 +108,10 @@ module Expr = Make (struct
assert_no_attributes attrs;
e
| _ ->
Location.raise_errorf ~loc:(loc_of_extension ext) "expression expected"
Ast_builder.Default.(
pexp_extension ~loc:(loc_of_extension ext)
(Location.error_extensionf ~loc:(loc_of_extension ext)
"expression expected"))
end)

module Patt = Make (struct
Expand All @@ -125,12 +128,18 @@ module Patt = Make (struct

let annotate p core_type = ppat_constraint ~loc:core_type.ptyp_loc p core_type

let cast ext =
let cast ext : Ppxlib.pattern =
Burnleydev1 marked this conversation as resolved.
Show resolved Hide resolved
match snd ext with
| PPat (p, None) -> p
| PPat (_, Some e) ->
Location.raise_errorf ~loc:e.pexp_loc "guard not expected here"
| _ -> Location.raise_errorf ~loc:(loc_of_extension ext) "pattern expected"
Ast_builder.Default.(
ppat_extension ~loc:e.pexp_loc
(Location.error_extensionf ~loc:e.pexp_loc "guard not expected here"))
| _ ->
Ast_builder.Default.(
ppat_extension ~loc:(loc_of_extension ext)
(Location.error_extensionf ~loc:(loc_of_extension ext)
"pattern expected"))
end)

let () =
Expand Down