Browse Source

maybe fix toplevel display (see #5123)

Maybe break parsing. It's about 50/50. Time will tell.
Simon Krajewski 9 years ago
parent
commit
11407af032
2 changed files with 15 additions and 14 deletions
  1. 4 11
      src/main.ml
  2. 11 3
      src/syntax/parser.ml

+ 4 - 11
src/main.ml

@@ -1260,37 +1260,30 @@ try
 				let file, pos = try ExtString.String.split file_pos "@" with _ -> failwith ("Invalid format : " ^ file_pos) in
 				let file = unquote file in
 				let pos, smode = try ExtString.String.split pos "@" with _ -> pos,"" in
-				let activate_special_display_mode () =
-					Common.define com Define.NoCOpt;
-					Parser.use_parser_resume := false
-				in
 				let mode = match smode with
 					| "position" ->
-						activate_special_display_mode();
+						Common.define com Define.NoCOpt;
 						DMPosition
 					| "usage" ->
-						activate_special_display_mode();
+						Common.define com Define.NoCOpt;
 						DMUsage
 					| "type" ->
-						activate_special_display_mode();
+						Common.define com Define.NoCOpt;
 						DMType
 					| "toplevel" ->
-						activate_special_display_mode();
+						Common.define com Define.NoCOpt;
 						DMToplevel
 					| "document-symbols" ->
 						Common.define com Define.NoCOpt;
 						DMDocumentSymbols;
 					| "" ->
-						Parser.use_parser_resume := true;
 						DMDefault
 					| _ ->
 						let smode,arg = try ExtString.String.split smode "@" with _ -> pos,"" in
 						match smode with
 							| "resolve" ->
-								activate_special_display_mode();
 								DMResolve arg
 							| _ ->
-								Parser.use_parser_resume := true;
 								DMDefault
 				in
 				let pos = try int_of_string pos with _ -> failwith ("Invalid format : "  ^ pos) in

+ 11 - 3
src/syntax/parser.ml

@@ -71,7 +71,6 @@ let unquote_ident f =
 let cache = ref (DynArray.create())
 let last_doc = ref None
 let use_doc = ref false
-let use_parser_resume = ref true
 let resume_display = ref null_pos
 let in_macro = ref false
 
@@ -91,7 +90,7 @@ let type_path sl in_import = match sl with
 
 let is_resuming p =
 	let p2 = !resume_display in
-	p.pmax = p2.pmin && !use_parser_resume && Common.unique_full_path p.pfile = p2.pfile
+	p.pmax = p2.pmin && Common.unique_full_path p.pfile = p2.pfile
 
 let set_resume p =
 	resume_display := { p with pfile = Common.unique_full_path p.pfile }
@@ -1217,7 +1216,16 @@ and expr = parser
 		| [< '(Binop OpOr,p2) when do_resume() >] ->
 			set_resume p1;
 			display (EDisplay ((EObjectDecl [],p1),false),p1);
-		| [< b = block1; '(BrClose,p2); s >] ->
+		| [< b = block1; s >] ->
+			let p2 = match s with parser
+				| [< '(BrClose,p2) >] -> p2
+				| [< >] ->
+					(* Ignore missing } if we are resuming and "guess" the last position. *)
+					if do_resume() then begin match Stream.peek s with
+						| Some (_,p) -> p
+						| None -> pos (last_token s)
+					end else serror()
+			in
 			let e = (b,punion p1 p2) in
 			(match b with
 			| EObjectDecl _ -> expr_next e s