Skip to content

Commit

Permalink
applying requested changes.
Browse files Browse the repository at this point in the history
Signed-off-by: Burnleydev1 <[email protected]>
  • Loading branch information
Burnleydev1 authored and NathanReb committed Jan 11, 2024
1 parent 08c23fb commit df9cc61
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
18 changes: 8 additions & 10 deletions src/context_free.ml
Original file line number Diff line number Diff line change
Expand Up @@ -518,30 +518,28 @@ class map_top_down ?(expect_mismatch_handler = Expect_mismatch_handler.nop)
| None ->
self#pexp_apply_without_traversing_function base_ctxt e func args
| Some pattern -> (
let pat_expr =
try (pattern e, [])
let generated_code =
try return (pattern e)
with exn when embed_errors -> (None, [ exn_to_error exn ])
in
pat_expr >>= fun expr ->
generated_code >>= fun expr ->
match expr with
| None ->
self#pexp_apply_without_traversing_function base_ctxt e func
args
| Some e -> self#expression base_ctxt e
(* with exn when embed_errors -> (e, [ exn_to_error exn ]) *)))
| Some e -> self#expression base_ctxt e))
| Pexp_ident id -> (
match Hashtbl.find_opt special_functions id.txt with
| None -> super#expression base_ctxt e
| Some pattern -> (
let pat_exp =
try (pattern e, [])
let generated_code =
try return (pattern e)
with exn when embed_errors -> (None, [ exn_to_error exn ])
in
pat_exp >>= fun expr ->
generated_code >>= fun expr ->
match expr with
| None -> super#expression base_ctxt e
| Some e -> self#expression base_ctxt e
(* with exn when embed_errors -> (e, [ exn_to_error exn ]) *)))
| Some e -> self#expression base_ctxt e))
| Pexp_constant (Pconst_integer (s, Some c)) -> (
try expand_constant Integer c s
with exn when embed_errors -> (e, [ exn_to_error exn ]))
Expand Down
4 changes: 2 additions & 2 deletions test/driver/exception_handling/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,12 @@ when the -embed-errors flag is not passed
When embed-errors is not passed
$ ./special_functions.exe impl.ml
File "impl.ml", lines 1-2, characters 0-7:
Error: error special function
Error: error special function
[1]

When embed-errors is not passed
$ ./special_functions.exe -embed-errors impl.ml
[%%ocaml.error "error special function "]
[%%ocaml.error "error special function"]
[%%ocaml.error "second error special function"]
;;n_args n_args2

Expand Down
2 changes: 1 addition & 1 deletion test/driver/exception_handling/special_functions.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open Ppxlib

let expand e = Location.raise_errorf ~loc:e.pexp_loc "error special function "
let expand e = Location.raise_errorf ~loc:e.pexp_loc "error special function"

let expand2 e =
Location.raise_errorf ~loc:e.pexp_loc "second error special function"
Expand Down

0 comments on commit df9cc61

Please sign in to comment.