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

Convert Jane Syntax to use attributes for many syntactic categories #1412

Merged
merged 20 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
20 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
7 changes: 5 additions & 2 deletions ocaml/.depend
Original file line number Diff line number Diff line change
Expand Up @@ -450,19 +450,20 @@ parsing/jane_syntax.cmi : \
parsing/parsetree.cmi \
parsing/longident.cmi \
parsing/location.cmi \
parsing/jane_syntax_parsing.cmi \
parsing/asttypes.cmi
parsing/jane_syntax_parsing.cmo : \
parsing/parsetree.cmi \
utils/misc.cmi \
parsing/location.cmi \
utils/language_extension.cmi \
parsing/asttypes.cmi \
parsing/ast_helper.cmi \
parsing/jane_syntax_parsing.cmi
parsing/jane_syntax_parsing.cmx : \
parsing/parsetree.cmi \
utils/misc.cmx \
parsing/location.cmx \
utils/language_extension.cmx \
parsing/asttypes.cmi \
parsing/ast_helper.cmx \
parsing/jane_syntax_parsing.cmi
parsing/jane_syntax_parsing.cmi : \
Expand Down Expand Up @@ -2079,6 +2080,7 @@ typing/untypeast.cmo : \
parsing/parsetree.cmi \
parsing/longident.cmi \
parsing/location.cmi \
parsing/jane_syntax_parsing.cmi \
parsing/jane_syntax.cmi \
typing/ident.cmi \
typing/env.cmi \
Expand All @@ -2091,6 +2093,7 @@ typing/untypeast.cmx : \
parsing/parsetree.cmi \
parsing/longident.cmx \
parsing/location.cmx \
parsing/jane_syntax_parsing.cmx \
parsing/jane_syntax.cmx \
typing/ident.cmx \
typing/env.cmx \
Expand Down
14,653 changes: 7,254 additions & 7,399 deletions ocaml/boot/menhir/parser.ml

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions ocaml/ocamldoc/odoc_sig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,8 @@ module Analyser =
and analyse_module_type_kind
?(erased = Name.Map.empty) env current_module_name module_type sig_module_type =
match Jane_syntax.Module_type.of_ast module_type with
| Some (Jmty_strengthen _) -> failwith "strengthen not implemented yet"
| Some (Jmty_strengthen _, _attrs) ->
failwith "strengthen not implemented yet"
| None ->
match module_type.Parsetree.pmty_desc with
Parsetree.Pmty_ident longident ->
Expand Down Expand Up @@ -1657,7 +1658,8 @@ module Analyser =
and analyse_module_kind
?(erased = Name.Map.empty) env current_module_name module_type sig_module_type =
match Jane_syntax.Module_type.of_ast module_type with
| Some (Jmty_strengthen _) -> failwith "strengthen not implemented yet"
| Some (Jmty_strengthen _, _attrs) ->
failwith "strengthen not implemented yet"
| None ->
match module_type.Parsetree.pmty_desc with
| Parsetree.Pmty_ident _longident ->
Expand Down
2 changes: 1 addition & 1 deletion ocaml/parsing/ast_invariants.ml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ let iterator =
end;
let loc = exp.pexp_loc in
match Jane_syntax.Expression.of_ast exp with
| Some jexp -> jexpr self exp.pexp_loc jexp
| Some (jexp, _attrs) -> jexpr self exp.pexp_loc jexp
| None ->
match exp.pexp_desc with
| Pexp_tuple ([] | [_]) -> invalid_tuple loc
Expand Down
24 changes: 16 additions & 8 deletions ocaml/parsing/ast_iterator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,12 @@ module T = struct
let iter sub ({ptyp_desc = desc; ptyp_loc = loc; ptyp_attributes = attrs}
as typ) =
sub.location sub loc;
sub.attributes sub attrs;
match Jane_syntax.Core_type.of_ast typ with
| Some jtyp -> sub.typ_jane_syntax sub jtyp
| Some (jtyp, attrs) ->
sub.attributes sub attrs;
sub.typ_jane_syntax sub jtyp
| None ->
sub.attributes sub attrs;
match desc with
| Ptyp_any
| Ptyp_var _ -> ()
Expand Down Expand Up @@ -260,10 +262,12 @@ module MT = struct
let iter sub
({pmty_desc = desc; pmty_loc = loc; pmty_attributes = attrs} as mty) =
sub.location sub loc;
sub.attributes sub attrs;
match Jane_syntax.Module_type.of_ast mty with
| Some jmty -> sub.module_type_jane_syntax sub jmty
| Some (jmty, attrs) ->
sub.attributes sub attrs;
sub.module_type_jane_syntax sub jmty
| None ->
sub.attributes sub attrs;
match desc with
| Pmty_ident s -> iter_loc sub s
| Pmty_alias s -> iter_loc sub s
Expand Down Expand Up @@ -429,10 +433,12 @@ module E = struct
let iter sub
({pexp_loc = loc; pexp_desc = desc; pexp_attributes = attrs} as expr)=
sub.location sub loc;
sub.attributes sub attrs;
match Jane_syntax.Expression.of_ast expr with
| Some jexp -> sub.expr_jane_syntax sub jexp
| Some (jexp, attrs) ->
sub.attributes sub attrs;
sub.expr_jane_syntax sub jexp
| None ->
sub.attributes sub attrs;
match desc with
| Pexp_ident x -> iter_loc sub x
| Pexp_constant _ -> ()
Expand Down Expand Up @@ -529,10 +535,12 @@ module P = struct
let iter sub
({ppat_desc = desc; ppat_loc = loc; ppat_attributes = attrs} as pat) =
sub.location sub loc;
sub.attributes sub attrs;
match Jane_syntax.Pattern.of_ast pat with
| Some jpat -> sub.pat_jane_syntax sub jpat
| Some (jpat, attrs) ->
sub.attributes sub attrs;
sub.pat_jane_syntax sub jpat
| None ->
sub.attributes sub attrs;
match desc with
| Ppat_any -> ()
| Ppat_var s -> iter_loc sub s
Expand Down
32 changes: 18 additions & 14 deletions ocaml/parsing/ast_mapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,15 @@ module T = struct
as typ) =
let open Typ in
let loc = sub.location sub loc in
let attrs = sub.attributes sub attrs in
match Jane_syntax.Core_type.of_ast typ with
| Some jtyp -> begin
Jane_syntax_parsing.Core_type.wrap_desc ~loc ~attrs @@
| Some (jtyp, attrs) -> begin
let attrs = sub.attributes sub attrs in
Jane_syntax_parsing.AST.wrap_desc Core_type ~loc ~attrs @@
match sub.typ_jane_syntax sub jtyp with
| _ -> .
end
| None ->
let attrs = sub.attributes sub attrs in
match desc with
| Ptyp_any -> any ~loc ~attrs ()
| Ptyp_var s -> var ~loc ~attrs s
Expand Down Expand Up @@ -298,14 +299,15 @@ module MT = struct
({pmty_desc = desc; pmty_loc = loc; pmty_attributes = attrs} as mty) =
let open Mty in
let loc = sub.location sub loc in
let attrs = sub.attributes sub attrs in
match Jane_syntax.Module_type.of_ast mty with
| Some jmty -> begin
Jane_syntax_parsing.Module_type.wrap_desc ~loc ~attrs @@
| Some (jmty, attrs) -> begin
let attrs = sub.attributes sub attrs in
Jane_syntax_parsing.AST.wrap_desc Module_type ~loc ~attrs @@
match sub.module_type_jane_syntax sub jmty with
| Jmty_strengthen smty -> Jane_syntax.Strengthen.mty_of ~loc smty
end
| None ->
let attrs = sub.attributes sub attrs in
match desc with
| Pmty_ident s -> ident ~loc ~attrs (map_loc sub s)
| Pmty_alias s -> alias ~loc ~attrs (map_loc sub s)
Expand Down Expand Up @@ -352,7 +354,7 @@ module MT = struct
let loc = sub.location sub loc in
match Jane_syntax.Signature_item.of_ast sigi with
| Some jsigi -> begin
Jane_syntax_parsing.Signature_item.wrap_desc ~loc ~attrs:[] @@
Jane_syntax_parsing.AST.wrap_desc Signature_item ~loc ~attrs:[] @@
match sub.signature_item_jane_syntax sub jsigi with
| Jsig_include_functor incl ->
Jane_syntax.Include_functor.sig_item_of ~loc incl
Expand Down Expand Up @@ -432,7 +434,7 @@ module M = struct
let loc = sub.location sub loc in
match Jane_syntax.Structure_item.of_ast stri with
| Some jstri -> begin
Jane_syntax_parsing.Structure_item.wrap_desc ~loc ~attrs:[] @@
Jane_syntax_parsing.AST.wrap_desc Structure_item ~loc ~attrs:[] @@
match sub.structure_item_jane_syntax sub jstri with
| Jstr_include_functor incl ->
Jane_syntax.Include_functor.str_item_of ~loc incl
Expand Down Expand Up @@ -507,15 +509,16 @@ module E = struct
({pexp_loc = loc; pexp_desc = desc; pexp_attributes = attrs} as exp) =
let open Exp in
let loc = sub.location sub loc in
let attrs = sub.attributes sub attrs in
match Jane_syntax.Expression.of_ast exp with
| Some jexp -> begin
Jane_syntax_parsing.Expression.wrap_desc ~loc ~attrs @@
| Some (jexp, attrs) -> begin
let attrs = sub.attributes sub attrs in
Jane_syntax_parsing.AST.wrap_desc Expression ~loc ~attrs @@
match sub.expr_jane_syntax sub jexp with
| Jexp_comprehension c -> Jane_syntax.Comprehensions.expr_of ~loc c
| Jexp_immutable_array i -> Jane_syntax.Immutable_arrays.expr_of ~loc i
end
| None ->
let attrs = sub.attributes sub attrs in
match desc with
| Pexp_ident x -> ident ~loc ~attrs (map_loc sub x)
| Pexp_constant x -> constant ~loc ~attrs (sub.constant sub x)
Expand Down Expand Up @@ -617,14 +620,15 @@ module P = struct
({ppat_desc = desc; ppat_loc = loc; ppat_attributes = attrs} as pat) =
let open Pat in
let loc = sub.location sub loc in
let attrs = sub.attributes sub attrs in
match Jane_syntax.Pattern.of_ast pat with
| Some jpat -> begin
Jane_syntax_parsing.Pattern.wrap_desc ~loc ~attrs @@
| Some (jpat, attrs) -> begin
let attrs = sub.attributes sub attrs in
Jane_syntax_parsing.AST.wrap_desc Pattern ~loc ~attrs @@
match sub.pat_jane_syntax sub jpat with
| Jpat_immutable_array i -> Jane_syntax.Immutable_arrays.pat_of ~loc i
end
| None ->
let attrs = sub.attributes sub attrs in
match desc with
| Ppat_any -> any ~loc ~attrs ()
| Ppat_var s -> var ~loc ~attrs (map_loc sub s)
Expand Down
10 changes: 5 additions & 5 deletions ocaml/parsing/depend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ let handle_extension ext =

