gbranden pushed a commit to branch master
in repository groff.

commit c16bea9bdfb2eaa9b97c806e79aff441e9795087
Author: G. Branden Robinson <g.branden.robin...@gmail.com>
AuthorDate: Sun Mar 2 21:48:10 2025 -0600

    [troff]: Implement recursive node dumping (2/9).
    
    * src/roff/troff/node.h (struct node): Add new virtual member function,
      `dump_properties()`, to support modular composition of node dumping.
      All nodes have properties, but some dervived classes of `node` have
      _additional_ properties.  Also, we want to be able to distinguish
      property reporting from contained-node reporting, which is where
      recursion comes in.
    
      (node::dump_properties): Implement it.  This takes over most of the
      former function of `node::dump_node()`...
    
      (node::dump_node): ...which now just writes out braces `{` `}` with
      properties in between.
---
 ChangeLog               | 13 +++++++++++++
 src/roff/troff/node.cpp | 16 +++++++++++++---
 src/roff/troff/node.h   |  1 +
 3 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e726a2ef9..8d8769a3b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2025-03-02  G. Branden Robinson <g.branden.robin...@gmail.com>
+
+       * src/roff/troff/node.h (struct node): Add new virtual member
+       function, `dump_properties()`, to support modular composition of
+       node dumping.  All nodes have properties, but some dervived
+       classes of `node` have _additional_ properties.  Also, we want
+       to be able to distinguish property reporting from contained-node
+       reporting, which is where recursion comes in.
+       (node::dump_properties): Implement it.  This takes over most of
+       the former function of `node::dump_node()`...
+       (node::dump_node): ...which now just writes out braces `{` `}`
+       with properties in between.
+
 2025-03-02  G. Branden Robinson <g.branden.robin...@gmail.com>
 
        * src/roff/troff/node.h (struct node): Undeclare
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index e0ee14569..a3637291c 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -2609,9 +2609,9 @@ units node::size()
   return points_to_units(10);
 }
 
-void node::dump_node()
+void node::dump_properties()
 {
-  fprintf(stderr, "{\"type\": \"%s\"", type());
+  fprintf(stderr, "\"type\": \"%s\"", type());
   fprintf(stderr, ", \"diversion level\": %d", div_nest_level);
   fprintf(stderr, ", \"is_special_node\": %s",
          is_special ? "true" : "false");
@@ -2623,7 +2623,17 @@ void node::dump_node()
     fputs(", \"state\": ", stderr);
     state->display_state();
   }
-  fputs("}", stderr);
+  fflush(stderr);
+}
+
+void 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);
+  dump_properties();
+  fputc('}', stderr);
   fflush(stderr);
 }
 
diff --git a/src/roff/troff/node.h b/src/roff/troff/node.h
index efdcd6294..2af7662b0 100644
--- a/src/roff/troff/node.h
+++ b/src/roff/troff/node.h
@@ -116,6 +116,7 @@ struct node {
 
   virtual bool is_same_as(node *) = 0;
   virtual const char *type() = 0;
+  virtual void dump_properties();
   virtual void dump_node();
 };
 

_______________________________________________
groff-commit mailing list
groff-commit@gnu.org
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to