Skip to content

Commit 4003ba4

Browse files
gpetiotjonludlam
authored andcommitted
Convert light table contents to nestable block elements
1 parent cc1598d commit 4003ba4

File tree

4 files changed

+199
-91
lines changed

4 files changed

+199
-91
lines changed

src/ast.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ type nestable_block_element =
5555
{{:https://ocaml.org/releases/4.12/htmlman/ocamldoc.html#sss:ocamldoc-list}manual}).
5656
*)
5757

58-
and table =
59-
[ `Light of inline_element abstract_table
60-
| `Heavy of nestable_block_element abstract_table ]
58+
and table = nestable_block_element abstract_table * [ `Light | `Heavy ]
6159

6260
type internal_tag =
6361
[ `Canonical of string with_location | `Inline | `Open | `Closed ]

src/syntax.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ module Table = struct
6363
| _ -> None
6464

6565
let valid_align_row lx = List.map valid_align lx |> Option.join_list
66-
let create ~header ~data ~align : Ast.table = `Light (header, data, align)
66+
67+
let create ~header ~data ~align : Ast.table =
68+
let to_block x = Loc.at x.Loc.location (`Paragraph [ x ]) in
69+
let cell_to_block = List.map to_block in
70+
let row_to_block = List.map cell_to_block in
71+
let grid_to_block = List.map row_to_block in
72+
((row_to_block header, grid_to_block data, align), `Light)
6773

6874
let from_grid (grid : _ Ast.grid) : Ast.table =
6975
match grid with
@@ -87,7 +93,7 @@ module Table = struct
8793
end
8894

8995
module Heavy_syntax = struct
90-
let create ~header ~data ~align : Ast.table = `Heavy (header, data, align)
96+
let create ~header ~data ~align : Ast.table = ((header, data, align), `Heavy)
9197

9298
let valid_header_row row =
9399
List.map

test/test.ml

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,20 @@ module Ast_to_sexp = struct
8585
|> fun items -> List items
8686
in
8787
List [ Atom kind; Atom weight; items ]
88-
| `Table t -> (
88+
| `Table ((header, data, align), s) ->
89+
let syntax = function `Light -> "light" | `Heavy -> "heavy" in
8990
let map name x f = List [ Atom name; List (List.map f x) ] in
90-
let to_sexp (type a) ((header, data, align) : a Ast.abstract_table)
91-
~syntax ~f =
92-
List
93-
[
94-
Atom "table";
95-
List [ Atom "syntax"; Atom syntax ];
96-
( map "header" header @@ fun cell ->
97-
map "cell" cell @@ at.at (f at) );
98-
( map "data" data @@ fun row ->
99-
map "row" row @@ fun cell -> map "cell" cell @@ at.at (f at) );
100-
map "align" align @@ alignment;
101-
]
102-
in
103-
match t with
104-
| `Light t -> to_sexp t ~syntax:"light" ~f:inline_element
105-
| `Heavy t -> to_sexp t ~syntax:"heavy" ~f:nestable_block_element)
91+
List
92+
[
93+
Atom "table";
94+
List [ Atom "syntax"; Atom (syntax s) ];
95+
( map "header" header @@ fun cell ->
96+
map "cell" cell @@ at.at (nestable_block_element at) );
97+
( map "data" data @@ fun row ->
98+
map "row" row @@ fun cell ->
99+
map "cell" cell @@ at.at (nestable_block_element at) );
100+
map "align" align @@ alignment;
101+
]
106102

107103
let tag at : Ast.tag -> sexp = function
108104
| `Author s -> List [ Atom "@author"; Atom s ]

0 commit comments

Comments
 (0)