let rec add_type bv ty =
match Jane_syntax.Core_type.of_ast ty with
| Some jty -> add_type_jst bv jty
| Some (jty, _attrs) -> add_type_jst bv jty
| None ->
match ty.ptyp_desc with
Ptyp_any -> ()
Expand Down Expand Up @@ -173,7 +173,7 @@ let pattern_bv = ref String.Map.empty

let rec add_pattern bv pat =
match Jane_syntax.Pattern.of_ast pat with
| Some jpat -> add_pattern_jane_syntax bv jpat
| Some (jpat, _attrs) -> add_pattern_jane_syntax bv jpat
| None ->
match pat.ppat_desc with
Ppat_any -> ()
Expand Down Expand Up @@ -212,7 +212,7 @@ let add_pattern bv pat =

let rec add_expr bv exp =
match Jane_syntax.Expression.of_ast exp with
| Some jexp -> add_expr_jane_syntax bv jexp
| Some (jexp, _attrs) -> add_expr_jane_syntax bv jexp
| None ->
match exp.pexp_desc with
Pexp_ident l -> add bv l
Expand Down Expand Up @@ -347,7 +347,7 @@ and add_binding_op bv bv' pbop =

and add_modtype bv mty =
match Jane_syntax.Module_type.of_ast mty with
| Some jmty -> add_modtype_jane_syntax bv jmty
| Some (jmty, _attrs) -> add_modtype_jane_syntax bv jmty
| None ->
match mty.pmty_desc with
Pmty_ident l -> add bv l
Expand Down Expand Up @@ -397,7 +397,7 @@ and add_module_alias bv l =

and add_modtype_binding bv mty =
match Jane_syntax.Module_type.of_ast mty with
| Some jmty -> add_modtype_jane_syntax_binding bv jmty
| Some (jmty, _attrs) -> add_modtype_jane_syntax_binding bv jmty
| None ->
match mty.pmty_desc with
Pmty_alias l ->
Expand Down
Loading