Simon Krajewski 5 months ago
parent
commit
f12e31003b
3 changed files with 10 additions and 12 deletions
  1. 3 4
      src/syntax/grammar.ml
  2. 6 6
      src/syntax/parser.ml
  3. 1 2
      src/syntax/parserEntry.ml

+ 3 - 4
src/syntax/grammar.ml

@@ -125,7 +125,6 @@ let check_redundant_var ctx p1 = function%parser
 let parsing_macro_cond = ref false
 
 let rec parse_file (ctx : parser_ctx) s =
-	last_doc := None;
 	match%parser s with
 	| [ (Kwd Package,_); parse_package as pack ] ->
 		begin match%parser s with
@@ -235,7 +234,7 @@ and parse_type_decl ctx mode s =
 	match%parser s with
 	| [ (Kwd Import,p1) ] -> parse_import ctx s p1
 	| [ (Kwd Using,p1) ] -> parse_using ctx s p1
-	| [ get_doc as doc; [%let meta = parse_meta ctx]; parse_common_flags as c ] ->
+	| [ [%let doc = get_doc ctx]; [%let meta = parse_meta ctx]; parse_common_flags as c ] ->
 		match%parser s with
 		| [ (Kwd Function,p1); dollar_ident as name; [%let pl = parse_constraint_params ctx]; (POpen,_); [%let args = psep_trailing Comma (parse_fun_param ctx)]; (PClose,_); [%let t = popt (parse_type_hint ctx)] ] ->
 			let e, p2 = (match%parser s with
@@ -880,7 +879,7 @@ and parse_type_anonymous ctx s =
 		if p0 = None then raise Stream.Failure else serror()
 
 and parse_enum ctx s =
-	let doc = get_doc s in
+	let doc = get_doc ctx s in
 	let meta = parse_meta ctx s in
 	match%parser s with
 	| [ [%let name, p1 = ident]; [%let params = parse_constraint_params ctx] ] ->
@@ -942,7 +941,7 @@ and parse_var_field_assignment ctx = function%parser
 	| [ ] -> serror()
 
 and parse_class_field ctx tdecl s =
-	let doc = get_doc s in
+	let doc = get_doc ctx s in
 	let meta = parse_meta ctx s in
 	match%parser s with
 	| [ [%let al = plist parse_cf_rights] ] ->

+ 6 - 6
src/syntax/parser.ml

@@ -74,6 +74,7 @@ exception SyntaxCompletion of syntax_completion * DisplayTypes.completion_subjec
 type parser_ctx = {
 	lexer_ctx : Lexer.lexer_ctx;
 	syntax_errors : (error_msg * pos) list ref;
+	last_doc : (string * int) option ref;
 }
 
 let error_msg = function
@@ -113,6 +114,7 @@ type 'a parse_result =
 let create_context lexer_ctx = {
 	lexer_ctx;
 	syntax_errors = ref [];
+	last_doc = ref None;
 }
 
 let s_decl_flag = function
@@ -172,7 +174,6 @@ let delayed_syntax_completion : (syntax_completion * DisplayTypes.completion_sub
 (* Per-file state *)
 
 let in_display_file = ref false
-let last_doc : (string * int) option ref = ref None
 
 let reset_state () =
 	in_display := false;
@@ -183,8 +184,7 @@ let reset_state () =
 	had_resume := false;
 	code_ref := Sedlexing.Utf8.from_string "";
 	delayed_syntax_completion := None;
-	in_display_file := false;
-	last_doc := None
+	in_display_file := false
 
 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
@@ -205,15 +205,15 @@ let handle_stream_error ctx msg s =
 	in
 	syntax_error ctx err ~pos s ()
 
-let get_doc s =
+let get_doc ctx s =
 	(* do the peek first to make sure we fetch the doc *)
 	match Stream.peek s with
 	| None -> None
 	| Some (tk,p) ->
-		match !last_doc with
+		match !(ctx.last_doc) with
 		| None -> None
 		| Some (d,pos) ->
-			last_doc := None;
+			ctx.last_doc := None;
 			Some d
 
 let unsupported_decl_flag decl flag pos ctx =

+ 1 - 2
src/syntax/parserEntry.ml

@@ -229,7 +229,6 @@ let parse entry lctx defines code file =
 			code_ref := old_code;
 		)
 	in
-	last_doc := None;
 	in_macro := Define.defined defines Define.Macro;
 	Lexer.skip_header code;
 
@@ -251,7 +250,7 @@ let parse entry lctx defines 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 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 pctx.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 ->