Skip to content

Commit 0641cb9

Browse files
panglesdjonludlam
authored andcommitted
Add suggestion on wrong content inside {table } and {tr }`
Signed-off-by: Paul-Elliot <[email protected]>
1 parent e592b29 commit 0641cb9

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/syntax.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,7 @@ and heavy_table ~parent_markup ~parent_markup_location input =
13381338
| token ->
13391339
Parse_error.not_allowed next_token.location ~what:(Token.describe token)
13401340
~in_what:(Token.describe parent_markup)
1341+
~suggestion:"Move outside of {table ...}, or inside {tr ...}"
13411342
|> add_warning input;
13421343
junk input;
13431344
consume_rows acc ~last_loc
@@ -1371,6 +1372,8 @@ and heavy_table_row ~parent_markup input =
13711372
| token ->
13721373
Parse_error.not_allowed next_token.location ~what:(Token.describe token)
13731374
~in_what:(Token.describe parent_markup)
1375+
~suggestion:
1376+
"Move outside of {table ...}, or inside {td ...} or {th ...}"
13741377
|> add_warning input;
13751378
junk input;
13761379
consume_cell_items acc

test/test_tables.ml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,33 @@ let%expect_test _ =
3737
(table (syntax heavy) (data ((row ((header ()))))) (align ())))))
3838
(warnings ())) |}]
3939

40+
let bad_data =
41+
test "{table absurd content}";
42+
[%expect
43+
{|
44+
((output (((f.ml (1 0) (1 22)) (table (syntax heavy) (data ()) (align ())))))
45+
(warnings
46+
( "File \"f.ml\", line 1, characters 7-13:\
47+
\n'absurd' is not allowed in '{table ...}' (table).\
48+
\nSuggestion: Move outside of {table ...}, or inside {tr ...}"
49+
"File \"f.ml\", line 1, characters 14-21:\
50+
\n'content' is not allowed in '{table ...}' (table).\
51+
\nSuggestion: Move outside of {table ...}, or inside {tr ...}"))) |}]
52+
53+
let bad_row =
54+
test "{table {tr absurd content}}";
55+
[%expect
56+
{|
57+
((output
58+
(((f.ml (1 0) (1 27)) (table (syntax heavy) (data ((row ()))) (align ())))))
59+
(warnings
60+
( "File \"f.ml\", line 1, characters 11-17:\
61+
\n'absurd' is not allowed in '{tr ...}' (table row).\
62+
\nSuggestion: Move outside of {table ...}, or inside {td ...} or {th ...}"
63+
"File \"f.ml\", line 1, characters 18-25:\
64+
\n'content' is not allowed in '{tr ...}' (table row).\
65+
\nSuggestion: Move outside of {table ...}, or inside {td ...} or {th ...}"))) |}]
66+
4067
let multiple_headers =
4168
test "{table {tr {th}} {tr {th}} {tr {td}}}";
4269
[%expect

0 commit comments

Comments
 (0)