@@ -464,7 +464,7 @@ module type AST_syntactic_category = sig
464
464
?loc : Location .t -> attrs :attributes -> ast_desc -> ast
465
465
end
466
466
467
- module type AST = sig
467
+ module type AST_internal = sig
468
468
include AST_syntactic_category
469
469
470
470
val embedding_syntax : Embedding_syntax .t
@@ -543,9 +543,9 @@ module Make_with_attribute
543
543
val attributes : ast -> attributes
544
544
val with_attributes : ast -> attributes -> ast
545
545
end ) :
546
- AST with type ast = AST_syntactic_category. ast
547
- and type ast_desc =
548
- AST_syntactic_category. ast_desc With_attributes. t
546
+ AST_internal with type ast = AST_syntactic_category. ast
547
+ and type ast_desc =
548
+ AST_syntactic_category. ast_desc With_attributes. t
549
549
= struct
550
550
include AST_syntactic_category
551
551
@@ -606,8 +606,8 @@ module Make_with_extension_node
606
606
[AST.match_extension]). Partial inverse of [make_extension_use]. *)
607
607
val match_extension_use : ast -> (extension * ast ) option
608
608
end ) :
609
- AST with type ast = AST_syntactic_category. ast
610
- and type ast_desc = AST_syntactic_category. ast_desc =
609
+ AST_internal with type ast = AST_syntactic_category. ast
610
+ and type ast_desc = AST_syntactic_category. ast_desc =
611
611
struct
612
612
include AST_syntactic_category
613
613
@@ -655,21 +655,21 @@ module Type_AST_syntactic_category = struct
655
655
end
656
656
657
657
(* * Types; embedded as [[[%jane.FEATNAME] * BODY]]. *)
658
- module Core_type = Make_with_attribute (struct
658
+ module Core_type0 = Make_with_attribute (struct
659
659
include Type_AST_syntactic_category
660
660
661
661
let plural = " types"
662
662
end )
663
663
664
664
(* * Constructor arguments; the same as types, but used in fewer places *)
665
- module Constructor_argument = Make_with_attribute (struct
665
+ module Constructor_argument0 = Make_with_attribute (struct
666
666
include Type_AST_syntactic_category
667
667
668
668
let plural = " constructor arguments"
669
669
end )
670
670
671
671
(* * Expressions; embedded using an attribute on the expression. *)
672
- module Expression = Make_with_attribute (struct
672
+ module Expression0 = Make_with_attribute (struct
673
673
type ast = expression
674
674
type ast_desc = expression_desc
675
675
@@ -685,7 +685,7 @@ module Expression = Make_with_attribute (struct
685
685
end )
686
686
687
687
(* * Patterns; embedded using an attribute on the pattern. *)
688
- module Pattern = Make_with_attribute (struct
688
+ module Pattern0 = Make_with_attribute (struct
689
689
type ast = pattern
690
690
type ast_desc = pattern_desc
691
691
@@ -701,7 +701,7 @@ module Pattern = Make_with_attribute (struct
701
701
end )
702
702
703
703
(* * Module types; embedded using an attribute on the module type. *)
704
- module Module_type = Make_with_attribute (struct
704
+ module Module_type0 = Make_with_attribute (struct
705
705
type ast = module_type
706
706
type ast_desc = module_type_desc
707
707
720
720
[include sig [%%extension.EXTNAME];; BODY end]. Signature items don't have
721
721
attributes or we'd use them instead.
722
722
*)
723
- module Signature_item = Make_with_extension_node (struct
723
+ module Signature_item0 = Make_with_extension_node (struct
724
724
type ast = signature_item
725
725
type ast_desc = signature_item_desc
726
726
763
763
[include struct [%%extension.EXTNAME];; BODY end]. Structure items don't
764
764
have attributes or we'd use them instead.
765
765
*)
766
- module Structure_item = Make_with_extension_node (struct
766
+ module Structure_item0 = Make_with_extension_node (struct
767
767
type ast = structure_item
768
768
type ast_desc = structure_item_desc
769
769
@@ -803,51 +803,37 @@ module Structure_item = Make_with_extension_node (struct
803
803
end )
804
804
805
805
(* *****************************************************************************)
806
+ (* Main exports *)
806
807
807
- module AST = struct
808
- type (_, _) t =
809
- | Expression : (expression , expression_desc With_attributes .t ) t
810
- | Pattern : (pattern , pattern_desc With_attributes .t ) t
811
- | Module_type : (module_type , module_type_desc With_attributes .t ) t
812
- | Signature_item : (signature_item , signature_item_desc ) t
813
- | Structure_item : (structure_item , structure_item_desc ) t
814
- | Core_type : (core_type , core_type_desc With_attributes .t ) t
815
- | Constructor_argument : (core_type , core_type_desc With_attributes .t ) t
816
-
817
- let to_module (type ast ast_desc ) (t : (ast, ast_desc) t ) :
818
- (module AST with type ast = ast and type ast_desc = ast_desc ) =
819
- match t with
820
- | Expression -> (module Expression )
821
- | Pattern -> (module Pattern )
822
- | Module_type -> (module Module_type )
823
- | Signature_item -> (module Signature_item )
824
- | Structure_item -> (module Structure_item )
825
- | Core_type -> (module Core_type )
826
- | Constructor_argument -> (module Constructor_argument )
827
-
828
- let wrap_desc (type ast ast_desc ) (t : (ast, ast_desc) t ) =
829
- let (module AST ) = to_module t in
830
- AST. wrap_desc
831
-
832
- let make_jane_syntax
833
- (type ast ast_desc )
834
- (t : (ast, ast_desc) t )
835
- feature
836
- trailing_components
837
- ast
838
- =
839
- let (module AST ) = to_module t in
808
+ module type AST = sig
809
+ type ast
810
+ type ast_desc
811
+
812
+ val wrap_desc :
813
+ ?loc : Location .t -> attrs :Parsetree .attributes -> ast_desc -> ast
814
+ val make_jane_syntax : Feature .t -> string list -> ast -> ast_desc
815
+ val make_entire_jane_syntax :
816
+ loc :Location .t -> Feature .t -> (unit -> ast ) -> ast_desc
817
+ val make_of_ast :
818
+ of_ast_internal :(Feature .t -> ast -> 'a option ) -> (ast -> 'a option )
819
+ end
820
+
821
+ module Make_ast (AST : AST_internal ) : AST with type ast = AST. ast
822
+ and type ast_desc = AST. ast_desc
823
+ = struct
824
+ include AST
825
+
826
+ let make_jane_syntax feature trailing_components ast =
840
827
AST. make_jane_syntax
841
828
(Embedded_name. of_feature feature trailing_components)
842
829
ast
843
830
844
- let make_entire_jane_syntax t ~loc feature ast =
845
- make_jane_syntax t feature []
831
+ let make_entire_jane_syntax ~loc feature ast =
832
+ make_jane_syntax feature []
846
833
(Ast_helper. with_default_loc (Location. ghostify loc) ast)
847
834
848
835
(* * Generically lift our custom ASTs for our novel syntax from OCaml ASTs. *)
849
- let make_of_ast (type ast ast_desc ) (t : (ast, ast_desc) t ) ~of_ast_internal =
850
- let (module AST ) = to_module t in
836
+ let make_of_ast ~of_ast_internal =
851
837
let of_ast ast =
852
838
let loc = AST. location ast in
853
839
let raise_error err = raise (Error (loc, err)) in
@@ -873,3 +859,11 @@ module AST = struct
873
859
in
874
860
of_ast
875
861
end
862
+
863
+ module Expression = Make_ast (Expression0 )
864
+ module Pattern = Make_ast (Pattern0 )
865
+ module Module_type = Make_ast (Module_type0 )
866
+ module Signature_item = Make_ast (Signature_item0 )
867
+ module Structure_item = Make_ast (Structure_item0 )
868
+ module Core_type = Make_ast (Core_type0 )
869
+ module Constructor_argument = Make_ast (Constructor_argument0 )
0 commit comments