Bläddra i källkod

parser config start

Simon Krajewski 5 månader sedan
förälder
incheckning
cc16e7676f

+ 2 - 2
src/compiler/compiler.ml

@@ -438,7 +438,7 @@ with
 	| Parser.Error (m,p) ->
 		error ctx (Parser.error_msg m) p
 	| Typecore.Forbid_package ((pack,m,p),pl,pf)  ->
-		if !Parser.display_mode <> DMNone && ctx.has_next then begin
+		if ctx.com.display.dms_kind <> DMNone && ctx.has_next then begin
 			ctx.has_error <- false;
 			ctx.messages <- [];
 		end else begin
@@ -539,7 +539,7 @@ let create_context comm cs timer_ctx compilation_step params = {
 		revision = version_revision;
 		pre = version_pre;
 		extra = Version.version_extra;
-	} params (DisplayTypes.DisplayMode.create !Parser.display_mode);
+	} params (DisplayTypes.DisplayMode.create DMNone);
 	messages = [];
 	has_next = false;
 	has_error = false;

+ 0 - 1
src/compiler/displayProcessing.ml

@@ -29,7 +29,6 @@ let handle_display_argument_old com file_pos actx =
 		let file_unique = com.file_keys#get file in
 		let pos, smode = try ExtString.String.split pos "@" with _ -> pos,"" in
 		let create mode =
-			Parser.display_mode := mode;
 			DisplayTypes.DisplayMode.create mode
 		in
 		let dm = match smode with

+ 1 - 1
src/compiler/server.ml

@@ -295,7 +295,7 @@ let check_module sctx com m_path m_extra p =
 				end
 		in
 		let has_policy policy = List.mem policy m_extra.m_check_policy || match policy with
-			| NoFileSystemCheck when !ServerConfig.do_not_check_modules && !Parser.display_mode <> DMNone -> true
+			| NoFileSystemCheck when !ServerConfig.do_not_check_modules && com.display.dms_kind <> DMNone -> true
 			| _ -> false
 		in
 		let check_file () =

+ 0 - 1
src/context/display/displayJson.ml

@@ -51,7 +51,6 @@ class display_handler (jsonrpc : jsonrpc_handler) com (cs : CompilationCache.t)
 
 	method enable_display ?(skip_define=false) mode =
 		com.display <- create mode;
-		Parser.display_mode := mode;
 		if not skip_define then Common.define_value com Define.Display "1"
 
 	method set_display_file was_auto_triggered requires_offset =

+ 2 - 2
src/context/formatString.ml

@@ -1,7 +1,7 @@
 open Globals
 open Ast
 
-let format_string defines s p process_expr =
+let format_string config s p process_expr =
 	let e = ref None in
 	let pmin = ref p.pmin in
 	let min = ref (p.pmin + 1) in
@@ -83,7 +83,7 @@ let format_string defines s p process_expr =
 					if Lexer.string_is_whitespace scode then Error.raise_typing_error "Expression cannot be empty" ep
 					else Error.raise_typing_error msg pos
 				in
-				match ParserEntry.parse_expr_string defines scode ep error true with
+				match ParserEntry.parse_expr_string config scode ep error true with
 					| ParseSuccess(data,_,_) -> data
 					| ParseError(_,(msg,p),_) -> error (Parser.error_msg msg) p
 			in

+ 2 - 2
src/macro/eval/evalDebugMisc.ml

@@ -78,9 +78,9 @@ let find_breakpoint ctx sid =
 
 exception Parse_expr_error of string
 
-let parse_expr ctx s p =
+let parse_expr ctx config s p =
 	let error s = raise (Parse_expr_error s) in
-	match ParserEntry.parse_expr_string (ctx.curapi.get_com()).Common.defines s p error true with
+	match ParserEntry.parse_expr_string config s p error true with
 	| ParseSuccess(data,_,_) -> data
 	| ParseError(_,(msg,_),_) -> error (Parser.error_msg msg)
 

+ 7 - 5
src/macro/eval/evalDebugSocket.ml

@@ -475,17 +475,16 @@ module ValueCompletion = struct
 	let get_completion ctx text column env =
 		let p = file_pos "" in
 		let save =
