Skip to content

Commit c8d675a

Browse files
committed
Support for type quote and splice
1 parent a31aa7b commit c8d675a

File tree

12 files changed

+32
-4
lines changed

12 files changed

+32
-4
lines changed

src/document/generator.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,10 @@ module Make (Syntax : SYNTAX) = struct
471471
(Link.from_path (path :> Paths.Path.t))
472472
| Poly (polyvars, t) ->
473473
O.txt ("'" ^ String.concat " '" polyvars ^ ". ") ++ type_expr t
474+
| Quote t ->
475+
O.span (O.txt "<[ " ++ O.box_hv (type_expr t) ++ O.txt " ]>")
476+
| Splice t ->
477+
O.span (O.txt "$" ++ type_expr ~needs_parentheses:true t)
474478
| Package pkg ->
475479
enclose ~l:"(" ~r:")"
476480
(O.keyword "module" ++ O.txt " "

src/loader/cmi.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,8 @@ let rec read_type_expr env typ =
529529
| Tsubst (typ,_) -> read_type_expr env typ
530530
#endif
531531
#if OCAML_VERSION = (5,2,0)
532-
| Tquote typ -> read_type_expr env typ
533-
| Tsplice typ -> read_type_expr env typ
532+
| Tquote typ -> Quote (read_type_expr env typ)
533+
| Tsplice typ -> Splice (read_type_expr env typ)
534534
#endif
535535
| Tlink _ -> assert false
536536
| Tof_kind _ -> assert false

src/loader/cmti.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ let rec read_core_type env container ctyp =
170170
read_core_type env container t
171171
#endif
172172
#if OCAML_VERSION = (5,2,0)
173-
| Ttyp_quote typ -> read_core_type env container typ
174-
| Ttyp_splice typ -> read_core_type env container typ
173+
| Ttyp_quote typ -> Quote (read_core_type env container typ)
174+
| Ttyp_splice typ -> Splice (read_core_type env container typ)
175175
#endif
176176
| Ttyp_call_pos -> Constr(Env.Path.read_type env.ident_env Predef.path_lexing_position, [])
177177
| Ttyp_of_kind _ -> assert false

src/model/lang.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,8 @@ and TypeExpr : sig
481481
| Object of TypeExpr.Object.t
482482
| Class of Path.ClassType.t * t list
483483
| Poly of string list * t
484+
| Quote of t
485+
| Splice of t
484486
| Package of TypeExpr.Package.t
485487
end =
486488
TypeExpr

src/model_desc/lang_desc.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,8 @@ and typeexpr_t =
665665
| Class (x1, x2) ->
666666
C ("Class", ((x1 :> Paths.Path.t), x2), Pair (path, List typeexpr_t))
667667
| Poly (x1, x2) -> C ("Poly", (x1, x2), Pair (List string, typeexpr_t))
668+
| Quote x -> C ("Quote", x, typeexpr_t)
669+
| Splice x -> C ("Splice", x, typeexpr_t)
668670
| Package x -> C ("Package", x, typeexpr_package))
669671

670672
(** {3 Compilation_unit} *)

src/xref2/compile.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,8 @@ and type_expression : Env.t -> Id.LabelParent.t -> _ -> _ =
945945
Class (`Resolved p, ts')
946946
| _ -> Class (path, ts'))
947947
| Poly (strs, t) -> Poly (strs, type_expression env parent t)
948+
| Quote t -> Quote (type_expression env parent t)
949+
| Splice t -> Splice (type_expression env parent t)
948950
| Package p -> Package (type_expression_package env parent p)
949951

950952
let compile ~filename env compilation_unit =

src/xref2/component.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ and TypeExpr : sig
130130
| Object of TypeExpr.Object.t
131131
| Class of Cpath.class_type * t list
132132
| Poly of string list * t
133+
| Quote of t
134+
| Splice of t
133135
| Package of TypeExpr.Package.t
134136
end =
135137
TypeExpr
@@ -1199,6 +1201,8 @@ module Fmt = struct
11991201
| Object x -> type_object c ppf x
12001202
| Class (x, y) -> type_class c ppf (x, y)
12011203
| Poly (_ss, _t) -> Format.fprintf ppf "(poly)"
1204+
| Quote t -> Format.fprintf ppf "(quote %a)" (type_expr c) t
1205+
| Splice t -> Format.fprintf ppf "(splice %a)" (type_expr c) t
12021206
| Package x -> type_package c ppf x
12031207

12041208
and resolved_module_path :
@@ -2340,6 +2344,8 @@ module Of_Lang = struct
23402344
Class
23412345
(class_type_path ident_map p, List.map (type_expression ident_map) ts)
23422346
| Object o -> Object (type_object ident_map o)
2347+
| Quote t -> Quote (type_expression ident_map t)
2348+
| Splice t -> Splice (type_expression ident_map t)
23432349
| Package p -> Package (type_package ident_map p)
23442350

23452351
and module_decl ident_map m =

src/xref2/component.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ and TypeExpr : sig
125125
| Object of TypeExpr.Object.t
126126
| Class of Cpath.class_type * t list
127127
| Poly of string list * t
128+
| Quote of t
129+
| Splice of t
128130
| Package of TypeExpr.Package.t
129131
end
130132

src/xref2/expand_tools.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ let rec type_expr map t =
6565
| Class (path, ts) -> Class (path, List.map (type_expr map) ts)
6666
| Poly (s, t) -> Poly (s, type_expr map t)
6767
| Package p -> Package (package map p)
68+
| Quote t -> Quote (type_expr map t)
69+
| Splice t -> Splice (type_expr map t)
6870

6971
and polymorphic_variant map pv =
7072
let open Lang.TypeExpr.Polymorphic_variant in

src/xref2/lang_of.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,8 @@ and type_expr map (parent : Identifier.LabelParent.t) (t : Component.TypeExpr.t)
10411041
| Class (p, ts) ->
10421042
Class (Path.class_type map p, List.map (type_expr map parent) ts)
10431043
| Poly (strs, t) -> Poly (strs, type_expr map parent t)
1044+
| Quote t -> Quote (type_expr map parent t)
1045+
| Splice t -> Splice (type_expr map parent t)
10441046
| Package p -> Package (type_expr_package map parent p)
10451047
with e ->
10461048
let bt = Printexc.get_backtrace () in

0 commit comments

Comments
 (0)