Skip to content

Commit

Permalink
[parser] check for Eof
Browse files Browse the repository at this point in the history
see #11368
  • Loading branch information
Simn authored and kLabz committed Nov 16, 2023
1 parent 38c4d0c commit c988f89
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/syntax/grammar.mly
Original file line number Diff line number Diff line change
Expand Up @@ -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 >] ->
Expand Down
8 changes: 8 additions & 0 deletions src/syntax/parserEntry.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c988f89

Please sign in to comment.