Skip to content

Commit c0f3e43

Browse files
committed
Skeleton to modernise ast.
There's `Parsetree`, the current parse tree, and `Parsetree0`, the legacy parse tree. Module `Parsetree.Legacy` contains functions to map to the legacy parse tree.
1 parent 7da4d6a commit c0f3e43

File tree

3 files changed

+1267
-0
lines changed

3 files changed

+1267
-0
lines changed

compiler/ml/parsetree.ml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,3 +596,74 @@ and module_binding = {
596596
pmb_loc: Location.t;
597597
}
598598
(* X = ME *)
599+
600+
module Legacy = struct
601+
let rec expression (e : expression) : Parsetree0.expression =
602+
{
603+
pexp_desc = expression_desc e.pexp_desc;
604+
pexp_loc = e.pexp_loc;
605+
pexp_attributes = attributes e.pexp_attributes;
606+
}
607+
608+
and expression_desc (_e : expression_desc) : Parsetree0.expression_desc =
609+
assert false
610+
611+
and expression_option (e : expression option) : Parsetree0.expression option =
612+
Option.map expression e
613+
614+
and attributes (a : attributes) : Parsetree0.attributes = List.map attribute a
615+
616+
and attribute ((lbl, p) : attribute) : Parsetree0.attribute = (lbl, payload p)
617+
618+
and payload (p : payload) : Parsetree0.payload =
619+
match p with
620+
| PStr s -> PStr (structure s)
621+
| PPat (p, l) -> PPat (pattern p, expression_option l)
622+
| PTyp t -> PTyp (core_type t)
623+
| PSig s -> PSig (signature s)
624+
625+
and structure (s : structure) : Parsetree0.structure =
626+
List.map structure_item s
627+
628+
and structure_item (_i : structure_item) : Parsetree0.structure_item =
629+
assert false
630+
631+
and signature (s : signature) : Parsetree0.signature =
632+
List.map signature_item s
633+
634+
and signature_item (_i : signature_item) : Parsetree0.signature_item =
635+
assert false
636+
637+
and pattern (_p : pattern) : Parsetree0.pattern = assert false
638+
639+
and core_type (t : core_type) : Parsetree0.core_type =
640+
{
641+
ptyp_desc = core_type_desc t.ptyp_desc;
642+
ptyp_loc = t.ptyp_loc;
643+
ptyp_attributes = attributes t.ptyp_attributes;
644+
}
645+
646+
and core_type_desc (d : core_type_desc) : Parsetree0.core_type_desc =
647+
match d with
648+
| Ptyp_any -> Ptyp_any
649+
| Ptyp_var s -> Ptyp_var s
650+
| Ptyp_arrow (lbl, t1, t2) -> Ptyp_arrow (lbl, core_type t1, core_type t2)
651+
| Ptyp_tuple tl -> Ptyp_tuple (List.map core_type tl)
652+
| Ptyp_constr (lid, tl) -> Ptyp_constr (lid, List.map core_type tl)
653+
| Ptyp_object (fields, closed) ->
654+
Ptyp_object (List.map object_field fields, closed)
655+
| Ptyp_class () -> Ptyp_class ()
656+
| Ptyp_alias (t, lid) -> Ptyp_alias (core_type t, lid)
657+
| Ptyp_variant (row_fields, closed, labels) ->
658+
Ptyp_variant (List.map row_field row_fields, closed, labels)
659+
| Ptyp_poly (s, t) -> Ptyp_poly (s, core_type t)
660+
| Ptyp_package (lid, tl) ->
661+
Ptyp_package (lid, List.map (fun (l, t) -> (l, core_type t)) tl)
662+
| Ptyp_extension ext -> Ptyp_extension (extension ext)
663+
664+
and object_field (_f : object_field) : Parsetree0.object_field = assert false
665+
666+
and row_field (_f : row_field) : Parsetree0.row_field = assert false
667+
668+
and extension (_e : extension) : Parsetree0.extension = assert false
669+
end

0 commit comments

Comments
 (0)