@@ -98,6 +98,12 @@ type t =
9898 | Direct of (Loc .t * Lib_name .t )
9999 | Re_export of (Loc .t * Lib_name .t )
100100 | Select of Select .t
101+ | Instantiate of
102+ { loc : Loc .t
103+ ; lib : Lib_name .t
104+ ; arguments : (Loc .t * Lib_name .t ) list
105+ ; new_name : Module_name .t option
106+ }
101107
102108let equal = Poly. equal
103109
@@ -107,6 +113,13 @@ let to_dyn =
107113 | Direct (_ , name ) -> Lib_name. to_dyn name
108114 | Re_export (_ , name ) -> variant " re_export" [ Lib_name. to_dyn name ]
109115 | Select s -> variant " select" [ Select. to_dyn s ]
116+ | Instantiate { lib; arguments; new_name; loc = _ } ->
117+ variant
118+ " instantiate"
119+ [ Lib_name. to_dyn lib
120+ ; list (fun (_ , arg ) -> Lib_name. to_dyn arg) arguments
121+ ; option Module_name. to_dyn new_name
122+ ]
110123;;
111124
112125let direct x = Direct x
@@ -126,6 +139,19 @@ let decode ~allow_re_export =
126139 , let + select = Select. decode in
127140 Select select )
128141 ]
142+ < |> enter
143+ ((* TODO art-w: oxcaml extension is not recognized by installed
144+ libraries, which are missing a `(using oxcaml 0.1)`
145+ let+ () = Syntax.since Oxcaml.syntax (0, 1) *)
146+ let + () = Syntax. since Stanza. syntax (3 , 20 )
147+ and + loc, lib = located Lib_name. decode
148+ and + arguments, new_name =
149+ until_keyword
150+ " :as"
151+ ~before: (located Lib_name. decode)
152+ ~after: Module_name. decode
153+ in
154+ Instantiate { loc; lib; arguments; new_name })
129155 < |> let + loc, name = located Lib_name. decode in
130156 Direct (loc, name))
131157 in
@@ -144,11 +170,22 @@ let encode =
144170 Code_error. raise
145171 " Lib_dep.encode: cannot encode select"
146172 [ " select" , Select. to_dyn select ]
173+ | Instantiate { lib; arguments; new_name; loc = _ } ->
174+ let as_name =
175+ match new_name with
176+ | None -> []
177+ | Some new_name -> [ string " :as" ; Module_name. encode new_name ]
178+ in
179+ list
180+ sexp
181+ ((Lib_name. encode lib :: List. map arguments ~f: (fun (_ , arg ) -> Lib_name. encode arg))
182+ @ as_name)
147183;;
148184
149185module L = struct
150186 type kind =
151187 | Required
188+ | Required_multiple
152189 | Optional
153190 | Forbidden
154191
@@ -186,12 +223,21 @@ module L = struct
186223 [ Pp. textf
187224 " library %S is present both as a forbidden and required dependency"
188225 (Lib_name. to_string name)
226+ ]
227+ | Required_multiple , Required_multiple -> acc
228+ | Required_multiple , _ | _ , Required_multiple ->
229+ User_error. raise
230+ ~loc
231+ [ Pp. textf
232+ " parameterized library %S is present in multiple forms"
233+ (Lib_name. to_string name)
189234 ])
190235 in
191236 ignore
192237 (List. fold_left t ~init: Lib_name.Map. empty ~f: (fun acc x ->
193238 match x with
194239 | Re_export (_ , s ) | Direct (_ , s ) -> add Required s acc
240+ | Instantiate { lib = s ; _ } -> add Required_multiple s acc
195241 | Select { choices; _ } ->
196242 List. fold_left choices ~init: acc ~f: (fun acc (c : Select.Choice.t ) ->
197243 let acc = Lib_name.Set. fold c.required ~init: acc ~f: (add Optional ) in
0 commit comments