~sircmpwn/scdoc

7bdbb5bab590c0be795fba46a5e9ed4366fb2d4b — Sebastian a month ago 9140b4b
Disallows differing row lengths in table

scdoc will now fail if the rows in a table don't all have the same
length. A test has also been added to check this behavior, and scdoc(5)
has been updated to clarify the behavior.

Signed-off-by: Sebastian <sebastian@sebsite.pw>
3 files changed, 24 insertions(+), 3 deletions(-)

M scdoc.5.scd
M src/main.c
M test/tables
M scdoc.5.scd => scdoc.5.scd +2 -1
@@ 122,7 122,8 @@ respectively (or space to continue the previous cell on multiple lines),
followed by [ or - or ] to align the contents to the left, center, or right,
followed by a space and the contents of that cell. You may use a space instead
of an alignment specifier to inherit the alignment of the same column in the
previous row.
previous row. Each row must have the same number of columns; empty columns are
permitted.

The first character of the first row is not limited to | and has special
meaning. [ will produce a table with borders around each cell. | will produce a

M src/main.c => src/main.c +7 -2
@@ 481,6 481,7 @@ static void parse_table(struct parser *p, uint32_t style) {
	struct table_row *currow = NULL, *prevrow = NULL;
	struct table_cell *curcell = NULL;
	int column = 0;
	int numcolumns = -1;
	uint32_t ch;
	parser_pushch(p, '|');



@@ 495,12 496,16 @@ static void parse_table(struct parser *p, uint32_t style) {
			prevrow = currow;
			currow = xcalloc(1, sizeof(struct table_row));
			if (prevrow) {
				// TODO: Verify the number of columns match
				if (column != numcolumns && numcolumns != -1) {
					parser_fatal(p, "Each row must have the "
							"same number of columns");
				}
				numcolumns = column;
				column = 0;
				prevrow->next = currow;
			}
			curcell = xcalloc(1, sizeof(struct table_cell));
			currow->cell = curcell;
			column = 0;
			if (!table) {
				table = currow;
			}

M test/tables => test/tables +15 -0
@@ 10,3 10,18 @@ bug-example(1)
:-
EOF
end 0

begin "Disallows differing row lengths"
scdoc <<EOF >/dev/null
bug-example(1)

[-
:-
:-
|-
:-
|-
:-
:-
EOF
end 1