2
0
Эх сурвалжийг харах

fixed type printing and parenthesis in type declarations.

Nicolas Cannasse 19 жил өмнө
parent
commit
0eef835287
4 өөрчлөгдсөн 13 нэмэгдсэн , 3 устгасан
  1. 1 0
      ast.ml
  2. 1 1
      parser.ml
  3. 10 2
      type.ml
  4. 1 0
      typer.ml

+ 1 - 0
ast.ml

@@ -137,6 +137,7 @@ and type_path =
 	| TPNormal of type_path_normal
 	| TPFunction of type_path list * type_path
 	| TPAnonymous of (string * type_path) list
+	| TPParent of type_path
 
 type func = {
 	f_args : (string * type_path option) list;

+ 1 - 1
parser.ml

@@ -171,7 +171,7 @@ and parse_type_opt = parser
 	| [< >] -> None
 
 and parse_type_path = parser
-	| [< '(POpen,_); t = parse_type_path; '(PClose,_); s >] -> parse_type_path_next t s
+	| [< '(POpen,_); t = parse_type_path; '(PClose,_); s >] -> parse_type_path_next (TPParent t) s
 	| [< '(BrOpen,_); l = psep Comma parse_type_anonymous; '(BrClose,_); s >] -> parse_type_path_next (TPAnonymous l) s
 	| [< t = parse_type_path_normal; s >] -> parse_type_path_next (TPNormal t) s
 

+ 10 - 2
type.ml

@@ -186,9 +186,11 @@ let rec s_type ctx t =
 	| TInst (c,tl) ->
 		Ast.s_type_path c.cl_path ^ s_type_params ctx tl
 	| TFun ([],t) ->
-		"Void -> " ^ s_type ctx t
+		"Void -> " ^ s_fun ctx t false
 	| TFun (l,t) ->
-		String.concat " -> " (List.map (fun (s,t) -> (if s = "" then "" else s ^ " : ") ^ match t with TFun _ -> "(" ^ s_type ctx t ^ ")" | _ -> s_type ctx t) l) ^ " -> " ^ s_type ctx t
+		String.concat " -> " (List.map (fun (s,t) -> 
+			(if s = "" then "" else s ^ " : ") ^ s_fun ctx t true
+		) l) ^ " -> " ^ s_fun ctx t false
 	| TAnon (fl,name) ->
 		(match name with
 		| Some s -> s
@@ -200,6 +202,12 @@ let rec s_type ctx t =
 	| TLazy f ->		
 		s_type ctx (!f())
 
+and s_fun ctx t void =
+	match t with
+	| TFun _ -> "(" ^ s_type ctx t ^ ")"
+	| TEnum ({ e_path = ([],"Void") },[]) when void -> "(" ^ s_type ctx t ^ ")"
+	| _ -> s_type ctx t
+
 and s_type_params ctx = function
 	| [] -> ""
 	| l -> "<" ^ String.concat ", " (List.map (s_type ctx) l) ^ ">"

+ 1 - 0
typer.ml

@@ -256,6 +256,7 @@ let rec load_normal_type ctx t p allow_no_params =
 
 and load_type ctx p t =
 	match t with
+	| TPParent t -> load_type ctx p t
 	| TPNormal t -> load_normal_type ctx t p false
 	| TPAnonymous l ->
 		let rec loop acc (n,t) =