-			let old = !Parser.display_mode,DisplayPosition.display_position#get in
+			let old = DisplayPosition.display_position#get in
 			(fun () ->
-				Parser.display_mode := fst old;
-				DisplayPosition.display_position#set (snd old);
+				DisplayPosition.display_position#set old;
 			)
 		in
-		Parser.display_mode := DMDefault;
+		let config = Parser.create_config (ctx.curapi.get_com()).Common.defines true true DMDefault in
 		let offset = column + (String.length "class X{static function main() ") - 1 (* this is retarded *) in
 		DisplayPosition.display_position#set {p with pmin = offset; pmax = offset};
 		begin try
-			let e = parse_expr ctx text p in
+			let e = parse_expr ctx config text p in
 			let e = ExprPreprocessing.find_before_pos DMDefault e in
 			save();
 			let rec loop e = match fst e with
@@ -542,6 +541,9 @@ let expect_env hctx env = match env with
 	| None -> hctx.send_error "No frame found"
 
 let handler =
+	let parse_expr ctx p =
+		parse_expr ctx (ParserConfig.default_config (ctx.curapi.get_com()).Common.defines) p
+	in
 	let parse_breakpoint hctx jo =
 		let j = hctx.jsonrpc in
 		let obj = j#get_object "breakpoint" jo in

+ 1 - 1
src/macro/macroApi.ml

@@ -2234,7 +2234,7 @@ let macro_api ccom get_api =
 				encode_obj ["file",encode_string p.Globals.pfile;"pos",vint p.Globals.pmin]
 		);
 		"get_display_mode", vfun0 (fun() ->
-			encode_display_mode !Parser.display_mode
+			encode_display_mode (ccom()).display.dms_kind;
 		);
 		"get_configuration", vfun0 (fun() ->
 			let com = ccom() in

+ 11 - 11
src/syntax/grammar.ml

@@ -153,7 +153,7 @@ and parse_type_decls ctx mode pmax pack acc s =
 			| _ -> ()
 		) acc;
 		raise (TypePath (pack,Some(name,true),b,p))
-	| Stream.Error msg when !in_display_file ->
+	| Stream.Error msg when ctx.config.in_display_file ->
 		Error msg
 	in
 	match result with
@@ -191,7 +191,7 @@ and parse_class_content ctx doc meta flags n p1 s =
 	let tl = parse_constraint_params ctx s in
 	let rec loop had_display p0 acc =
 		let check_display p1 =
