[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 17/17: [tbl]: Refactor handling of vertical lines.
From: |
G. Branden Robinson |
Subject: |
[groff] 17/17: [tbl]: Refactor handling of vertical lines. |
Date: |
Thu, 2 Feb 2023 04:24:39 -0500 (EST) |
gbranden pushed a commit to branch master
in repository groff.
commit 006e24c9f592304ecded205460bd075ee1f0fa44
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Mon Jan 30 13:19:36 2023 -0600
[tbl]: Refactor handling of vertical lines.
[tbl]: Refactor handling of vertical lines in table. Validate input
more strictly. Add diagnostics when vertical lines are redundant with
box borders.
* src/preproc/tbl/main.cpp (process_format): Shift diagnostic about
excess vertical lines in a sequence at the beginning of a row
description to later, after the first proper column descriptor has
been interpreted. Normalize a sequence of more than two consecutive
vertical lines to 2 when they occur at the beginning of a row
description. Unconditionally update `list->vline` and reset
`vline_count` once we start looking for modifiers, since we know we've
finished any sequence of vertical lines, and at the end of a row
definition. Rename and retype loop variable int `success` to Boolean
`is_valid_modifier_sequence`. Drop now-invalid assertion.
* src/preproc/tbl/table.cpp (table::add_vlines): Throw new diagnostics
when vertical lines are redundant with box borders. Add assertion to
ensure we got a valid vertical line value (0, 1, or 2) from
`process_format`. Throw these only once per table format, not for
every row.
Tested with:
.ll 64n
.nf
1234567890123456789012345678901234567890123456789012345678901234
.fi
.TS
L L L L L.
abandoning babysitter cablecasts dachshunds earmarkingX
.TE
.
.TS
| L L L L L.
abandoning babysitter cablecasts dachshunds earmarkingX
.TE
.
.TS
L L L L L |.
abandoning babysitter cablecasts dachshunds earmarkingX
.TE
.
.TS
| L L L L L |.
abandoning babysitter cablecasts dachshunds earmarkingX
.TE
.
.TS
doublebox;
L L L L L.
abandoning babysitter cablecasts dachshunds earmarkingX
.TE
.
.TS
box;
| L L L L L |.
abandoning babysitter cablecasts dachshunds earmarkingX
.TE
.
.TS
box tab(:);
Lz S | Rt
Ld| Cb| ^
^ | Rz S.
left:r
l:center:
:right
.TE
.TS
L,|||R.
foo
bar
.TE
.TS
L||R.
foo bar
.TE
.pl \n(nlu
---
ChangeLog | 23 +++++++++++++++++++++++
src/preproc/tbl/main.cpp | 33 +++++++++++++++++----------------
src/preproc/tbl/table.cpp | 19 +++++++++++++++++--
3 files changed, 57 insertions(+), 18 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 7294c63f3..760efe9a9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2023-02-02 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ [tbl]: Refactor handling of vertical lines in format. Validate
+ input more strictly. Add diagnostics when vertical lines are
+ redundant with box borders.
+
+ * src/preproc/tbl/main.cpp (process_format): Shift diagnostic
+ about excess vertical lines in a sequence at the beginning of a
+ row description to later, after the first proper column
+ descriptor has been interpreted. Normalize a sequence of more
+ than two consecutive vertical lines to 2 when they occur at the
+ beginning of a row description. Unconditionally update
+ `list->vline` and reset `vline_count` once we start looking for
+ modifiers, since we know we've finished any sequence of vertical
+ lines, and at the end of a row definition. Rename and retype
+ loop variable int `success` to Boolean
+ `is_valid_modifier_sequence`. Drop now-invalid assertion.
+ * src/preproc/tbl/table.cpp (table::add_vlines): Throw new
+ diagnostics when vertical lines are redundant with box borders.
+ Add assertion to ensure we got a valid vertical line value (0,
+ 1, or 2) from `process_format`. Throw these only once per table
+ format, not for every row.
+
2023-01-30 G. Branden Robinson <g.branden.robinson@gmail.com>
* src/preproc/tbl/main.cpp (process_table): Trivially refactor.
diff --git a/src/preproc/tbl/main.cpp b/src/preproc/tbl/main.cpp
index a868b4238..467c19f86 100644
--- a/src/preproc/tbl/main.cpp
+++ b/src/preproc/tbl/main.cpp
@@ -841,11 +841,7 @@ format *process_format(table_input &in, options *opt,
// leading vertical line in row
opt->flags |= table::HAS_TOP_VLINE;
vline_count++;
- if (vline_count > 2) {
- vline_count = 2;
- error("more than 2 vertical lines at beginning of row"
- " description");
- }
+ // list->vline_count is updated later
break;
case ' ':
case '\t':
@@ -868,9 +864,14 @@ format *process_format(table_input &in, options *opt,
if (got_period)
break;
list = new input_entry_format(t, list);
- if (vline_count)
- list->vline_count = vline_count;
- int success = 1;
+ if (vline_count > 2) {
+ vline_count = 2;
+ error("more than 2 vertical lines at beginning of row description");
+ }
+ list->vline_count = vline_count;
+ // Now handle modifiers.
+ vline_count = 0;
+ bool is_valid_modifier_sequence = true;
do {
switch (c) {
case '0':
@@ -1115,7 +1116,7 @@ format *process_format(table_input &in, options *opt,
if (is_first_row)
opt->flags |= table::HAS_TOP_VLINE;
c = in.get();
- list->vline++;
+ vline_count++;
break;
case ' ':
case '\t':
@@ -1125,15 +1126,17 @@ format *process_format(table_input &in, options *opt,
if (c == opt->tab_char)
c = in.get();
else
- success = 0;
+ is_valid_modifier_sequence = false;
break;
}
- } while (success);
- if (list->vline > 2) {
- list->vline = 2;
+ } while (is_valid_modifier_sequence);
+ if (vline_count > 2) {
+ vline_count = 2;
error("more than 2 vertical lines after column descriptor");
}
+ list->vline += vline_count;
if (c == '\n' || c == ',') {
+ vline_count = 0;
is_first_row = false;
c = in.get();
list->is_last_column = true;
@@ -1238,10 +1241,8 @@ format *process_format(table_input &in, options *opt,
error("multiple widths for column %1", col + 1);
f->width[col] = tem->width;
}
- if (tem->vline_count) {
- assert(col == 0);
+ if (tem->vline_count)
f->vline[row][col] = tem->vline_count;
- }
f->vline[row][col + 1] = tem->vline;
if (tem->is_last_column) {
row++;
diff --git a/src/preproc/tbl/table.cpp b/src/preproc/tbl/table.cpp
index 97b0845d1..d815bbf13 100644
--- a/src/preproc/tbl/table.cpp
+++ b/src/preproc/tbl/table.cpp
@@ -1675,8 +1675,23 @@ void table::add_entry(int r, int c, const string &str,
void table::add_vlines(int r, const char *v)
{
allocate(r);
- for (int i = 0; i < ncolumns+1; i++)
- vline[r][i] = v[i];
+ bool lwarned = false;
+ bool twarned = false;
+ for (int i = 0; i < ncolumns+1; i++) {
+ assert(v[i] < 3);
+ if (v[i] && (flags & (BOX | ALLBOX | DOUBLEBOX)) && (i == 0)
+ && (!lwarned)) {
+ error("ignoring vertical line at leading edge of boxed table");
+ lwarned = true;
+ }
+ else if (v[i] && (flags & (BOX | ALLBOX | DOUBLEBOX))
+ && (i == ncolumns) && (!twarned)) {
+ error("ignoring vertical line at trailing edge of boxed table");
+ twarned = true;
+ }
+ else
+ vline[r][i] = v[i];
+ }
}
void table::check()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 17/17: [tbl]: Refactor handling of vertical lines.,
G. Branden Robinson <=