瀏覽代碼

[parser] check for Eof

see #11368
Simon Krajewski 1 年之前
父節點
當前提交
c988f89330
共有 2 個文件被更改,包括 9 次插入1 次删除
  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 rec	parse_file s =
+let rec parse_file s =
 	last_doc := None;
 	match s with parser
 	| [< '(Kwd Package,_); pack = parse_package; s >] ->

+ 8 - 0
src/syntax/parserEntry.ml

@@ -363,6 +363,14 @@ let parse entry ctx code file =
 	try
 		let l = entry s in
 		(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
 		restore();
 		Lexer.restore old;