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

refactor a bit so it's easier to grasp what's going on

Dan Korostelev 9 жил өмнө
parent
commit
af753184c6
1 өөрчлөгдсөн 12 нэмэгдсэн , 8 устгасан
  1. 12 8
      src/main.ml

+ 12 - 8
src/main.ml

@@ -372,9 +372,9 @@ let parse_hxml file =
 	IO.close_in ch;
 	parse_hxml_data data
 
-let lookup_classes com spath =
+let get_module_path_from_file_path com spath =
 	let rec loop = function
-		| [] -> []
+		| [] -> None
 		| cp :: l ->
 			let cp = (if cp = "" then "./" else cp) in
 			let c = add_trailing_slash (get_real_path (Common.get_full_path cp)) in
@@ -384,8 +384,8 @@ let lookup_classes com spath =
 				(try
 					let path = make_type_path path in
 					(match loop l with
-					| [x] when String.length (Ast.s_type_path x) < String.length (Ast.s_type_path path) -> [x]
-					| _ -> [path])
+					| Some x as r when String.length (Ast.s_type_path x) < String.length (Ast.s_type_path path) -> r
+					| _ -> Some path)
 				with _ -> loop l)
 			end else
 				loop l
@@ -1443,15 +1443,19 @@ try
 		com.warning <- message ctx;
 		com.error <- error ctx;
 		com.main_class <- None;
+		if com.display <> DMUsage then
+			classes := [];
 		let real = get_real_path (!Parser.resume_display).Ast.pfile in
-		classes := lookup_classes com real @ (if com.display = DMUsage then !classes else []);
-		if !classes = [] then begin
+		(match get_module_path_from_file_path com real with
+		| Some path ->
+			classes := path :: !classes
+		| None ->
 			if not (Sys.file_exists real) then failwith "Display file does not exist";
 			(match List.rev (ExtString.String.nsplit real path_sep) with
 			| file :: _ when file.[0] >= 'a' && file.[1] <= 'z' -> failwith ("Display file '" ^ file ^ "' should not start with a lowercase letter")
 			| _ -> ());
-			failwith "Display file was not found in class path";
-		end;
+			failwith "Display file was not found in class path"
+		);
 		Common.log com ("Display file : " ^ real);
 		Common.log com ("Classes found : ["  ^ (String.concat "," (List.map Ast.s_type_path !classes)) ^ "]");
 	end;