@@ -281,6 +281,7 @@ let reify in_macro =
281281 | CTParent t -> ct " TParent" [to_type_hint t p]
282282 | CTExtend (tl ,fields ) -> ct " TExtend" [to_array to_tpath tl p; to_array to_cfield fields p]
283283 | CTOptional t -> ct " TOptional" [to_type_hint t p]
284+ | CTNamed (n ,t ) -> ct " TNamed" [to_placed_name n; to_type_hint t p]
284285 and to_type_hint (t ,p ) _ =
285286 (* to_obj ["type",to_ctype t p;"pos",to_pos p] p *)
286287 to_ctype (t,p) p
@@ -933,49 +934,63 @@ and parse_complex_type_inner = parser
933934 | [< >] -> serror() )
934935 | [< '(Question ,p1); t,p2 = parse_complex_type_inner >] ->
935936 CTOptional (t,p2),punion p1 p2
937+ | [< n = dollar_ident; s >] ->
938+ (match s with parser
939+ | [< '(DblDot ,_); t = parse_complex_type_inner >] ->
940+ let p1 = snd n in
941+ let p2 = snd t in
942+ CTNamed (n,t),punion p1 p2
943+ | [< s >] ->
944+ let n,p = n in
945+ let t,p = parse_type_path2 None [] n p s in
946+ CTPath t,p
947+ )
936948 | [< t,p = parse_type_path >] ->
937949 CTPath t,p
938950
939951and parse_type_path s = parse_type_path1 None [] s
940952
941953and parse_type_path1 p0 pack = parser
942954 | [< name, p1 = dollar_ident_macro pack; s >] ->
943- if is_lower_ident name then
944- (match s with parser
945- | [< '(Dot ,p) >] ->
946- if is_resuming p then
947- raise (TypePath (List. rev (name :: pack),None ,false ))
948- else
949- parse_type_path1 (match p0 with None -> Some p1 | Some _ -> p0) (name :: pack) s
950- | [< '(Semicolon ,_) >] ->
951- error (Custom " Type name should start with an uppercase letter" ) p1
952- | [< >] -> serror() )
953- else
954- let sub,p2 = (match s with parser
955- | [< '(Dot ,p); s >] ->
956- (if is_resuming p then
957- raise (TypePath (List. rev pack,Some (name,false ),false ))
958- else match s with parser
959- | [< '(Const (Ident name),p2) when not (is_lower_ident name) >] -> Some name,p2
960- | [< '(Binop OpOr ,_) when do_resume() >] ->
961- set_resume p;
962- raise (TypePath (List. rev pack,Some (name,false ),false ))
963- | [< >] -> serror() )
964- | [< >] -> None ,p1
965- ) in
966- let params,p2 = (match s with parser
967- | [< '(Binop OpLt ,_); l = psep Comma parse_type_path_or_const; '(Binop OpGt ,p2) >] -> l,p2
968- | [< > ] -> [] ,p2
969- ) in
970- {
971- tpackage = List. rev pack;
972- tname = name;
973- tparams = params;
974- tsub = sub;
975- },punion (match p0 with None -> p1 | Some p -> p) p2
955+ parse_type_path2 p0 pack name p1 s
976956 | [< '(Binop OpOr ,_) when do_resume() >] ->
977957 raise (TypePath (List. rev pack,None ,false ))
978958
959+ and parse_type_path2 p0 pack name p1 s =
960+ if is_lower_ident name then
961+ (match s with parser
962+ | [< '(Dot ,p) >] ->
963+ if is_resuming p then
964+ raise (TypePath (List. rev (name :: pack),None ,false ))
965+ else
966+ parse_type_path1 (match p0 with None -> Some p1 | Some _ -> p0) (name :: pack) s
967+ | [< '(Semicolon ,_) >] ->
968+ error (Custom " Type name should start with an uppercase letter" ) p1
969+ | [< >] -> serror() )
970+ else
971+ let sub,p2 = (match s with parser
972+ | [< '(Dot ,p); s >] ->
973+ (if is_resuming p then
974+ raise (TypePath (List. rev pack,Some (name,false ),false ))
975+ else match s with parser
976+ | [< '(Const (Ident name),p2) when not (is_lower_ident name) >] -> Some name,p2
977+ | [< '(Binop OpOr ,_) when do_resume() >] ->
978+ set_resume p;
979+ raise (TypePath (List. rev pack,Some (name,false ),false ))
980+ | [< >] -> serror() )
981+ | [< >] -> None ,p1
982+ ) in
983+ let params,p2 = (match s with parser
984+ | [< '(Binop OpLt ,_); l = psep Comma parse_type_path_or_const; '(Binop OpGt ,p2) >] -> l,p2
985+ | [< > ] -> [] ,p2
986+ ) in
987+ {
988+ tpackage = List. rev pack;
989+ tname = name;
990+ tparams = params;
991+ tsub = sub;
992+ },punion (match p0 with None -> p1 | Some p -> p) p2
993+
979994and type_name = parser
980995 | [< '(Const (Ident name),p) >] ->
981996 if is_lower_ident name then
0 commit comments