Browse Source

remove weird field refs

Simon Krajewski 5 tháng trước cách đây
mục cha
commit
6e1bcfedc4
2 tập tin đã thay đổi với 14 bổ sung16 xóa
  1. 10 12
      src/syntax/parser.ml
  2. 4 4
      src/syntax/parserEntry.ml

+ 10 - 12
src/syntax/parser.ml

@@ -83,12 +83,12 @@ type parser_config = {
 
 type parser_ctx = {
 	lexer_ctx : Lexer.lexer_ctx;
-	syntax_errors : (error_msg * pos) list ref;
-	last_doc : (string * int) option ref;
+	mutable syntax_errors : (error_msg * pos) list;
+	mutable last_doc : (string * int) option;
 	in_macro : bool;
 	code : Sedlexing.lexbuf;
 	mutable had_resume : bool;
-	delayed_syntax_completion : syntax_completion_on option ref;
+	mutable delayed_syntax_completion : syntax_completion_on option;
 	cache : (token * pos) DynArray.t;
 	config : parser_config;
 }
@@ -132,12 +132,12 @@ type 'a parse_result =
 
 let create_context lexer_ctx config in_macro code = {
 	lexer_ctx;
-	syntax_errors = ref [];
-	last_doc = ref None;
+	syntax_errors = [];
+	last_doc = None;
 	in_macro;
 	code;
 	had_resume = false;
-	delayed_syntax_completion = ref None;
+	delayed_syntax_completion = None;
 	cache = DynArray.create ();
 	config;
 }
@@ -183,15 +183,13 @@ let next_token ctx s = match Stream.peek s with
 
 let next_pos ctx s = pos (next_token ctx s)
 
-(* Global state *)
-
 let reset_state () =
 	display_position#reset
 
 let syntax_error_with_pos ctx error_msg p v =
 	let p = if p.pmax = max_int then {p with pmax = p.pmin + 1} else p in
 	if not ctx.config.in_display then error error_msg p;
-	ctx.syntax_errors := (error_msg,p) :: !(ctx.syntax_errors);
+	ctx.syntax_errors <- (error_msg,p) :: ctx.syntax_errors;
 	v
 
 let syntax_error ctx error_msg ?(pos=None) s v =
@@ -212,10 +210,10 @@ let get_doc ctx s =
 	match Stream.peek s with
 	| None -> None
 	| Some (tk,p) ->
-		match !(ctx.last_doc) with
+		match ctx.last_doc with
 		| None -> None
 		| Some (d,pos) ->
-			ctx.last_doc := None;
+			ctx.last_doc <- None;
 			Some d
 
 let unsupported_decl_flag decl flag pos ctx =
@@ -268,7 +266,7 @@ let magic_type_ct p = make_ptp_ct magic_type_path p
 let magic_type_th p = magic_type_ct p,p
 
 let delay_syntax_completion ctx kind so p =
-	ctx.delayed_syntax_completion := Some(kind,DisplayTypes.make_subject so p)
+	ctx.delayed_syntax_completion <- Some(kind,DisplayTypes.make_subject so p)
 
 let type_path sl in_import p = match sl with
 	| n :: l when n.[0] >= 'A' && n.[0] <= 'Z' -> raise (TypePath (List.rev l,Some (n,false),in_import,p));

+ 4 - 4
src/syntax/parserEntry.ml

@@ -234,7 +234,7 @@ let parse config entry lctx code file =
 		| Comment s ->
 			(* if encloses_resume (pos tk) then syntax_completion SCComment (pos tk); *)
 			let l = String.length s in
-			if l > 0 && s.[0] = '*' then ctx.last_doc := Some (String.sub s 1 (l - (if l > 1 && s.[l-1] = '*' then 2 else 1)), (snd tk).pmin);
+			if l > 0 && s.[0] = '*' then ctx.last_doc <- Some (String.sub s 1 (l - (if l > 1 && s.[l-1] = '*' then 2 else 1)), (snd tk).pmin);
 			let tk = next_token() in
 			tk
 		| CommentLine s ->
@@ -348,16 +348,16 @@ let parse config entry lctx code file =
 		end;
 		let was_display_file = ctx.config.in_display_file in
 		let pdi = {
-			pd_errors = List.rev !(ctx.syntax_errors);
+			pd_errors = List.rev ctx.syntax_errors;
 			pd_dead_blocks = dbc#get_dead_blocks;
 			pd_conditions = conds#get_conditions;
 			pd_was_display_file = was_display_file;
 			pd_had_resume = ctx.had_resume;
-			pd_delayed_syntax_completion = !(ctx.delayed_syntax_completion);
+			pd_delayed_syntax_completion = ctx.delayed_syntax_completion;
 		} in
 		if was_display_file then
 			ParseSuccess(l,pdi)
-		else begin match List.rev !(ctx.syntax_errors) with
+		else begin match List.rev ctx.syntax_errors with
 			| [] -> ParseSuccess(l,pdi)
 			| error :: errors -> ParseError(l,error,errors)
 		end