From 3a5f9afe163cd6b4e9d4a18ea43314b23251ced4 Mon Sep 17 00:00:00 2001 From: lubegasimon Date: Thu, 30 Nov 2023 17:27:16 +0300 Subject: [PATCH] warn when a table is unclosed --- src/parser/parse_error.ml | 4 ++++ src/parser/syntax.ml | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/parser/parse_error.ml b/src/parser/parse_error.ml index 4ee22c470a..6cb0eb4774 100644 --- a/src/parser/parse_error.ml +++ b/src/parser/parse_error.ml @@ -81,3 +81,7 @@ let truncated_code_block_meta : Loc.span -> Warning.t = let truncated_code_block : Loc.span -> Warning.t = Warning.make ~suggestion:"add ']}'." "Missing end of code block." + +let unclosed_table : Loc.span -> Warning.t = + Warning.make ~suggestion:"try to add '}' at the end of table content." + "Unclosed table '{t ...' or '{table ...'" diff --git a/src/parser/syntax.ml b/src/parser/syntax.ml index d8ecb87b55..e26c0948b3 100644 --- a/src/parser/syntax.ml +++ b/src/parser/syntax.ml @@ -118,13 +118,17 @@ module Table = struct end module Reader = struct - let until_rbrace input acc = + let until_rbrace_or_eof input acc = let rec consume () = let next_token = peek input in match next_token.value with | `Right_brace -> junk input; `End (acc, next_token.location) + | `End -> + Parse_error.unclosed_table next_token.location |> add_warning input; + junk input; + `End (acc, next_token.location) | `Space _ | `Single_newline _ | `Blank_line _ -> junk input; consume () @@ -1310,7 +1314,7 @@ and explicit_list_items : which is consumed. *) and light_table ~parent_markup ~parent_markup_location input = let rec consume_rows acc ~last_loc = - Reader.until_rbrace input acc >>> fun next_token -> + Reader.until_rbrace_or_eof input acc >>> fun next_token -> match next_token.Loc.value with | `Bar | #token_that_always_begins_an_inline_element -> ( let next, row, last_loc = @@ -1340,6 +1344,10 @@ and light_table_row ~parent_markup ~last_loc input = let return row cell = List.rev (push_cells row cell) in let next_token = peek input in match next_token.value with + | `End -> + Parse_error.unclosed_table next_token.location |> add_warning input; + junk input; + (`Stop, return acc_row acc_cell, next_token.location) | `Right_brace -> junk input; (`Stop, return acc_row acc_cell, next_token.location) @@ -1385,7 +1393,7 @@ and light_table_row ~parent_markup ~last_loc input = which is consumed. *) and heavy_table ~parent_markup ~parent_markup_location input = let rec consume_rows acc ~last_loc = - Reader.until_rbrace input acc >>> fun next_token -> + Reader.until_rbrace_or_eof input acc >>> fun next_token -> match next_token.Loc.value with | `Begin_table_row as token -> junk input; @@ -1411,7 +1419,7 @@ and heavy_table ~parent_markup ~parent_markup_location input = which is consumed. *) and heavy_table_row ~parent_markup input = let rec consume_cell_items acc = - Reader.until_rbrace input acc >>> fun next_token -> + Reader.until_rbrace_or_eof input acc >>> fun next_token -> match next_token.Loc.value with | `Begin_table_cell kind as token -> junk input;