gbranden pushed a commit to branch master
in repository groff.
commit ab19255d1d0f8151ba590ccf5121e816fae457a3
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sun Mar 2 11:41:58 2025 -0600
[troff]: Implement recursive node dumping (1/9).
* src/roff/troff/node.h (struct node): Undeclare `dump_node_list()`
virtual function.
* src/roff/troff/node.cpp (node::dump_node_list): Rename this...
(dump_node_list): ...to this. Instead of being a member function, it
is now an ordinary function taking a pointer-to-node as argument.
This is a temporary measure to keep node list dumping working. Stop
throwing assertion if the given node pointer is null. Instead, we
simply write an empty list (`[ ]`).
* src/roff/troff/env.h (class environment): Rename member function
`dump_node_list()` to `dump_pending_nodes()`.
* src/roff/troff/env.cpp (environment::dump_node_list): Rename this...
(environment::dump_pending_nodes): ...to this.
(environment:add_char) [0]: Update call sites.
(environment::dump_node_list): Rename this...
(environment::dump_pending_nodes): ...to this. Stop refusing to
dump a null pointer. Update call site as above.
This change reveals formerly hidden nodes.
Changes `pline` request output as follows.
[{"type": "line_start_node", "diversion level": 0, "is_special_node":
false},
{"type": "zero_width_node", "diversion level": 0, "is_special_node":
false},
{"type": "glyph_node", "character": "d", "diversion level": 0,
"is_special_node": false},
{"type": "glyph_node", "character": "e", "diversion level": 0,
"is_special_node": false},
-{"type": "glyph_node", "character": "f", "diversion level": 0,
"is_special_node": false}]
+{"type": "glyph_node", "character": "f", "diversion level": 0,
"is_special_node": false},
+{"type": "word_space_node", "diversion level": 0, "is_special_node":
false}]
[{"type": "line_start_node", "diversion level": 0, "is_special_node":
false},
{"type": "hline_node", "diversion level": 0, "is_special_node": false},
{"type": "zero_width_node", "diversion level": 0, "is_special_node":
false},
{"type": "glyph_node", "character": "d", "diversion level": 0,
"is_special_node": false, "state": "<state>"},
{"type": "glyph_node", "character": "e", "diversion level": 0,
"is_special_node": false, "state": "<state>"},
-{"type": "glyph_node", "character": "f", "diversion level": 0,
"is_special_node": false, "state": "<state>"}]
+{"type": "glyph_node", "character": "f", "diversion level": 0,
"is_special_node": false, "state": "<state>"},
+{"type": "word_space_node", "diversion level": 0, "is_special_node":
false}]
+[ ]
[{"type": "line_start_node", "diversion level": 0, "is_special_node":
false},
---
ChangeLog | 21 +++++++++++++++++++++
src/roff/troff/env.cpp | 15 ++++++++-------
src/roff/troff/env.h | 2 +-
src/roff/troff/node.cpp | 10 +++++-----
src/roff/troff/node.h | 1 -
5 files changed, 35 insertions(+), 14 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 74066b114..e726a2ef9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2025-03-02 G. Branden Robinson <[email protected]>
+
+ * src/roff/troff/node.h (struct node): Undeclare
+ `dump_node_list()` virtual function.
+ * src/roff/troff/node.cpp (node::dump_node_list): Rename this...
+ (dump_node_list): ...to this. Instead of being a member
+ function, it is now an ordinary function taking a
+ pointer-to-node as argument. This is a temporary measure to
+ keep node list dumping working. Stop throwing assertion if the
+ given node pointer is null. Instead, we simply write an empty
+ list (`[ ]`).
+ * src/roff/troff/env.h (class environment): Rename member
+ function `dump_node_list()` to `dump_pending_nodes()`.
+ * src/roff/troff/env.cpp (environment::dump_node_list): Rename
+ this...
+ (environment::dump_pending_nodes): ...to this.
+ (environment:add_char) [0]: Update call sites.
+ (environment::dump_node_list): Rename this...
+ (environment::dump_pending_nodes): ...to this. Stop refusing to
+ dump a null pointer. Update call site as above.
+
2025-03-02 G. Branden Robinson <[email protected]>
[troff]: Revise `pline` output style. Use more JSON/YAML-ish
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index 4abb05f56..4349bba66 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -351,7 +351,7 @@ void environment::add_char(charinfo *ci)
start_line();
#if 0
fprintf(stderr, "current line is\n");
- line->dump_node_list();
+ dump_node_list(line);
#endif
if (ci != hyphen_indicator_char)
line = line->add_char(ci, this, &width_total, &space_total, &gc_np);
@@ -360,7 +360,7 @@ void environment::add_char(charinfo *ci)
}
#if 0
fprintf(stderr, "now after we have added character the line is\n");
- line->dump_node_list();
+ dump_node_list(line);
#endif
if ((!suppress_push) && gc_np) {
if (gc_np && (gc_np->state == 0 /* nullptr */)) {
@@ -374,7 +374,7 @@ void environment::add_char(charinfo *ci)
}
#if 0
fprintf(stderr, "now we have possibly added the state the line is\n");
- line->dump_node_list();
+ dump_node_list(line);
#endif
}
@@ -2418,10 +2418,11 @@ void environment::dump_troff_state()
#undef SPACES
}
-void environment::dump_node_list()
+extern void dump_node_list(node *);
+
+void environment::dump_pending_nodes()
{
- if (line != 0 /* nullptr */)
- line->dump_node_list();
+ dump_node_list(line);
}
statem *environment::construct_state(bool has_only_eol)
@@ -3599,7 +3600,7 @@ void print_env()
static void print_nodes_from_input_line()
{
- curenv->dump_node_list();
+ curenv->dump_pending_nodes();
skip_line();
}
diff --git a/src/roff/troff/env.h b/src/roff/troff/env.h
index 6b4ec03f9..09823b628 100644
--- a/src/roff/troff/env.h
+++ b/src/roff/troff/env.h
@@ -371,7 +371,7 @@ public:
int /* fill */);
void construct_new_line_state(node *n);
void dump_troff_state();
- void dump_node_list();
+ void dump_pending_nodes();
friend void title_length();
friend void space_size();
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index 0bd007e7b..e0ee14569 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -2627,17 +2627,17 @@ void node::dump_node()
fflush(stderr);
}
-void node::dump_node_list()
+// TODO: Turn this into container_node::dump().
+void dump_node_list(node *nlist)
{
// It's stored in reverse order already; this puts it forward again.
std::stack<node *> reversed_node_list;
- node *n = next;
+ node *n = nlist;
- assert(next != 0 /* nullptr */);
- do {
+ while (n != 0 /* nullptr */) {
reversed_node_list.push(n);
n = n->next;
- } while (n != 0 /* nullptr */);
+ }
fputc('[', stderr);
bool need_comma = false;
while (!reversed_node_list.empty()) {
diff --git a/src/roff/troff/node.h b/src/roff/troff/node.h
index d503c2e0e..efdcd6294 100644
--- a/src/roff/troff/node.h
+++ b/src/roff/troff/node.h
@@ -117,7 +117,6 @@ struct node {
virtual bool is_same_as(node *) = 0;
virtual const char *type() = 0;
virtual void dump_node();
- virtual void dump_node_list();
};
inline node::node()
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit