Skip to content

Migrate modes from jane syntax to the parsetree #2510

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

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ocaml/ocamldoc/odoc_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ module Analyser =
| Parsetree.Ppat_any -> None
| Parsetree.Ppat_var name -> Some name
| Parsetree.Ppat_tuple _ -> None (* FIXME when we will handle tuples *)
| Parsetree.Ppat_constraint (pat, _) -> iter_pat pat.Parsetree.ppat_desc
| Parsetree.Ppat_constraint (pat, _, _) -> iter_pat pat.Parsetree.ppat_desc
| _ -> None
in
let rec iter ?(first=false) last_pos acc_env acc p_e_list =
Expand Down
8 changes: 4 additions & 4 deletions ocaml/ocamldoc/odoc_sig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ module Analyser =
let comment_opt = analyze_alerts comment_opt cd_attributes in
let vc_args =
match cd_args with
| Cstr_tuple l -> Cstr_tuple (List.map (fun (ty, _) -> Odoc_env.subst_type env ty) l)
| Cstr_tuple l -> Cstr_tuple (List.map (fun {ca_type=ty; _} -> Odoc_env.subst_type env ty) l)
| Cstr_record l ->
Cstr_record (List.map (get_field env name_comment_list) l)
in
Expand Down Expand Up @@ -499,7 +499,7 @@ module Analyser =
let open Typedtree in
function
| Cstr_tuple l ->
Odoc_type.Cstr_tuple (List.map (fun (ty, _) -> tuple ty) l)
Odoc_type.Cstr_tuple (List.map (fun {ca_type=ty; _} -> tuple ty) l)
| Cstr_record l ->
let comments = Record.(doc typedtree) pos_end l in
Odoc_type.Cstr_record (List.map (record comments) l)
Expand Down Expand Up @@ -976,7 +976,7 @@ module Analyser =
let xt_args =
match types_ext.ext_args with
| Cstr_tuple l ->
Cstr_tuple (List.map (fun (ty, _) -> Odoc_env.subst_type new_env ty) l)
Cstr_tuple (List.map (fun {ca_type=ty; _} -> Odoc_env.subst_type new_env ty) l)
| Cstr_record l ->
let docs = Record.(doc types ext_loc_end) l in
Cstr_record (List.map (get_field new_env docs) l)
Expand Down Expand Up @@ -1022,7 +1022,7 @@ module Analyser =
let ex_args =
let pos_end = Loc.end_ types_ext.ext_loc in
match types_ext.ext_args with
| Cstr_tuple l -> Cstr_tuple (List.map (fun (ty, _) -> Odoc_env.subst_type env ty) l)
| Cstr_tuple l -> Cstr_tuple (List.map (fun {ca_type=ty; _} -> Odoc_env.subst_type env ty) l)
| Cstr_record l ->
let docs = Record.(doc types) pos_end l in
Cstr_record (List.map (get_field env docs) l)
Expand Down
26 changes: 18 additions & 8 deletions ocaml/parsing/ast_helper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module Typ = struct

