@@ -93,31 +93,25 @@ module Table = struct
93
93
end
94
94
95
95
module Heavy_syntax = struct
96
- let create ~header ~data ~ align : Ast. table = ((header, data, align ), `Heavy )
96
+ let create ~header ~data : Ast. table = ((header, data, [] ), `Heavy )
97
97
98
98
let valid_header_row row =
99
- List. map
100
- (function
101
- | `Header align , x -> Some (Option. value align ~default: `Center , x)
102
- | `Data , _ -> None )
103
- row
99
+ List. map (function `Header , x -> Some x | `Data , _ -> None ) row
104
100
|> Option. join_list
105
101
106
102
let from_grid grid : Ast.table =
107
103
match grid with
108
- | [] -> create ~header: [] ~data: [] ~align: []
104
+ | [] -> create ~header: [] ~data: []
109
105
| row1 :: rows2_N ->
110
- let header, data, align =
106
+ let header, data =
111
107
(* If the first line is the header row, everything else is data. *)
112
108
match valid_header_row row1 with
113
- | Some header ->
114
- let align, header = List. split header in
115
- (header, rows2_N, align)
109
+ | Some header -> (header, rows2_N)
116
110
(* Otherwise everything is considered data. *)
117
- | None -> ([] , grid, [] )
111
+ | None -> ([] , grid)
118
112
in
119
113
let data = List. map (List. map snd) data in
120
- create ~header ~data ~align
114
+ create ~header ~data
121
115
end
122
116
end
123
117
@@ -1349,14 +1343,12 @@ and heavy_table_row ~parent_markup input =
1349
1343
let rec consume_cell_items acc =
1350
1344
Reader. until_rbrace input acc >>> fun next_token ->
1351
1345
match next_token.Loc. value with
1352
- | `Begin_table_header as token -> (
1346
+ | `Begin_table_header as token ->
1353
1347
junk input;
1354
1348
let content, _brace_location =
1355
1349
heavy_table_header input ~parent_markup: token
1356
1350
in
1357
- match content with
1358
- | None -> consume_cell_items ((`Header None , [] ) :: acc)
1359
- | Some (x , b ) -> consume_cell_items ((`Header x, b) :: acc))
1351
+ consume_cell_items ((`Header , content) :: acc)
1360
1352
| `Begin_table_data as token ->
1361
1353
junk input;
1362
1354
let content, token_after_list_item, _where_in_line =
@@ -1378,49 +1370,27 @@ and heavy_table_row ~parent_markup input =
1378
1370
in
1379
1371
consume_cell_items []
1380
1372
1381
- (* Consumes a table header (that might start with '{L ...}', '{C ...}' or '{R ... }',
1382
- which are represented by [`Begin_paragraph_style _] tokens).
1373
+ (* Consumes a table header.
1383
1374
1384
1375
This function is called immediately after '{th' ([`Begin_table_header]) is
1385
1376
read. The only "valid" way to exit is by reading a [`Right_brace] token,
1386
1377
which is consumed. *)
1387
1378
and heavy_table_header ~parent_markup input =
1388
1379
let rec consume_items acc =
1389
1380
Reader. until_rbrace input acc >>> fun next_token ->
1390
- match next_token.Loc. value with
1391
- | `Begin_paragraph_style style as token ->
1392
- junk input;
1393
- (match acc with
1394
- | Some _ ->
1395
- Parse_error. not_allowed next_token.location
1396
- ~what: (Token. describe token)
1397
- ~in_what: (Token. describe parent_markup)
1398
- |> add_warning input
1399
- | None -> () );
1400
- let content, token_after_list_item, _where_in_line =
1401
- block_element_list In_table_header ~parent_markup input
1402
- in
1403
- (match token_after_list_item.value with
1404
- | `Right_brace -> junk input
1405
- | `End ->
1406
- Parse_error. not_allowed token_after_list_item.location
1407
- ~what: (Token. describe `End ) ~in_what: (Token. describe token)
1408
- |> add_warning input);
1409
- consume_items (Some (Some style, content))
1410
- | token ->
1411
- (match acc with
1412
- | Some _ ->
1413
- Parse_error. not_allowed next_token.location
1414
- ~what: (Token. describe token)
1415
- ~in_what: (Token. describe parent_markup)
1416
- |> add_warning input
1417
- | None -> () );
1418
- let content, _token_after_list_item, _where_in_line =
1419
- block_element_list In_table_header ~parent_markup input
1420
- in
1421
- consume_items (Some (None , content))
1381
+ (match acc with
1382
+ | _ :: _ ->
1383
+ Parse_error. not_allowed next_token.location
1384
+ ~what: (Token. describe next_token.value)
1385
+ ~in_what: (Token. describe parent_markup)
1386
+ |> add_warning input
1387
+ | [] -> () );
1388
+ let content, _token_after_list_item, _where_in_line =
1389
+ block_element_list In_table_header ~parent_markup input
1390
+ in
1391
+ consume_items content
1422
1392
in
1423
- consume_items None
1393
+ consume_items []
1424
1394
1425
1395
(* {2 Entry point} *)
1426
1396
0 commit comments