Browse Source

[parser] check for Eof

see #11368
Simon Krajewski 1 year ago
parent
commit
c988f89330
2 changed files with 9 additions and 1 deletions
  1. 1 1
      src/syntax/grammar.mly
  2. 8 0
      src/syntax/parserEntry.ml

+ 1 - 1
src/syntax/grammar.mly

@@ -121,7 +121,7 @@ let check_redundant_var p1 = parser
 
 
 let parsing_macro_cond = ref false
 let parsing_macro_cond = ref false
 
 
-let rec	parse_file s =
+let rec parse_file s =
 	last_doc := None;
 	last_doc := None;
 	match s with parser
 	match s with parser
 	| [< '(Kwd Package,_); pack = parse_package; s >] ->
 	| [< '(Kwd Package,_); pack = parse_package; s >] ->

+ 8 - 0
src/syntax/parserEntry.ml

@@ -363,6 +363,14 @@ let parse entry ctx code file =
 	try
 	try
 		let l = entry s in
 		let l = entry s in
 		(match !mstack with p :: _ -> syntax_error Unclosed_conditional ~pos:(Some p) sraw () | _ -> ());
 		(match !mstack with p :: _ -> syntax_error Unclosed_conditional ~pos:(Some p) sraw () | _ -> ());
+		begin match Stream.peek s with
+			| None ->
+				() (* Eof could already have been consumed *)
+			| Some (Eof,_) ->
+				() (* This is what we want *)
+			| Some (tok,p) ->
+				error (Unexpected tok) p (* This isn't *)
+		end;
 		let was_display_file = !in_display_file in
 		let was_display_file = !in_display_file in
 		restore();
 		restore();
 		Lexer.restore old;
 		Lexer.restore old;