@@ -156,6 +156,11 @@ type token_that_always_begins_an_inline_element =
156
156
let _check_subset : token_that_always_begins_an_inline_element -> Token.t =
157
157
fun t -> (t :> Token.t )
158
158
159
+ (* The different contexts in which the inline parser [inline_element] and
160
+ [delimited_inline_parser] can be called. The inline parser's behavior depends
161
+ somewhat on the context: new lines are forbidden in light tables. *)
162
+ type inline_context = In_light_table | Outside_light_table
163
+
159
164
(* Consumes tokens that make up a single non-link inline element:
160
165
161
166
- a horizontal space ([`Space], significant in inline elements),
@@ -177,8 +182,12 @@ let _check_subset : token_that_always_begins_an_inline_element -> Token.t =
177
182
178
183
This function consumes exactly the tokens that make up the element. *)
179
184
let rec inline_element :
180
- input -> Loc. span -> _ -> Ast. inline_element with_location =
181
- fun input location next_token ->
185
+ input ->
186
+ Loc. span ->
187
+ context :inline_context ->
188
+ _ ->
189
+ Ast. inline_element with_location =
190
+ fun input location ~context next_token ->
182
191
match next_token with
183
192
| `Space _ as token ->
184
193
junk input;
@@ -208,7 +217,8 @@ let rec inline_element :
208
217
in
209
218
let content, brace_location =
210
219
delimited_inline_element_list ~parent_markup
211
- ~parent_markup_location: location ~requires_leading_whitespace input
220
+ ~parent_markup_location: location ~requires_leading_whitespace ~context
221
+ input
212
222
in
213
223
214
224
let location = Loc. span [ location; brace_location ] in
@@ -236,7 +246,7 @@ let rec inline_element :
236
246
let content, brace_location =
237
247
delimited_inline_element_list ~parent_markup
238
248
~parent_markup_location: location ~requires_leading_whitespace: false
239
- input
249
+ ~context input
240
250
in
241
251
242
252
let location = Loc. span [ location; brace_location ] in
@@ -274,7 +284,7 @@ let rec inline_element :
274
284
let content, brace_location =
275
285
delimited_inline_element_list ~parent_markup
276
286
~parent_markup_location: location ~requires_leading_whitespace: false
277
- input
287
+ ~context input
278
288
in
279
289
280
290
`Link (u, content) |> Loc. at (Loc. span [ location; brace_location ])
@@ -305,9 +315,11 @@ and delimited_inline_element_list :
305
315
parent_markup :[< Token. t ] ->
306
316
parent_markup_location :Loc. span ->
307
317
requires_leading_whitespace :bool ->
318
+ context :inline_context ->
308
319
input ->
309
320
Ast. inline_element with_location list * Loc. span =
310
- fun ~parent_markup ~parent_markup_location ~requires_leading_whitespace input ->
321
+ fun ~parent_markup ~parent_markup_location ~requires_leading_whitespace
322
+ ~context input ->
311
323
(* [~at_start_of_line] is used to interpret [`Minus] and [`Plus]. These are
312
324
word tokens if not the first non-whitespace tokens on their line. Then,
313
325
they are allowed in a non-link element list. *)
@@ -330,10 +342,17 @@ and delimited_inline_element_list :
330
342
it is an internal space, and we want to add it to the non-link inline
331
343
element list. *)
332
344
| (`Space _ | #token_that_always_begins_an_inline_element ) as token ->
333
- let acc = inline_element input next_token.location token :: acc in
345
+ let acc =
346
+ inline_element input next_token.location ~context token :: acc
347
+ in
334
348
consume_elements ~at_start_of_line: false acc
335
- | `Single_newline ws ->
349
+ | `Single_newline ws as blank ->
336
350
junk input;
351
+ if context = In_light_table then
352
+ Parse_error. not_allowed ~what: (Token. describe blank)
353
+ ~in_what: (Token. describe `Begin_table_light )
354
+ next_token.location
355
+ |> add_warning input;
337
356
let element = Loc. same next_token (`Space ws) in
338
357
consume_elements ~at_start_of_line: true (element :: acc)
339
358
| `Blank_line ws as blank ->
@@ -356,7 +375,9 @@ and delimited_inline_element_list :
356
375
~suggestion next_token.location
357
376
|> add_warning input);
358
377
359
- let acc = inline_element input next_token.location bullet :: acc in
378
+ let acc =
379
+ inline_element input next_token.location ~context bullet :: acc
380
+ in
360
381
consume_elements ~at_start_of_line: false acc
361
382
| other_token ->
362
383
Parse_error. not_allowed
@@ -438,7 +459,10 @@ let paragraph : input -> Ast.nestable_block_element with_location =
438
459
match next_token.value with
439
460
| (`Space _ | `Minus | `Plus | #token_that_always_begins_an_inline_element )
440
461
as token ->
441
- let element = inline_element input next_token.location token in
462
+ let element =
463
+ inline_element input next_token.location ~context: Outside_light_table
464
+ token
465
+ in
442
466
paragraph_line (element :: acc)
443
467
| _ -> acc
444
468
in
@@ -703,7 +727,7 @@ let rec block_element_list :
703
727
| { value = `Begin_table_row as token ; location } ->
704
728
let suggestion =
705
729
Printf. sprintf " move %s into %s." (Token. print token)
706
- (Token. describe ( `Begin_table `Heavy ) )
730
+ (Token. describe `Begin_table_heavy )
707
731
in
708
732
Parse_error. not_allowed ~what: (Token. describe token)
709
733
~in_what: (Token. describe parent_markup)
@@ -729,7 +753,7 @@ let rec block_element_list :
729
753
| { value = `Bar as token ; location } ->
730
754
let suggestion =
731
755
Printf. sprintf " move %s into %s." (Token. print token)
732
- (Token. describe ( `Begin_table `Light ) )
756
+ (Token. describe `Begin_table_light )
733
757
in
734
758
Parse_error. not_allowed ~what: (Token. describe token)
735
759
~in_what: (Token. describe parent_markup)
@@ -942,16 +966,19 @@ let rec block_element_list :
942
966
let block = Loc. at location block in
943
967
let acc = block :: acc in
944
968
consume_block_elements ~parsed_a_tag `After_text acc
945
- | { value = `Begin_table syntax as token ; location } as next_token ->
969
+ | { value = (`Begin_table_light | `Begin_table_heavy ) as token; location }
970
+ as next_token ->
946
971
warn_if_after_tags next_token;
947
972
warn_if_after_text next_token;
948
973
junk input;
949
974
let block, brace_location =
950
975
let parent_markup = token in
951
976
let parent_markup_location = location in
952
- match syntax with
953
- | `Light -> light_table input ~parent_markup ~parent_markup_location
954
- | `Heavy -> heavy_table input ~parent_markup ~parent_markup_location
977
+ match token with
978
+ | `Begin_table_light ->
979
+ light_table input ~parent_markup ~parent_markup_location
980
+ | `Begin_table_heavy ->
981
+ heavy_table input ~parent_markup ~parent_markup_location
955
982
in
956
983
let location = Loc. span [ location; brace_location ] in
957
984
let block = accepted_in_all_contexts context (`Table block) in
@@ -995,7 +1022,7 @@ let rec block_element_list :
995
1022
let content, brace_location =
996
1023
delimited_inline_element_list ~parent_markup: token
997
1024
~parent_markup_location: location ~requires_leading_whitespace: true
998
- input
1025
+ ~context: Outside_light_table input
999
1026
in
1000
1027
let location = Loc. span [ location; brace_location ] in
1001
1028
let paragraph =
@@ -1035,7 +1062,8 @@ let rec block_element_list :
1035
1062
let content, brace_location =
1036
1063
delimited_inline_element_list ~parent_markup: token
1037
1064
~parent_markup_location: location
1038
- ~requires_leading_whitespace: true input
1065
+ ~requires_leading_whitespace: true ~context: Outside_light_table
1066
+ input
1039
1067
in
1040
1068
if content = [] then
1041
1069
Parse_error. should_not_be_empty ~what: (Token. describe token)
@@ -1052,7 +1080,7 @@ let rec block_element_list :
1052
1080
let content, brace_location =
1053
1081
delimited_inline_element_list ~parent_markup: token
1054
1082
~parent_markup_location: location ~requires_leading_whitespace: true
1055
- input
1083
+ ~context: Outside_light_table input
1056
1084
in
1057
1085
let location = Loc. span [ location; brace_location ] in
1058
1086
@@ -1278,7 +1306,9 @@ and light_table_row ~parent_markup ~last_loc input =
1278
1306
let acc_row = if new_line then [] else List. rev acc_cell :: acc_row in
1279
1307
consume_row acc_row [] ~new_line: false ~last_loc
1280
1308
| #token_that_always_begins_an_inline_element as token ->
1281
- let i = inline_element input next_token.location token in
1309
+ let i =
1310
+ inline_element input next_token.location ~context: In_light_table token
1311
+ in
1282
1312
consume_row acc_row (i :: acc_cell) ~new_line: false
1283
1313
~last_loc: next_token.location
1284
1314
| other_token ->
0 commit comments