Skip to content

Commit 646b4ca

Browse files
committed
WIP: Upgrade latest_version to the actual 4.08 grammar
1 parent 68ea1a1 commit 646b4ca

23 files changed

+2502
-444
lines changed

ast/builder_v4_08.ml

Lines changed: 107 additions & 73 deletions
Large diffs are not rendered by default.

ast/builder_v4_08.mli

Lines changed: 87 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
(*$ Ppx_ast_cinaps.print_builder_mli (Astlib.Version.of_string "v4_08") *)
22
open Versions.V4_08
3+
val attribute :
4+
loc:Astlib.Location.t
5+
-> name:string Astlib.Loc.t
6+
-> payload:Payload.t
7+
-> Attribute.t
38
val ptyp_any :
49
loc:Astlib.Location.t
510
-> Core_type.t
@@ -56,6 +61,25 @@ val ptyp_extension :
5661
loc:Astlib.Location.t
5762
-> Extension.t
5863
-> Core_type.t
64+
val rtag :
65+
loc:Astlib.Location.t
66+
-> Label.t Astlib.Loc.t
67+
-> bool
68+
-> Core_type.t list
69+
-> Row_field.t
70+
val rinherit :
71+
loc:Astlib.Location.t
72+
-> Core_type.t
73+
-> Row_field.t
74+
val otag :
75+
loc:Astlib.Location.t
76+
-> Label.t Astlib.Loc.t
77+
-> Core_type.t
78+
-> Object_field.t
79+
val oinherit :
80+
loc:Astlib.Location.t
81+
-> Core_type.t
82+
-> Object_field.t
5983
val ppat_any :
6084
loc:Astlib.Location.t
6185
-> Pattern.t
@@ -301,9 +325,12 @@ val pexp_pack :
301325
-> Expression.t
302326
val pexp_open :
303327
loc:Astlib.Location.t
304-
-> Override_flag.t
305-
-> Longident_loc.t
328+
-> Open_declaration.t
329+
-> Expression.t
306330
-> Expression.t
331+
val pexp_letop :
332+
loc:Astlib.Location.t
333+
-> Letop.t
307334
-> Expression.t
308335
val pexp_extension :
309336
loc:Astlib.Location.t
@@ -317,6 +344,17 @@ val case :
317344
-> lhs:Pattern.t
318345
-> rhs:Expression.t
319346
-> Case.t
347+
val letop :
348+
ands:Binding_op.t list
349+
-> body:Expression.t
350+
-> let_:Binding_op.t
351+
-> Letop.t
352+
val binding_op :
353+
loc:Astlib.Location.t
354+
-> exp:Expression.t
355+
-> op:string Astlib.Loc.t
356+
-> pat:Pattern.t
357+
-> Binding_op.t
320358
val value_description :
321359
loc:Astlib.Location.t
322360
-> name:string Astlib.Loc.t
@@ -345,7 +383,8 @@ val constructor_declaration :
345383
-> res:Core_type.t option
346384
-> Constructor_declaration.t
347385
val type_extension :
348-
constructors:Extension_constructor.t list
386+
loc:Astlib.Location.t
387+
-> constructors:Extension_constructor.t list
349388
-> params:(Core_type.t * Variance.t) list
350389
-> path:Longident_loc.t
351390
-> private_:Private_flag.t
@@ -355,6 +394,10 @@ val extension_constructor :
355394
-> kind:Extension_constructor_kind.t
356395
-> name:string Astlib.Loc.t
357396
-> Extension_constructor.t
397+
val type_exception :
398+
loc:Astlib.Location.t
399+
-> constructor:Extension_constructor.t
400+
-> Type_exception.t
358401
val pcty_constr :
359402
loc:Astlib.Location.t
360403
-> Longident_loc.t
@@ -376,8 +419,7 @@ val pcty_extension :
376419
-> Class_type.t
377420
val pcty_open :
378421
loc:Astlib.Location.t
379-
-> Override_flag.t
380-
-> Longident_loc.t
422+
-> Open_description.t
381423
-> Class_type.t
382424
-> Class_type.t
383425
val class_signature :
@@ -524,6 +566,10 @@ val psig_type :
524566
-> Rec_flag.t
525567
-> Type_declaration.t list
526568
-> Signature_item.t
569+
val psig_typesubst :
570+
loc:Astlib.Location.t
571+
-> Type_declaration.t list
572+
-> Signature_item.t
527573
val psig_typext :
528574
loc:Astlib.Location.t
529575
-> Type_extension.t
@@ -536,6 +582,10 @@ val psig_module :
536582
loc:Astlib.Location.t
537583
-> Module_declaration.t
538584
-> Signature_item.t
585+
val psig_modsubst :
586+
loc:Astlib.Location.t
587+
-> Module_substitution.t
588+
-> Signature_item.t
539589
val psig_recmodule :
540590
loc:Astlib.Location.t
541591
-> Module_declaration.t list
@@ -574,16 +624,16 @@ val module_declaration :
574624
-> name:string Astlib.Loc.t
575625
-> type_:Module_type.t
576626
-> Module_declaration.t
627+
val module_substitution :
628+
loc:Astlib.Location.t
629+
-> manifest:Longident_loc.t
630+
-> name:string Astlib.Loc.t
631+
-> Module_substitution.t
577632
val module_type_declaration :
578633
loc:Astlib.Location.t
579634
-> name:string Astlib.Loc.t
580635
-> type_:Module_type.t option
581636
-> Module_type_declaration.t
582-
val open_description :
583-
loc:Astlib.Location.t
584-
-> lid:Longident_loc.t
585-
-> override:Override_flag.t
586-
-> Open_description.t
587637
val pmod_ident :
588638
loc:Astlib.Location.t
589639
-> Longident_loc.t
@@ -641,7 +691,7 @@ val pstr_typext :
641691
-> Structure_item.t
642692
val pstr_exception :
643693
loc:Astlib.Location.t
644-
-> Extension_constructor.t
694+
-> Type_exception.t
645695
-> Structure_item.t
646696
val pstr_module :
647697
loc:Astlib.Location.t
@@ -657,7 +707,7 @@ val pstr_modtype :
657707
-> Structure_item.t
658708
val pstr_open :
659709
loc:Astlib.Location.t
660-
-> Open_description.t
710+
-> Open_declaration.t
661711
-> Structure_item.t
662712
val pstr_class :
663713
loc:Astlib.Location.t
@@ -690,4 +740,29 @@ val module_binding :
690740
-> expr:Module_expr.t
691741
-> name:string Astlib.Loc.t
692742
-> Module_binding.t
743+
val toplevel_directive :
744+
loc:Astlib.Location.t
745+
-> arg:Directive_argument.t option
746+
-> name:string Astlib.Loc.t
747+
-> Toplevel_directive.t
748+
val pdir_none :
749+
loc:Astlib.Location.t
750+
-> Directive_argument.t
751+
val pdir_string :
752+
loc:Astlib.Location.t
753+
-> string
754+
-> Directive_argument.t
755+
val pdir_int :
756+
loc:Astlib.Location.t
757+
-> string
758+
-> char option
759+
-> Directive_argument.t
760+
val pdir_ident :
761+
loc:Astlib.Location.t
762+
-> Longident.t
763+
-> Directive_argument.t
764+
val pdir_bool :
765+
loc:Astlib.Location.t
766+
-> bool
767+
-> Directive_argument.t
693768
(*$*)

