Skip to content

Add parsing rules and jane syntax encoding for modal kind syntax #2345

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

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 0 deletions ocaml/ocamldoc/odoc_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,8 @@ module Analyser =
| Ifstr_include_functor incl ->
analyse_structure_item_include ~env ~comment_opt incl
end
| Jstr_layout (Lstr_kind_abbrev _) ->
Misc.fatal_error "Lstr_kind_abbrev"

(** Analysis of a parse tree structure item to obtain a new environment and a list of elements.*)
and analyse_structure_item env current_module_name loc pos_limit comment_opt parsetree_item_desc _typedtree
Expand Down
4 changes: 4 additions & 0 deletions ocaml/ocamldoc/odoc_sig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,8 @@ module Analyser =
let filter_out_erased_item_from_signature_jst _erased acc
: Jane_syntax.Signature_item.t -> _ = function
| Jsig_include_functor (Ifsig_include_functor _) -> acc
| Jsig_layout (Lsig_kind_abbrev _) ->
Misc.fatal_error "Lsig_kind_abbrev"

let filter_out_erased_items_from_signature erased signature =
if Name.Map.is_empty erased then signature
Expand Down Expand Up @@ -890,6 +892,8 @@ module Analyser =
| Ifsig_include_functor incl ->
analyse_signature_item_desc_include ~env ~comment_opt incl
end
| Jsig_layout (Lsig_kind_abbrev _) ->
Misc.fatal_error "Lsig_kind_abbrev"

(** Analyse the given signature_item_desc to create the corresponding module element
(with the given attached comment).*)
Expand Down
5 changes: 5 additions & 0 deletions ocaml/otherlibs/dynlink/dune
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
longident
docstrings
printast
pprintast
syntaxerr
jane_asttypes
jane_syntax_parsing
Expand Down Expand Up @@ -165,6 +166,7 @@
(copy_files ../../parsing/longident.ml)
(copy_files ../../parsing/docstrings.ml)
(copy_files ../../parsing/printast.ml)
(copy_files ../../parsing/pprintast.ml)
(copy_files ../../parsing/syntaxerr.ml)
(copy_files ../../parsing/jane_asttypes.ml)
(copy_files ../../parsing/jane_syntax_parsing.ml)
Expand Down Expand Up @@ -229,6 +231,7 @@
(copy_files ../../parsing/longident.mli)
(copy_files ../../parsing/docstrings.mli)
(copy_files ../../parsing/printast.mli)
(copy_files ../../parsing/pprintast.mli)
(copy_files ../../parsing/syntaxerr.mli)
(copy_files ../../parsing/jane_asttypes.mli)
(copy_files ../../parsing/jane_syntax_parsing.mli)
Expand Down Expand Up @@ -347,6 +350,7 @@
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Jane_asttypes.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Jane_syntax_parsing.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Jane_syntax.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Pprintast.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Ast_iterator.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Builtin_attributes.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Load_path.cmo
Expand Down Expand Up @@ -427,6 +431,7 @@
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Jane_asttypes.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Jane_syntax_parsing.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Jane_syntax.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Pprintast.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Load_path.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Ast_iterator.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Builtin_attributes.cmx
Expand Down
29 changes: 27 additions & 2 deletions ocaml/parsing/ast_iterator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type iterator = {
extension_constructor: iterator -> extension_constructor -> unit;
include_declaration: iterator -> include_declaration -> unit;
include_description: iterator -> include_description -> unit;
jkind_annotation:iterator -> Jane_asttypes.const_jkind -> unit;
jkind_annotation:iterator -> Jane_syntax.Jkind.t -> unit;
label_declaration: iterator -> label_declaration -> unit;
location: iterator -> Location.t -> unit;
module_binding: iterator -> module_binding -> unit;
Expand Down Expand Up @@ -360,9 +360,16 @@ module MT = struct
: Jane_syntax.Include_functor.signature_item -> unit = function
| Ifsig_include_functor incl -> sub.include_description sub incl

let iter_sig_layout sub
: Jane_syntax.Layouts.signature_item -> unit = function
| Lsig_kind_abbrev (name, jkind) ->
iter_loc sub name;
iter_loc_txt sub sub.jkind_annotation jkind

let iter_signature_item_jst sub : Jane_syntax.Signature_item.t -> unit =
function
| Jsig_include_functor ifincl -> iter_sig_include_functor sub ifincl
| Jsig_layout sigi -> iter_sig_layout sub sigi

let iter_signature_item sub ({psig_desc = desc; psig_loc = loc} as sigi) =
sub.location sub loc;
Expand Down Expand Up @@ -424,9 +431,16 @@ module M = struct
: Jane_syntax.Include_functor.structure_item -> unit = function
| Ifstr_include_functor incl -> sub.include_declaration sub incl

let iter_str_layout sub
: Jane_syntax.Layouts.structure_item -> unit = function
| Lstr_kind_abbrev (name, jkind) ->
iter_loc sub name;
iter_loc_txt sub sub.jkind_annotation jkind

let iter_structure_item_jst sub : Jane_syntax.Structure_item.t -> unit =
function
| Jstr_include_functor ifincl -> iter_str_include_functor sub ifincl
| Jstr_layout stri -> iter_str_layout sub stri

let iter_structure_item sub ({pstr_loc = loc; pstr_desc = desc} as stri) =
sub.location sub loc;
Expand Down Expand Up @@ -977,5 +991,16 @@ let default_iterator =
| PPat (x, g) -> this.pat this x; iter_opt (this.expr this) g
);

