Skip to content

Commit

Permalink
Merge pull request #2 from nojb/sync_503
Browse files Browse the repository at this point in the history
Adapt to Location.footnote, effect patterns
  • Loading branch information
NathanReb authored May 21, 2024
2 parents 380a0ce + 8ea9848 commit 7e812b0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions astlib/ast_503.ml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ module Parsetree = struct
[Ppat_constraint(Ppat_unpack(Some "P"), Ptyp_package S)]
*)
| Ppat_exception of pattern (** Pattern [exception P] *)
| Ppat_effect of pattern * pattern (* Pattern [effect P P] *)
| Ppat_extension of extension (** Pattern [[%id]] *)
| Ppat_open of Longident.t loc * pattern (** Pattern [M.(P)] *)

Expand Down
2 changes: 2 additions & 0 deletions astlib/location.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module Error = struct
kind : location_report_kind;
main : location_msg;
sub : location_msg list;
(*IF_AT_LEAST 503 footnote: unit -> (Format.formatter -> unit) option; *)
}

type t (*IF_AT_LEAST 408 = Ocaml_common.Location.error *) (*IF_NOT_AT_LEAST 408 = old_t *)
Expand Down Expand Up @@ -95,6 +96,7 @@ module Error = struct
kind = Report_error;
main = mk loc txt;
sub = List.map (fun { loc; txt } -> mk loc txt) sub;
(*IF_AT_LEAST 503 footnote = fun _ -> None; *)
}

let make ~sub msg =
Expand Down
13 changes: 10 additions & 3 deletions astlib/migrate_503_502.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ open Stdlib0
module From = Ast_503
module To = Ast_502

let migration_error loc missing_feature =
Location.raise_errorf ~loc
"migration error: %s is not supported before OCaml 5.03" missing_feature

let rec copy_toplevel_phrase :
Ast_503.Parsetree.toplevel_phrase -> Ast_502.Parsetree.toplevel_phrase =
function
Expand Down Expand Up @@ -272,14 +276,15 @@ and copy_pattern : Ast_503.Parsetree.pattern -> Ast_502.Parsetree.pattern =
Ast_503.Parsetree.ppat_loc_stack;
Ast_503.Parsetree.ppat_attributes;
} ->
let ppat_loc = copy_location ppat_loc in
{
Ast_502.Parsetree.ppat_desc = copy_pattern_desc ppat_desc;
Ast_502.Parsetree.ppat_loc = copy_location ppat_loc;
Ast_502.Parsetree.ppat_desc = copy_pattern_desc ppat_loc ppat_desc;
Ast_502.Parsetree.ppat_loc;
Ast_502.Parsetree.ppat_loc_stack = copy_location_stack ppat_loc_stack;
Ast_502.Parsetree.ppat_attributes = copy_attributes ppat_attributes;
}

and copy_pattern_desc :
and copy_pattern_desc loc :
Ast_503.Parsetree.pattern_desc -> Ast_502.Parsetree.pattern_desc = function
| Ast_503.Parsetree.Ppat_any -> Ast_502.Parsetree.Ppat_any
| Ast_503.Parsetree.Ppat_var x0 ->
Expand Down Expand Up @@ -325,6 +330,8 @@ and copy_pattern_desc :
(copy_loc (fun x -> Option.map (fun x -> x) x) x0)
| Ast_503.Parsetree.Ppat_exception x0 ->
Ast_502.Parsetree.Ppat_exception (copy_pattern x0)
| Ast_503.Parsetree.Ppat_effect _ ->
migration_error loc "effect pattern"
| Ast_503.Parsetree.Ppat_extension x0 ->
Ast_502.Parsetree.Ppat_extension (copy_extension x0)
| Ast_503.Parsetree.Ppat_open (x0, x1) ->
Expand Down

0 comments on commit 7e812b0

Please sign in to comment.