Browse Source

catched NCompile errors (fixed iseue #1657)

Nicolas Cannasse 12 years ago
parent
commit
7cfd5bbbb1
1 changed files with 13 additions and 3 deletions
  1. 13 3
      genneko.ml

+ 13 - 3
genneko.ml

@@ -826,9 +826,19 @@ let generate com =
 	let source = Common.defined com Define.NekoSource in
 	let use_nekoc = Common.defined com Define.UseNekoc in
 	if not use_nekoc then begin
-		let ch = IO.output_channel (open_out_bin com.file) in
-		Nbytecode.write ch (Ncompile.compile ctx.version e);
-		IO.close_out ch;
+		try
+			let ch = IO.output_channel (open_out_bin com.file) in
+			Nbytecode.write ch (Ncompile.compile ctx.version e);
+			IO.close_out ch;
+		with Ncompile.Error (msg,pos) ->
+			let rec loop p =
+				let pp = { pfile = pos.psource; pmin = p; pmax = p; } in
+				if Lexer.get_error_line pp >= pos.pline then
+					pp
+				else
+					loop (p + 1)
+			in
+			error msg (loop 0)
 	end;
 	let command cmd = try com.run_command cmd with _ -> -1 in
 	let neko_file = (try Filename.chop_extension com.file with _ -> com.file) ^ ".neko" in