jkind_annotation = (fun _this _l -> ());
jkind_annotation =
(fun this -> function
| Default -> ()
| Primitive_layout_or_abbreviation s ->
iter_loc this s
| Mod (t, mode_expr) ->
this.jkind_annotation this t;
this.modes this mode_expr
| With (t, ty) ->
this.jkind_annotation this t;
this.typ this ty
| Kind_of ty -> this.typ this ty);
}
2 changes: 1 addition & 1 deletion ocaml/parsing/ast_iterator.mli
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type iterator = {
extension_constructor: iterator -> extension_constructor -> unit;
include_declaration: iterator -> include_declaration -> unit;
include_description: iterator -> include_description -> unit;
jkind_annotation: iterator -> Jane_asttypes.const_jkind -> unit;
jkind_annotation: iterator -> Jane_syntax.Jkind.t -> unit;
label_declaration: iterator -> label_declaration -> unit;
location: iterator -> Location.t -> unit;
module_binding: iterator -> module_binding -> unit;
Expand Down
44 changes: 42 additions & 2 deletions ocaml/parsing/ast_mapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type mapper = {
include_declaration: mapper -> include_declaration -> include_declaration;
include_description: mapper -> include_description -> include_description;
jkind_annotation:
mapper -> Jane_asttypes.const_jkind -> Jane_asttypes.const_jkind;
mapper -> Jane_syntax.Jkind.t -> Jane_syntax.Jkind.t;
label_declaration: mapper -> label_declaration -> label_declaration;
location: mapper -> Location.t -> Location.t;
module_binding: mapper -> module_binding -> module_binding;
Expand Down Expand Up @@ -421,11 +421,23 @@ module MT = struct
| Ifsig_include_functor incl ->
Ifsig_include_functor (sub.include_description sub incl)

module L = Jane_syntax.Layouts

let map_sig_layout sub : L.signature_item -> L.signature_item =
function
| Lsig_kind_abbrev (name, jkind) ->
Lsig_kind_abbrev (
map_loc sub name,
map_loc_txt sub sub.jkind_annotation jkind
)

let map_signature_item_jst sub :
Jane_syntax.Signature_item.t -> Jane_syntax.Signature_item.t =
function
| Jsig_include_functor ifincl ->
Jsig_include_functor (map_sig_include_functor sub ifincl)
| Jsig_layout sigi ->
Jsig_layout (map_sig_layout sub sigi)

let map_signature_item sub ({psig_desc = desc; psig_loc = loc} as sigi) =
let open Sig in
Expand All @@ -435,6 +447,8 @@ module MT = struct
match sub.signature_item_jane_syntax sub jsigi with
| Jsig_include_functor incl ->
Jane_syntax.Include_functor.sig_item_of ~loc incl
| Jsig_layout sigi ->
Jane_syntax.Layouts.sig_item_of ~loc sigi
end
| None ->
match desc with
Expand Down Expand Up @@ -502,11 +516,23 @@ module M = struct
| Ifstr_include_functor incl ->
Ifstr_include_functor (sub.include_declaration sub incl)

module L = Jane_syntax.Layouts

let map_str_layout sub : L.structure_item -> L.structure_item =
function
| Lstr_kind_abbrev (name, jkind) ->
Lstr_kind_abbrev (
map_loc sub name,
map_loc_txt sub sub.jkind_annotation jkind
)

let map_structure_item_jst sub :
Jane_syntax.Structure_item.t -> Jane_syntax.Structure_item.t =
function
| Jstr_include_functor ifincl ->
Jstr_include_functor (map_str_include_functor sub ifincl)
| Jstr_layout stri ->
Jstr_layout (map_str_layout sub stri)

let map_structure_item sub ({pstr_loc = loc; pstr_desc = desc} as stri) =
let open Str in
Expand All @@ -516,6 +542,8 @@ module M = struct
match sub.structure_item_jane_syntax sub jstri with
| Jstr_include_functor incl ->
Jane_syntax.Include_functor.str_item_of ~loc incl
| Jstr_layout stri ->
Jane_syntax.Layouts.str_item_of ~loc stri
end
| None ->
match desc with
Expand Down Expand Up @@ -1105,7 +1133,19 @@ let default_mapper =
| PPat (x, g) -> PPat (this.pat this x, map_opt (this.expr this) g)
);

jkind_annotation = (fun _this l -> l);

jkind_annotation = (fun this -> function
| Default -> Default
| Primitive_layout_or_abbreviation s ->
Primitive_layout_or_abbreviation (map_loc this s)
| Mod (t, mode_expr) ->
Mod (
this.jkind_annotation this t,
this.modes this mode_expr
)
| With (t, ty) ->
With (this.jkind_annotation this t, this.typ this ty)
| Kind_of ty -> Kind_of (this.typ this ty));

expr_jane_syntax = E.map_jst;
extension_constructor_jane_syntax = T.map_extension_constructor_jst;
Expand Down
2 changes: 1 addition & 1 deletion ocaml/parsing/ast_mapper.mli
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type mapper = {
type *)

jkind_annotation:
mapper -> Jane_asttypes.const_jkind -> Jane_asttypes.const_jkind;
mapper -> Jane_syntax.Jkind.t -> Jane_syntax.Jkind.t;
label_declaration: mapper -> label_declaration -> label_declaration;
location: mapper -> Location.t -> Location.t;
module_binding: mapper -> module_binding -> module_binding;
Expand Down
15 changes: 9 additions & 6 deletions ocaml/parsing/depend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
(**************************************************************************)

open Asttypes
open Jane_asttypes
open Location
open Longident
open Parsetree
Expand Down Expand Up @@ -98,7 +97,7 @@ let handle_extension ext =

(* CR layouts: Remember to add this when jkinds can have module
prefixes. *)
let add_jkind _bv (_jkind : jkind_annotation) = ()
let add_jkind _bv (_jkind : Jane_syntax.Jkind.annotation) = ()

let add_vars_jkinds bv vars_jkinds =
let add_one (_, jkind) = Option.iter (add_jkind bv) jkind in
Expand Down Expand Up @@ -531,11 +530,13 @@ and add_include_description (bv, m) incl =
let add = String.Map.fold String.Map.add m' in
(add bv, add m)

and add_sig_item_jst bvm : Jane_syntax.Signature_item.t -> _ = function
and add_sig_item_jst (bv, m) : Jane_syntax.Signature_item.t -> _ = function
| Jsig_include_functor (Ifsig_include_functor incl) ->
(* It seems to be correct to treat [include functor] the same as
[include], but it's possible we could do something cleverer. *)
add_include_description bvm incl
add_include_description (bv, m) incl
| Jsig_layout (Lsig_kind_abbrev (_, jkind)) ->
add_jkind bv jkind; (bv, m)

and add_sig_item (bv, m) item =
match Jane_syntax.Signature_item.of_ast item with
Expand Down Expand Up @@ -685,11 +686,13 @@ and add_include_declaration (bv, m) incl =
let add = String.Map.fold String.Map.add m' in
(add bv, add m)

and add_struct_item_jst bvm : Jane_syntax.Structure_item.t -> _ = function
and add_struct_item_jst (bv, m) : Jane_syntax.Structure_item.t -> _ = function
| Jstr_include_functor (Ifstr_include_functor incl) ->
(* It seems to be correct to treat [include functor] the same as
[include], but it's possible we could do something cleverer. *)
add_include_declaration bvm incl
add_include_declaration (bv, m) incl
| Jstr_layout (Lstr_kind_abbrev (_name, jkind)) ->
add_jkind bv jkind; (bv, m)

and add_struct_item (bv, m) item : _ String.Map.t * _ String.Map.t =
match Jane_syntax.Structure_item.of_ast item with
Expand Down
8 changes: 0 additions & 8 deletions ocaml/parsing/jane_asttypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,3 @@
(* special exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)

type const_jkind = string

let jkind_of_string x = x

let jkind_to_string x = x

type jkind_annotation = const_jkind Location.loc
11 changes: 0 additions & 11 deletions ocaml/parsing/jane_asttypes.mli
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,3 @@
{{!Compiler_libs}compiler-libs}.

*)

(** [const_jkind] is private to limit confusion with type variables, which
are also strings in the parser.
*)
type const_jkind

val jkind_of_string : string -> const_jkind

val jkind_to_string : const_jkind -> string

type jkind_annotation = const_jkind Location.loc
Loading