gbranden pushed a commit to branch master in repository groff. commit 3648a3be66435e17c6cc4080e4146171b26ceca5 Author: G. Branden Robinson <g.branden.robin...@gmail.com> AuthorDate: Sat Mar 15 15:04:03 2025 -0500
[troff]: Implement recursive node dumping (8i/9). * src/roff/troff/node.cpp (class ligature_node): Add `dump_node` member function, overriding virtual function in `node` base class. (ligature_node::dump_node): Disclose more information, namely the contents of any contained nodes. Changes `pline` request output as follows. -{"type": "ligature_node", "diversion level": 0, "is_special_node": false, "special character": "fl"}, +{"type": "ligature_node", "diversion level": 0, "is_special_node": false, "n1": {"type": "glyph_node", "diversion level": 0, "is_special_node": false, "character": "f"}, "n2": {"type": "glyph_node", "diversion level": 0, "is_special_node": false, "character": "l"}}, --- ChangeLog | 8 ++++++++ src/roff/troff/node.cpp | 24 ++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index f1bcf224a..68b2d7627 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2025-03-15 G. Branden Robinson <g.branden.robin...@gmail.com> + + * src/roff/troff/node.cpp (class ligature_node): Add `dump_node` + member function, overriding virtual function in `node` base + class. + (ligature_node::dump_node): Disclose more information, namely + the contents of any contained nodes. + 2025-03-15 G. Branden Robinson <g.branden.robin...@gmail.com> [troff]: Derive class `bracket_node` from struct diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp index 6df4bccd5..c82b02517 100644 --- a/src/roff/troff/node.cpp +++ b/src/roff/troff/node.cpp @@ -1961,8 +1961,8 @@ public: bool is_tag(); }; -// TODO: Do not derive from `container_node`; implement custom double -// container dumper in dump_node(). +// Not derived from `container_node`; implements custom double container +// dumper in dump_node(). class ligature_node : public glyph_node { node *n1; node *n2; @@ -1987,6 +1987,7 @@ public: const char *type(); bool causes_tprint(); bool is_tag(); + void dump_node(); }; // TODO: Do not derive from `container_node`; implement custom double @@ -2299,6 +2300,25 @@ node *ligature_node::add_self(node *n, hyphen_list **p) return n; } +void ligature_node::dump_node() +{ + fputc('{', stderr); + // Flush so that in case something goes wrong with property dumping, + // we know that we traversed to a new node. + fflush(stderr); + node::dump_properties(); + if (n1 != 0 /* nullptr */) { + fputs(", \"n1\": ", stderr); + n1->dump_node(); + } + if (n2 != 0 /* nullptr */) { + fputs(", \"n2\": ", stderr); + n2->dump_node(); + } + fputc('}', stderr); + fflush(stderr); +} + kern_pair_node::kern_pair_node(hunits n, node *first, node *second, statem* s, int divlevel, node *x) : node(x, s, divlevel), amount(n), n1(first), n2(second) _______________________________________________ groff-commit mailing list groff-commit@gnu.org https://lists.gnu.org/mailman/listinfo/groff-commit