let any ?loc ?attrs () = mk ?loc ?attrs Ptyp_any
let var ?loc ?attrs a = mk ?loc ?attrs (Ptyp_var a)
let arrow ?loc ?attrs a b c = mk ?loc ?attrs (Ptyp_arrow (a, b, c))
let arrow ?loc ?attrs a b c d e = mk ?loc ?attrs (Ptyp_arrow (a, b, c, d, e))
let tuple ?loc ?attrs a = mk ?loc ?attrs (Ptyp_tuple a)
let constr ?loc ?attrs a b = mk ?loc ?attrs (Ptyp_constr (a, b))
let object_ ?loc ?attrs a b = mk ?loc ?attrs (Ptyp_object (a, b))
Expand Down Expand Up @@ -96,8 +96,8 @@ module Typ = struct
| Ptyp_var x ->
check_variable var_names t.ptyp_loc x;
Ptyp_var x
| Ptyp_arrow (label,core_type,core_type') ->
Ptyp_arrow(label, loop core_type, loop core_type')
| Ptyp_arrow (label,core_type,core_type',modes,modes') ->
Ptyp_arrow(label, loop core_type, loop core_type', modes, modes')
| Ptyp_tuple lst -> Ptyp_tuple (List.map loop lst)
| Ptyp_constr( { txt = Longident.Lident s }, [])
when List.mem s var_names ->
Expand Down Expand Up @@ -168,7 +168,7 @@ module Pat = struct
let record ?loc ?attrs a b = mk ?loc ?attrs (Ppat_record (a, b))
let array ?loc ?attrs a = mk ?loc ?attrs (Ppat_array a)
let or_ ?loc ?attrs a b = mk ?loc ?attrs (Ppat_or (a, b))
let constraint_ ?loc ?attrs a b = mk ?loc ?attrs (Ppat_constraint (a, b))
let constraint_ ?loc ?attrs a b c = mk ?loc ?attrs (Ppat_constraint (a, b, c))
let type_ ?loc ?attrs a = mk ?loc ?attrs (Ppat_type a)
let lazy_ ?loc ?attrs a = mk ?loc ?attrs (Ppat_lazy a)
let unpack ?loc ?attrs a = mk ?loc ?attrs (Ppat_unpack a)
Expand Down Expand Up @@ -204,7 +204,7 @@ module Exp = struct
let sequence ?loc ?attrs a b = mk ?loc ?attrs (Pexp_sequence (a, b))
let while_ ?loc ?attrs a b = mk ?loc ?attrs (Pexp_while (a, b))
let for_ ?loc ?attrs a b c d e = mk ?loc ?attrs (Pexp_for (a, b, c, d, e))
let constraint_ ?loc ?attrs a b = mk ?loc ?attrs (Pexp_constraint (a, b))
let constraint_ ?loc ?attrs a b c = mk ?loc ?attrs (Pexp_constraint (a, b, c))
let coerce ?loc ?attrs a b c = mk ?loc ?attrs (Pexp_coerce (a, b, c))
let send ?loc ?attrs a b = mk ?loc ?attrs (Pexp_send (a, b))
let new_ ?loc ?attrs a = mk ?loc ?attrs (Pexp_new a)
Expand Down Expand Up @@ -412,10 +412,11 @@ end

module Val = struct
let mk ?(loc = !default_loc) ?(attrs = []) ?(docs = empty_docs)
?(prim = []) name typ =
?(prim = []) ?(modes = []) name typ =
{
pval_name = name;
pval_type = typ;
pval_modes = modes;
pval_attributes = add_docs_attrs docs attrs;
pval_loc = loc;
pval_prim = prim;
Expand Down Expand Up @@ -493,11 +494,12 @@ end

module Vb = struct
let mk ?(loc = !default_loc) ?(attrs = []) ?(docs = empty_docs)
?(text = []) ?value_constraint pat expr =
?(text = []) ?value_constraint ?(modes = []) pat expr =
{
pvb_pat = pat;
pvb_expr = expr;
pvb_constraint=value_constraint;
pvb_modes=modes;
pvb_attributes =
add_text_attrs text (add_docs_attrs docs attrs);
pvb_loc = loc;
Expand Down Expand Up @@ -550,11 +552,19 @@ module Type = struct
pcd_attributes = add_info_attrs info attrs;
}

let constructor_arg ?(loc = !default_loc) ?(modalities = []) typ =
{
pca_modalities = modalities;
pca_type = typ;
pca_loc = loc;
}

let field ?(loc = !default_loc) ?(attrs = []) ?(info = empty_info)
?(mut = Immutable) name typ =
?(mut = Immutable) ?(modalities = []) name typ =
{
pld_name = name;
pld_mutable = mut;
pld_modalities = modalities;
pld_type = typ;
pld_loc = loc;
pld_attributes = add_info_attrs info attrs;
Expand Down
22 changes: 14 additions & 8 deletions ocaml/parsing/ast_helper.mli
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ module Typ :

val any: ?loc:loc -> ?attrs:attrs -> unit -> core_type
val var: ?loc:loc -> ?attrs:attrs -> string -> core_type
val arrow: ?loc:loc -> ?attrs:attrs -> arg_label -> core_type -> core_type
-> core_type
val arrow: ?loc:loc -> ?attrs:attrs -> arg_label -> core_type -> core_type ->
mode with_loc list -> mode with_loc list -> core_type
val tuple: ?loc:loc -> ?attrs:attrs -> core_type list -> core_type
val constr: ?loc:loc -> ?attrs:attrs -> lid -> core_type list -> core_type
val object_: ?loc:loc -> ?attrs:attrs -> object_field list
Expand Down Expand Up @@ -117,7 +117,8 @@ module Pat:
-> pattern
val array: ?loc:loc -> ?attrs:attrs -> pattern list -> pattern
val or_: ?loc:loc -> ?attrs:attrs -> pattern -> pattern -> pattern
val constraint_: ?loc:loc -> ?attrs:attrs -> pattern -> core_type -> pattern
val constraint_: ?loc:loc -> ?attrs:attrs -> pattern -> core_type option
-> mode with_loc list -> pattern
val type_: ?loc:loc -> ?attrs:attrs -> lid -> pattern
val lazy_: ?loc:loc -> ?attrs:attrs -> pattern -> pattern
val unpack: ?loc:loc -> ?attrs:attrs -> str_opt -> pattern
Expand Down Expand Up @@ -177,7 +178,7 @@ module Exp:
val coerce: ?loc:loc -> ?attrs:attrs -> expression -> core_type option
-> core_type -> expression
val constraint_: ?loc:loc -> ?attrs:attrs -> expression -> core_type
-> expression
-> mode with_loc list -> expression
val send: ?loc:loc -> ?attrs:attrs -> expression -> str -> expression
val new_: ?loc:loc -> ?attrs:attrs -> lid -> expression
val setinstvar: ?loc:loc -> ?attrs:attrs -> str -> expression -> expression
Expand Down Expand Up @@ -210,7 +211,7 @@ module Exp:
module Val:
sig
val mk: ?loc:loc -> ?attrs:attrs -> ?docs:docs ->
?prim:string list -> str -> core_type -> value_description
?prim:string list -> ?modes:mode with_loc list -> str -> core_type -> value_description
end

(** Type declarations *)
Expand All @@ -226,8 +227,13 @@ module Type:
?vars:str list -> ?args:constructor_arguments -> ?res:core_type ->
str ->
constructor_declaration

val constructor_arg: ?loc:loc -> ?modalities:modality with_loc list -> core_type ->
constructor_argument

val field: ?loc:loc -> ?attrs:attrs -> ?info:info ->
?mut:mutable_flag -> str -> core_type -> label_declaration
?mut:mutable_flag -> ?modalities:modality with_loc list -> str -> core_type ->
label_declaration
end

(** Type extensions *)
Expand Down Expand Up @@ -381,8 +387,8 @@ module Incl:
module Vb:
sig
val mk: ?loc: loc -> ?attrs:attrs -> ?docs:docs -> ?text:text ->
?value_constraint:value_constraint -> pattern -> expression ->
value_binding
?value_constraint:value_constraint -> ?modes:mode with_loc list -> pattern ->
expression -> value_binding
end


Expand Down
1 change: 0 additions & 1 deletion ocaml/parsing/ast_invariants.ml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ let iterator =
| Jexp_comprehension _
| Jexp_immutable_array _
| Jexp_layout _
| Jexp_modes _
-> ()
in
let expr self exp =
Expand Down
Loading
Loading