ast/cinaps/gen_builder.ml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,17 @@ module Builder = struct
164164
match (shortcut type_name : Shortcut.t option) with
165165
| None -> []
166166
| Some {other_fields = _::_; _} ->
167-
(* There currently is only attr, loc and descr in records for which we
168-
have shortcuts and the code here relies on it, if new fields or added
169-
we'll need do deal with them.
170-
Note that a [xxx_loc_stack] has been added in recent OCaml versions. *)
167+
(* There currently is only attr, loc, loc_stack and descr in records for
168+
which we have shortcuts and the code here relies on it, if new fields
169+
are added we'll need do deal with them. *)
171170
assert false
172-
| Some {outer_record; desc_field; loc_field; attr_field; other_fields = []; _} ->
171+
| Some
172+
{ outer_record
173+
; desc_field
174+
; loc_field
175+
; attr_field
176+
; loc_stack_field
177+
; other_fields = []; _} ->
173178
let type_ = Astlib.Grammar.Name outer_record in
174179
List.map v ~f:(fun (cname, (constr : Astlib.Grammar.clause)) ->
175180
let arr =
@@ -206,6 +211,7 @@ module Builder = struct
206211
[ Some (Some desc_field, desc)
207212
; (loc_field >>| fun fname -> (Some fname, Expr.Ident "loc"))
208213
; (attr_field >>| fun fname -> (Some fname, empty_attributes))
214+
; (loc_stack_field >>| fun fname -> (Some fname, Expr.Const Nil))
209215
]
210216
|> List.filter_opt
211217
in

ast/cinaps/shortcut.ml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ type t =
66
; desc_field : string
77
; attr_field : string option
88
; loc_field : string option
9+
; loc_stack_field : string option
910
; other_fields : (string * Astlib.Grammar.ty) list
1011
}
1112

@@ -18,6 +19,7 @@ let find_field ~suffix record : (string * Astlib.Grammar.ty) option =
1819
let loc_suffix = "_loc"
1920
let desc_suffix = "_desc"
2021
let attr_suffix = "_attributes"
22+
let loc_stack_suffix = "_loc_stack"
2123

2224
let desc_field record = find_field ~suffix:desc_suffix record
2325

@@ -33,24 +35,32 @@ let loc_field record =
3335
| Some (loc_field, Location) -> Some loc_field
3436
| Some (_, _) -> assert false
3537

38+
let loc_stack_field record =
39+
match find_field ~suffix:loc_stack_suffix record with
40+
| None -> None
41+
| Some (loc_stack_field, List Location) -> Some loc_stack_field
42+
| Some (_, _) -> assert false
43+
3644
let other_fields record =
3745
List.filter record
3846
~f:(fun (field_name, _) ->
3947
not
4048
( String.is_suffix ~suffix:loc_suffix field_name
4149
|| String.is_suffix ~suffix:desc_suffix field_name
42-
|| String.is_suffix ~suffix:attr_suffix field_name ))
50+
|| String.is_suffix ~suffix:attr_suffix field_name
51+
|| String.is_suffix ~suffix:loc_stack_suffix field_name))
4352

4453
let from_record ~name record =
4554
match desc_field record with
4655
| None -> None
4756
| Some (desc_field, Name inner_variant) ->
4857
let loc_field = loc_field record in
4958
let attr_field = attr_field record in
59+
let loc_stack_field = loc_stack_field record in
5060
let other_fields = other_fields record in
5161
Some
5262
{ outer_record = name; inner_variant
53-
; desc_field; loc_field; attr_field; other_fields }
63+
; desc_field; loc_field; attr_field; loc_stack_field; other_fields }
5464
| Some (_, _) ->
5565
assert false
5666

ast/cinaps/shortcut.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
description
66
- [loc_field] is the name of the field in the parent pointing to the
77
location, if any
8+
- [loc_stack_field] is the name of the field in the parent pointing to the
9+
location stack, if any
810
- [attr_field] is the name of the field in the parent pointing to the
911
attributes, if any
1012
- [other_fields] is the list of the remaining fields of the parent *)
@@ -14,6 +16,7 @@ type t =
1416
; desc_field : string
1517
; attr_field : string option
1618
; loc_field : string option
19+
; loc_stack_field : string option
1720
; other_fields : (string * Astlib.Grammar.ty) list
1821
}
1922

0 commit comments

Comments
 (0)