Bladeren bron

added macro:Type reification

Nicolas Cannasse 13 jaren geleden
bovenliggende
commit
26467b850f
2 gewijzigde bestanden met toevoegingen van 11 en 3 verwijderingen
  1. 4 2
      ast.ml
  2. 7 1
      parser.ml

+ 4 - 2
ast.ml

@@ -519,7 +519,7 @@ let map_expr loop (e,p) =
 	) in
 	) in
 	(e,p)
 	(e,p)
 
 
-let expr_to_value in_macro e =
+let reify in_macro =
 	let mk_enum ename n vl p =
 	let mk_enum ename n vl p =
 		let constr = (EConst (Ident n),p) in
 		let constr = (EConst (Ident n),p) in
 		match vl with
 		match vl with
@@ -601,6 +601,8 @@ let expr_to_value in_macro e =
 	and to_ctype t p =
 	and to_ctype t p =
 		let ct n vl = mk_enum "ComplexType" n vl p in
 		let ct n vl = mk_enum "ComplexType" n vl p in
 		match t with
 		match t with
+		| CTPath { tpackage = []; tparams = []; tsub = None; tname = n } when n.[0] = '$' ->
+			to_string n p
 		| CTPath t -> ct "TPath" [to_tpath t p]
 		| CTPath t -> ct "TPath" [to_tpath t p]
 		| CTFunction (args,ret) -> ct "TFunction" [to_array to_ctype args p; to_ctype ret p]
 		| CTFunction (args,ret) -> ct "TFunction" [to_array to_ctype args p; to_ctype ret p]
 		| CTAnonymous fields -> ct "TAnonymous" [to_array to_cfield fields p]
 		| CTAnonymous fields -> ct "TAnonymous" [to_array to_cfield fields p]
@@ -767,4 +769,4 @@ let expr_to_value in_macro e =
 		| ECheckType (e1,ct) ->
 		| ECheckType (e1,ct) ->
 			expr "ECheckType" [loop e1; to_ctype ct p]
 			expr "ECheckType" [loop e1; to_ctype ct p]
 	in
 	in
-	to_expr e (snd e)
+	(fun e -> to_expr e (snd e)), to_ctype

+ 7 - 1
parser.ml

@@ -619,9 +619,15 @@ and expr = parser
 		| _ -> e)
 		| _ -> e)
 	| [< '(Const (Ident "macro"),p); s >] ->
 	| [< '(Const (Ident "macro"),p); s >] ->
 		(match Stream.npeek 1 s with
 		(match Stream.npeek 1 s with
+		| [(DblDot,_)] ->
+			(match s with parser
+			| [< '(DblDot,_); t = parse_complex_type >] -> 
+				let t = snd (reify !in_macro) t p in
+				(ECheckType (t,(CTPath { tpackage = ["haxe";"macro"]; tname = "Expr"; tsub = Some "ComplexType"; tparams = [] })),p)
+			| [< >] -> serror())
 		| [(_,p2)] when p2.pmin > p.pmax ->
 		| [(_,p2)] when p2.pmin > p.pmax ->
 			let reify e =
 			let reify e =
-				let e = expr_to_value !in_macro e in
+				let e = fst (reify !in_macro) e in
 				(ECheckType (e,(CTPath { tpackage = ["haxe";"macro"]; tname = "Expr"; tsub = None; tparams = [] })),pos e)
 				(ECheckType (e,(CTPath { tpackage = ["haxe";"macro"]; tname = "Expr"; tsub = None; tparams = [] })),pos e)
 			in
 			in
 			(match s with parser
 			(match s with parser