Skip to content

Commit d7b4ee6

Browse files
committed
WIP: Upgrade latest_version to the actual 4.08 grammar
1 parent 4018c9b commit d7b4ee6

28 files changed

+3152
-532
lines changed

ast/builder_v4_08.ml

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

ast/builder_v4_08.mli

Lines changed: 86 additions & 15 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+
-> string 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+
-> string 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,10 +325,13 @@ 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
306329
-> Expression.t
307330
-> Expression.t
331+
val pexp_letop :
332+
loc:Astlib.Location.t
333+
-> Letop.t
334+
-> Expression.t
308335
val pexp_extension :
309336
loc:Astlib.Location.t
310337
-> Extension.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 :
@@ -446,8 +488,7 @@ val pcl_extension :
446488
-> Class_expr.t
447489
val pcl_open :
448490
loc:Astlib.Location.t
449-
-> Override_flag.t
450-
-> Longident_loc.t
491+
-> Open_description.t
451492
-> Class_expr.t
452493
-> Class_expr.t
453494
val class_structure :
@@ -524,18 +565,26 @@ val psig_type :
524565
-> Rec_flag.t
525566
-> Type_declaration.t list
526567
-> Signature_item.t
568+
val psig_typesubst :
569+
loc:Astlib.Location.t
570+
-> Type_declaration.t list
571+
-> Signature_item.t
527572
val psig_typext :
528573
loc:Astlib.Location.t
529574
-> Type_extension.t
530575
-> Signature_item.t
531576
val psig_exception :
532577
loc:Astlib.Location.t
533-
-> Extension_constructor.t
578+
-> Type_exception.t
534579
-> Signature_item.t
535580
val psig_module :
536581
loc:Astlib.Location.t
537582
-> Module_declaration.t
538583
-> Signature_item.t
584+
val psig_modsubst :
585+
loc:Astlib.Location.t
586+
-> Module_substitution.t
587+
-> Signature_item.t
539588
val psig_recmodule :
540589
loc:Astlib.Location.t
541590
-> Module_declaration.t list
@@ -574,16 +623,16 @@ val module_declaration :
574623
-> name:string Astlib.Loc.t
575624
-> type_:Module_type.t
576625
-> Module_declaration.t
626+
val module_substitution :
627+
loc:Astlib.Location.t
628+
-> manifest:Longident_loc.t
629+
-> name:string Astlib.Loc.t
630+
-> Module_substitution.t
577631
val module_type_declaration :
578632
loc:Astlib.Location.t
579633
-> name:string Astlib.Loc.t
580634
-> type_:Module_type.t option
581635
-> 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
587636
val pmod_ident :
588637
loc:Astlib.Location.t
589638
-> Longident_loc.t
@@ -641,7 +690,7 @@ val pstr_typext :
641690
-> Structure_item.t
642691
val pstr_exception :
643692
loc:Astlib.Location.t
644-
-> Extension_constructor.t
693+
-> Type_exception.t
645694
-> Structure_item.t
646695
val pstr_module :
647696
loc:Astlib.Location.t
@@ -657,7 +706,7 @@ val pstr_modtype :
657706
-> Structure_item.t
658707
val pstr_open :
659708
loc:Astlib.Location.t
660-
-> Open_description.t
709+
-> Open_declaration.t
661710
-> Structure_item.t
662711
val pstr_class :
663712
loc:Astlib.Location.t
@@ -690,4 +739,26 @@ val module_binding :
690739
-> expr:Module_expr.t
691740
-> name:string Astlib.Loc.t
692741
-> Module_binding.t
742+
val toplevel_directive :
743+
loc:Astlib.Location.t
744+
-> arg:Directive_argument.t option
745+
-> name:string Astlib.Loc.t
746+
-> Toplevel_directive.t
747+
val pdir_string :
748+
loc:Astlib.Location.t
749+
-> string
750+
-> Directive_argument.t
751+
val pdir_int :
752+
loc:Astlib.Location.t
753+
-> string
754+
-> char option
755+
-> Directive_argument.t
756+
val pdir_ident :
757+
loc:Astlib.Location.t
758+
-> Longident.t
759+
-> Directive_argument.t
760+
val pdir_bool :
761+
loc:Astlib.Location.t
762+
-> bool
763+
-> Directive_argument.t
693764
(*$*)

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/gen_viewer.ml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ let wrapper_types grammar =
1515
| _ -> acc)
1616

1717
let shortcut_viewer_name ~shortcut cname =
18-
let _, base_name = String.lsplit2_exn ~on:'_' cname in
18+
let base_name =
19+
match String.lsplit2 ~on:'_' cname with
20+
| Some (_prefix, basename) -> basename
21+
| None -> String.lowercase_ascii cname
22+
in
1923
let prefix =
2024
match shortcut.Shortcut.outer_record with
2125
| "expression" -> "e"
@@ -29,6 +33,9 @@ let shortcut_viewer_name ~shortcut cname =
2933
| "class_expr" -> "ce"
3034
| "class_type" -> "ct"
3135
| "class_type_field" -> "ctf"
36+
| "row_field" -> "rf"
37+
| "object_field" -> "of"
38+
| "directive_argument" -> "da"
3239
| s -> failwith "No prefix for shortcut: " ^ s
3340
in
3441
variant_viewer_name (prefix ^ base_name)

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)