Skip to content

Commit 2c2e5b7

Browse files
committed
Print module
1 parent e1227bc commit 2c2e5b7

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

tools/src/print_tast.ml

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ module Transform = struct
3838
aux path;
3939
Buffer.contents buf
4040

41+
let mk_path path = Ident (path_to_string path)
42+
4143
let mk_row_field (row_field : Types.row_field) : oak =
4244
match row_field with
4345
| Rpresent _ -> Ident "row_field.Rpresent"
@@ -58,7 +60,7 @@ module Transform = struct
5860
( "type_desc.Tconstr",
5961
Tuple
6062
[
61-
{name = "path"; value = Ident (path_to_string path)};
63+
{name = "path"; value = mk_path path};
6264
{name = "ts"; value = mk_type_expr_list ts};
6365
] )
6466
| Tarrow (_, t1, t2, _) ->
@@ -79,7 +81,7 @@ module Transform = struct
7981
Tuple
8082
[
8183
{name = "type_expr"; value = mk_type_desc t.desc};
82-
{name = "path"; value = Ident (path_to_string path)};
84+
{name = "path"; value = mk_path path};
8385
{
8486
name = "ts";
8587
value =
@@ -123,7 +125,7 @@ module Transform = struct
123125
( "type_desc.Tpackage",
124126
Tuple
125127
[
126-
{name = "path"; value = Ident (path_to_string path)};
128+
{name = "path"; value = mk_path path};
127129
{name = "lids"; value = List lids};
128130
{name = "ts"; value = mk_type_expr_list ts};
129131
] )
@@ -157,7 +159,7 @@ module Transform = struct
157159
value =
158160
Tuple
159161
[
160-
{name = "Path.t"; value = Ident (path_to_string path)};
162+
{name = "Path.t"; value = mk_path path};
161163
{
162164
name = "fields";
163165
value =
@@ -419,8 +421,30 @@ module Transform = struct
419421
{name = "name"; value = String type_.name};
420422
{name = "attributes"; value = mk_attribute_list type_.attributes};
421423
]
424+
let rec mk_structure (structure : SharedTypes.Module.structure) : oak =
425+
Record
426+
[
427+
{name = "name"; value = String structure.name};
428+
{name = "docstring"; value = mk_string_list structure.docstring};
429+
{name = "items"; value = List (List.map mk_item structure.items)};
430+
{name = "deprecated"; value = mk_string_option structure.deprecated};
431+
]
432+
433+
and mk_module (module_ : SharedTypes.Module.t) : oak =
434+
match module_ with
435+
| SharedTypes.Module.Ident path -> Application ("Ident", mk_path path)
436+
| SharedTypes.Module.Structure structure ->
437+
Application ("Structure", mk_structure structure)
438+
| SharedTypes.Module.Constraint (t1, t2) ->
439+
Application
440+
( "Constraint",
441+
Tuple
442+
[
443+
{name = "t1"; value = mk_module t1};
444+
{name = "t2"; value = mk_module t2};
445+
] )
422446

423-
let mk_item (item : SharedTypes.Module.item) : oak =
447+
and mk_item (item : SharedTypes.Module.item) : oak =
424448
let kind =
425449
match item.kind with
426450
| SharedTypes.Module.Value v ->
@@ -433,7 +457,14 @@ module Transform = struct
433457
{name = "type"; value = mk_type t};
434458
{name = "rec_status"; value = mk_rec_status rec_status};
435459
] )
436-
| SharedTypes.Module.Module _ -> Ident "Module"
460+
| SharedTypes.Module.Module m ->
461+
Application
462+
( "Module",
463+
Record
464+
[
465+
{name = "type_"; value = mk_module m.type_};
466+
{name = "isModuleType"; value = mk_bool m.isModuleType};
467+
] )
437468
in
438469
Record
439470
[
@@ -443,15 +474,6 @@ module Transform = struct
443474
{name = "deprecated"; value = mk_string_option item.deprecated};
444475
]
445476

446-
let mk_structure (structure : SharedTypes.Module.structure) : oak =
447-
Record
448-
[
449-
{name = "name"; value = String structure.name};
450-
{name = "docstring"; value = mk_string_list structure.docstring};
451-
{name = "items"; value = List (List.map mk_item structure.items)};
452-
{name = "deprecated"; value = mk_string_option structure.deprecated};
453-
]
454-
455477
let mk_file (file : SharedTypes.File.t) : oak =
456478
Record
457479
[

0 commit comments

Comments
 (0)