-			if not had_display && !in_display_file && !display_mode = DMDefault && display_position#enclosed_in p1 then
+			if not had_display && ctx.config.in_display_file && ctx.config.display_mode = DMDefault && display_position#enclosed_in p1 then
 				syntax_completion (if List.mem HInterface n then SCInterfaceRelation else SCClassRelation) None (display_position#with_pos p1)
 		in
 		match%parser s with
@@ -445,7 +445,7 @@ and parse_using ctx s p1 =
 
 and parse_abstract_relations ctx =
 	let check_display p1 (ct,p2) =
-		if !in_display_file && p1.pmax < (display_position#get).pmin && p2.pmin >= (display_position#get).pmax then
+		if ctx.config.in_display_file && p1.pmax < (display_position#get).pmin && p2.pmin >= (display_position#get).pmax then
 			(* This means we skipped the display position between the to/from and the type-hint we parsed.
 			   Very weird case, it was probably a {} like in #7137. Let's discard it and use magic. *)
 			(magic_type_th (display_position#with_pos p2))
@@ -547,7 +547,7 @@ and parse_class_field_resume ctx acc tdecl s =
 			acc,last_pos ctx s
 
 and parse_class_fields ctx tdecl p1 s =
-	if not (!in_display_file) then begin
+	if not (ctx.config.in_display_file) then begin
 		let acc = plist (parse_class_field ctx tdecl) s in
 		let p2 = (match%parser s with
 			| [ (BrClose,p2) ] -> p2
@@ -734,7 +734,7 @@ and parse_type_path2 ctx p0 pack name p1 s : placed_type_path =
 			| None -> p1
 			| Some p -> punion p p1
 		in
-		if !in_display_file && display_position#enclosed_in p then begin
+		if ctx.config.in_display_file && display_position#enclosed_in p then begin
 			make_ptp (mk_type_path (List.rev pack,name)) p
 		end else
 			f()
@@ -793,7 +793,7 @@ and parse_type_path_or_const ctx plt = function%parser
 	| [ (Kwd False,p) ] -> TPExpr (EConst (Ident "false"),p)
 	| [ [%let e = expr ctx] ] -> TPExpr e
 	| [ [%s s] ] ->
-		if !in_display_file then begin
+		if ctx.config.in_display_file then begin
 			if would_skip_display_position ctx plt false s then begin
 				TPType (magic_type_th (display_position#with_pos plt))
 			end else
@@ -1143,7 +1143,7 @@ and block_with_pos' ctx acc f p s =
 	with
 		| Stream.Failure ->
 			List.rev acc,p
-		| Stream.Error msg when !in_display_file ->
+		| Stream.Error msg when ctx.config.in_display_file ->
 			handle_stream_error ctx msg s;
 			(block_with_pos ctx acc (next_pos ctx s) s)
 
@@ -1389,7 +1389,7 @@ and expr (ctx : parser_ctx) s = match%parser s with
 		begin try
 			make_meta name params (secure_expr ctx s) p
 		with
-		| Stream.Failure | Stream.Error _ when !in_display_file ->
+		| Stream.Failure | Stream.Error _ when ctx.config.in_display_file ->
 			let e = EConst (Ident "null"),null_pos in
 			make_meta name params e p
 		end
@@ -1575,7 +1575,7 @@ and expr (ctx : parser_ctx) s = match%parser s with
 and expr_next ctx e1 s =
 	try
 		expr_next' ctx e1 s
-	with Stream.Error msg when !in_display ->
+	with Stream.Error msg when ctx.config.in_display ->
 		handle_stream_error ctx msg s;
 		e1
 
@@ -1698,7 +1698,7 @@ and parse_catches ctx etry catches pmax = function%parser
 	| [ ] -> List.rev catches,pmax
 
 and parse_call_params ctx f p1 s =
-	if not !in_display_file then begin
+	if not ctx.config.in_display_file then begin
 		let el = psep_trailing Comma (expr ctx) s in
 		match%parser s with
 		| [ (PClose,p2) ] -> f el p2
@@ -1725,7 +1725,7 @@ and parse_call_params ctx f p1 s =
 			| [ (Comma,p2)] ->
 				begin match%parser s with
 					| [ (PClose, p3) ] ->
-						if (is_signature_display()) then begin
+						if (is_signature_display ctx) then begin
 							let prev_arg_pos = punion p1 p2 in
 							let comma_paren_pos = punion p2 p3 in
 							(* first check wether the display position is within the previous argument *)

+ 28 - 21
src/syntax/parser.ml

@@ -19,7 +19,6 @@
 
 open Ast
 open Globals
-open DisplayTypes.DisplayMode
 open DisplayPosition
 
 type preprocessor_error =
@@ -71,10 +70,18 @@ exception Error of error_msg * pos
 exception TypePath of string list * (string * bool) option * bool (* in import *) * pos
 exception SyntaxCompletion of syntax_completion * DisplayTypes.completion_subject
 
+type parser_config = {
+	defines : Define.define;
+	in_display : bool;
+	in_display_file : bool;
+	display_mode : DisplayTypes.DisplayMode.t;
+}
+
 type parser_ctx = {
 	lexer_ctx : Lexer.lexer_ctx;
 	syntax_errors : (error_msg * pos) list ref;
 	last_doc : (string * int) option ref;
+	config : parser_config;
 }
 
 let error_msg = function
@@ -111,10 +118,18 @@ type 'a parse_result =
 	(* Parsed non-display file with errors *)
 	| ParseError of 'a * parse_error * parse_error list
 
-let create_context lexer_ctx = {
+let create_context lexer_ctx config = {
 	lexer_ctx;
 	syntax_errors = ref [];
 	last_doc = ref None;
+	config;
+}
+
+let create_config defines in_display in_display_file display_mode = {
+	defines;
+	in_display;
+	in_display_file;
+	display_mode;
 }
 
 let s_decl_flag = function
@@ -163,32 +178,24 @@ let next_pos ctx s = pos (next_token ctx s)
 
 (* Global state *)
 
-let in_display = ref false
 let was_auto_triggered = ref false
-let display_mode = ref DMNone
+
 let in_macro = ref false
 let had_resume = ref false
 let code_ref = ref (Sedlexing.Utf8.from_string "")
 let delayed_syntax_completion : (syntax_completion * DisplayTypes.completion_subject) option ref = ref None
 
-(* Per-file state *)
-
-let in_display_file = ref false
-
 let reset_state () =
-	in_display := false;
 	was_auto_triggered := false;
-	display_mode := DMNone;
 	display_position#reset;
 	in_macro := false;
 	had_resume := false;
 	code_ref := Sedlexing.Utf8.from_string "";
-	delayed_syntax_completion := None;
-	in_display_file := false
+	delayed_syntax_completion := None
 
 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 !in_display then error error_msg p;
+	if not ctx.config.in_display then error error_msg p;
 	ctx.syntax_errors := (error_msg,p) :: !(ctx.syntax_errors);
 	v
 
@@ -273,7 +280,7 @@ let type_path sl in_import p = match sl with
 	| _ -> raise (TypePath (List.rev sl,None,in_import,p))
 
 let would_skip_display_position ctx p1 plus_one s =
-	if !in_display_file then match Stream.npeek 1 s with
+	if ctx.config.in_display_file then match Stream.npeek 1 s with
 		| [ (_,p2) ] ->
 			let p2 = {p2 with pmin = p1.pmax + (if plus_one then 1 else 0)} in
 			display_position#enclosed_in p2
@@ -367,20 +374,20 @@ let mk_null_expr p = (EConst(Ident "null"),p)
 let mk_display_expr e dk = (EDisplay(e,dk),(pos e))
 
 let is_completion ctx =
-	!display_mode = DMDefault
+	ctx.config.display_mode = DMDefault
 
 let is_signature_display ctx =
-	!display_mode = DMSignature
+	ctx.config.display_mode = DMSignature
 
 let check_resume ctx p fyes fno =
-	if is_completion () && !in_display_file && p.pmax = (display_position#get).pmin then begin
+	if is_completion ctx && ctx.config.in_display_file && p.pmax = (display_position#get).pmin then begin
 		had_resume := true;
 		fyes()
 	end else
 		fno()
 
 let check_resume_range ctx p s fyes fno =
-	if is_completion () && !in_display_file then begin
+	if is_completion ctx && ctx.config.in_display_file then begin
 		let pnext = next_pos ctx s in
 		if p.pmin < (display_position#get).pmin && pnext.pmin >= (display_position#get).pmax then
 			fyes pnext
@@ -401,7 +408,7 @@ let check_completion ctx p0 plus_one s =
 			None
 
 let check_type_decl_flag_completion ctx mode flags s =
-	if not !in_display_file || not (is_completion()) then raise Stream.Failure;
+	if not ctx.config.in_display_file || not (is_completion ctx) then raise Stream.Failure;
 	let mode () = match flags with
 		| [] ->
 			SCTypeDecl mode
@@ -422,7 +429,7 @@ let check_type_decl_flag_completion ctx mode flags s =
 				raise Stream.Failure
 
 let check_type_decl_completion ctx mode pmax s =
-	if !in_display_file && is_completion() then begin
+	if ctx.config.in_display_file && is_completion ctx then begin
 		let pmin = match Stream.peek s with
 			| Some (Eof,_) | None -> max_int
 			| Some tk -> (pos tk).pmin
@@ -440,7 +447,7 @@ let check_type_decl_completion ctx mode pmax s =
 	end
 
 let check_signature_mark ctx e p1 p2 =
-	if not (is_signature_display()) then e
+	if not (is_signature_display ctx) then e
 	else begin
 		let p = punion p1 p2 in
 		if true || not !was_auto_triggered then begin (* TODO: #6383 *)

+ 12 - 0
src/syntax/parserConfig.ml

@@ -0,0 +1,12 @@
+open Globals
+open Common
+open DisplayPosition
+
+let default_config defines =
+	Parser.create_config defines false false DMNone
+
+let file_parser_config com file =
+	let open DisplayPosition in
+	let in_display = display_position#get <> null_pos in
+	let in_display_file = in_display && display_position#is_in_file (Path.UniqueKey.create file) in
+	Parser.create_config com.defines in_display in_display_file com.display.dms_kind

+ 25 - 30
src/syntax/parserEntry.ml

@@ -209,23 +209,18 @@ class dead_block_collector conds = object(self)
 end
 
 (* parse main *)
-let parse entry lctx defines code file =
-	let pctx = Parser.create_context lctx in
-	let entry = entry pctx in
+let parse config entry lctx code file =
+	let ctx = Parser.create_context lctx config in
+	let defines = config.defines in
+	let entry = entry ctx in
 	let restore_cache = TokenCache.clear () in
-	let was_display = !in_display in
-	let was_display_file = !in_display_file in
 	let old_code = !code_ref in
 	let old_macro = !in_macro in
 	code_ref := code;
-	in_display := display_position#get <> null_pos;
-	in_display_file := !in_display && display_position#is_in_file (Path.UniqueKey.create file);
 	let restore =
 		(fun () ->
 			restore_cache ();
-			in_display := was_display;
 			in_macro := old_macro;
-			in_display_file := was_display_file;
 			code_ref := old_code;
 		)
 	in
@@ -241,7 +236,7 @@ let parse entry lctx defines code file =
 	let dbc = new dead_block_collector conds in
 	let sraw = Stream.from (fun _ -> Some (Lexer.sharp_token lctx code)) in
 	let preprocessor_error ppe pos tk =
-		syntax_error pctx (Preprocessor_error ppe) ~pos:(Some pos) sraw tk
+		syntax_error ctx (Preprocessor_error ppe) ~pos:(Some pos) sraw tk
 	in
 	let rec next_token() = process_token (Lexer.token lctx code)
 
@@ -250,14 +245,14 @@ 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 pctx.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 ->
-			if !in_display_file then begin
+			if ctx.config.in_display_file then begin
 				let p = pos tk in
 				(* Completion at the / should not pick up the comment (issue #9133) *)
-				let p = if is_completion() then {p with pmin = p.pmin + 1} else p in
+				let p = if is_completion ctx then {p with pmin = p.pmin + 1} else p in
 				(* The > 0 check is to deal with the special case of line comments at the beginning of the file (issue #10322) *)
 				if display_position#enclosed_in p && p.pmin > 0 then syntax_completion SCComment None (pos tk);
 			end;
@@ -266,7 +261,7 @@ let parse entry lctx defines code file =
 			conds#cond_end (snd tk);
 			next_token()
 		| Sharp "elseif" ->
-			let _,(e,pe) = parse_macro_cond pctx sraw in
+			let _,(e,pe) = parse_macro_cond ctx sraw in
 			conds#cond_elseif (e,pe) (snd tk);
 			dbc#open_dead_block pe;
 			let tk = skip_tokens (pos tk) false in
@@ -295,7 +290,7 @@ let parse entry lctx defines code file =
 			tk
 
 	and enter_macro is_if p =
-		let tk, e = parse_macro_cond pctx sraw in
+		let tk, e = parse_macro_cond ctx sraw in
 		(if is_if then conds#cond_if e else conds#cond_elseif e p);
 		let tk = (match tk with None -> Lexer.token lctx code | Some tk -> tk) in
 		if is_true (eval defines e) then begin
@@ -313,7 +308,7 @@ let parse entry lctx defines code file =
 			Lexer.token lctx code
 		| Sharp "elseif" when not test ->
 			dbc#close_dead_block (pos tk);
-			let _,(e,pe) = parse_macro_cond pctx sraw in
+			let _,(e,pe) = parse_macro_cond ctx sraw in
 			conds#cond_elseif (e,pe) (snd tk);
 			dbc#open_dead_block pe;
 			skip_tokens p test
@@ -330,7 +325,7 @@ let parse entry lctx defines code file =
 			dbc#close_dead_block (pos tk);
 			enter_macro false (snd tk)
 		| Sharp "if" ->
-			let _,e = parse_macro_cond pctx sraw in
+			let _,e = parse_macro_cond ctx sraw in
 			conds#cond_if e;
 			dbc#open_dead_block (pos e);
 			let tk = skip_tokens p false in
@@ -362,41 +357,41 @@ let parse entry lctx defines code file =
 			| Some (tok,p) ->
 				error (Unexpected tok) p (* This isn't *)
 		end;
-		let was_display_file = !in_display_file in
+		let was_display_file = ctx.config.in_display_file in
 		restore();
-		let pdi = {pd_errors = List.rev !(pctx.syntax_errors);pd_dead_blocks = dbc#get_dead_blocks;pd_conditions = conds#get_conditions} in
+		let pdi = {pd_errors = List.rev !(ctx.syntax_errors);pd_dead_blocks = dbc#get_dead_blocks;pd_conditions = conds#get_conditions} in
 		if was_display_file then
 			ParseSuccess(l,true,pdi)
-		else begin match List.rev !(pctx.syntax_errors) with
+		else begin match List.rev !(ctx.syntax_errors) with
 			| [] -> ParseSuccess(l,false,pdi)
 			| error :: errors -> ParseError(l,error,errors)
 		end
 	with
 		| Stream.Error _
 		| Stream.Failure ->
-			let last = (match Stream.peek s with None -> last_token pctx s | Some t -> t) in
+			let last = (match Stream.peek s with None -> last_token ctx s | Some t -> t) in
 			restore();
 			error (Unexpected (fst last)) (pos last)
 		| e ->
 			restore();
 			raise e
 
-let parse_string entry defines s p error inlined =
+let parse_string config entry s p error inlined =
 	let old_display = display_position#get in
-	let old_in_display_file = !in_display_file in
 	let restore() =
 		if not inlined then begin
 			display_position#set old_display;
-			in_display_file := old_in_display_file;
 		end;
 	in
 	let lctx = Lexer.create_temp_ctx p.pfile in
-	if not inlined then begin
+	let config = if not inlined then begin
 		display_position#reset;
-		in_display_file := false;
-	end;
+		{ config with in_display_file = false }
+	end else
+		config
+	in
 	let result = try
-		parse entry lctx defines (Sedlexing.Utf8.from_string s) p.pfile
+		parse config entry lctx (Sedlexing.Utf8.from_string s) p.pfile
 	with Error (e,pe) ->
 		restore();
 		error (error_msg e) (if inlined then pe else p)
@@ -410,9 +405,9 @@ let parse_string entry defines s p error inlined =
 	restore();
 	result
 
-let parse_expr_string defines s p error inl =
+let parse_expr_string config s p error inl =
 	let s = if p.pmin > 0 then (String.make p.pmin ' ') ^ s else s in
-	let result = parse_string expr defines s p error inl in
+	let result = parse_string config expr s p error inl in
 	if inl then
 		result
 	else begin

+ 6 - 6
src/typing/macroContext.ml

@@ -98,7 +98,7 @@ let make_macro_com_api com mcom p =
 	let timer_level = Timer.level_from_define com.defines Define.MacroTimes in
 	let parse_metadata s p =
 		try
-			match ParserEntry.parse_string Grammar.parse_meta com.defines s null_pos raise_typing_error false with
+			match ParserEntry.parse_string (ParserConfig.default_config com.defines) Grammar.parse_meta s null_pos raise_typing_error false with
 			| ParseSuccess(meta,_,_) -> meta
 			| ParseError(_,_,_) -> raise_typing_error "Malformed metadata string" p
 		with _ ->
@@ -168,7 +168,7 @@ let make_macro_com_api com mcom p =
 			let exit() = com.error_ext <- old in
 
 			try
-				let r = match ParserEntry.parse_expr_string com.defines s p raise_typing_error inl with
+				let r = match ParserEntry.parse_expr_string (ParserConfig.file_parser_config com p.pfile) s p raise_typing_error inl with
 					| ParseSuccess(data,true,_) when inl -> data (* ignore errors when inline-parsing in display file *)
 					| ParseSuccess(data,_,_) -> data
 					| ParseError _ -> Interp.exc_string "Invalid expression"
@@ -186,7 +186,7 @@ let make_macro_com_api com mcom p =
 				raise e
 		);
 		parse = (fun entry s ->
-			match ParserEntry.parse_string entry com.defines s null_pos raise_typing_error false with
+			match ParserEntry.parse_string (ParserConfig.default_config com.defines) entry s null_pos raise_typing_error false with
 			| ParseSuccess(r,_,_) -> r
 			| ParseError(_,(msg,p),_) -> Parser.error msg p
 		);
@@ -239,7 +239,7 @@ let make_macro_com_api com mcom p =
 			null_module
 		);
 		format_string = (fun s p ->
-			FormatString.format_string com.defines s p (fun e p -> (e,p))
+			FormatString.format_string (ParserConfig.file_parser_config com p.pfile) s p (fun e p -> (e,p))
 		);
 		cast_or_unify = (fun t e p ->
 			Interp.exc_string "unsupported"
@@ -301,7 +301,7 @@ let make_macro_com_api com mcom p =
 let make_macro_api ctx mctx p =
 	let parse_metadata s p =
 		try
-			match ParserEntry.parse_string Grammar.parse_meta ctx.com.defines s null_pos raise_typing_error false with
+			match ParserEntry.parse_string (ParserConfig.default_config mctx.com.defines) Grammar.parse_meta s null_pos raise_typing_error false with
 			| ParseSuccess(meta,_,_) -> meta
 			| ParseError(_,_,_) -> raise_typing_error "Malformed metadata string" p
 		with _ ->
@@ -1027,7 +1027,7 @@ let resolve_init_macro com e =
 	let p = fake_pos ("--macro " ^ e) in
 	let e = try
 		if String.get e (String.length e - 1) = ';' then raise_typing_error "Unexpected ;" p;
-		begin match ParserEntry.parse_expr_string com.defines e p raise_typing_error false with
+		begin match ParserEntry.parse_expr_string (ParserConfig.default_config com.defines) e p raise_typing_error false with
 		| ParseSuccess(data,_,_) -> data
 		| ParseError(_,(msg,p),_) -> (Parser.error msg p)
 		end

+ 2 - 2
src/typing/typeloadParse.ml

@@ -33,14 +33,14 @@ exception DisplayInMacroBlock
 let parse_file_from_lexbuf com file p lexbuf =
 	incr stats.s_files_parsed;
 	let parse_result = try
-		ParserEntry.parse Grammar.parse_file (Lexer.create_file_ctx file) com.defines lexbuf file
+		ParserEntry.parse (ParserConfig.file_parser_config com file) Grammar.parse_file (Lexer.create_file_ctx file) lexbuf file
 	with
 		| Sedlexing.MalFormed ->
 			raise_typing_error "Malformed file. Source files must be encoded with UTF-8." (file_pos file)
 		| e ->
 			raise e
 	in
-	begin match !Parser.display_mode,parse_result with
+	begin match com.display.dms_kind,parse_result with
 		| DMModuleSymbols (Some ""),_ -> ()
 		| DMModuleSymbols filter,(ParseSuccess(data,_,_)) when filter = None && DisplayPosition.display_position#is_in_file (com.file_keys#get file) ->
 			let ds = DocumentSymbols.collect_module_symbols None (filter = None) data in

+ 1 - 1
src/typing/typer.ml

@@ -626,7 +626,7 @@ and type_vars ctx vl p =
 		mk (TMeta((Meta.MergeBlock,[],p), e)) e.etype e.epos
 
 and format_string ctx s p =
-	FormatString.format_string ctx.com.defines s p (fun enext p ->
+	FormatString.format_string (ParserConfig.file_parser_config ctx.com p.pfile) s p (fun enext p ->
 		if ctx.f.in_display && DisplayPosition.display_position#enclosed_in p then
 			Display.preprocess_expr ctx.com (enext,p)
 		else