groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 17/38: [troff]: Improve error diagnostics.


From: G. Branden Robinson
Subject: [groff] 17/38: [troff]: Improve error diagnostics.
Date: Mon, 3 Oct 2022 01:42:56 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 2a993b9441fa28cd04c1cf86035dad137375ebc6
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Wed Sep 28 18:31:09 2022 -0500

    [troff]: Improve error diagnostics.
    
    * src/roff/troff/input.cpp (spring_trap, interpolate_string)
      (interpolate_string_with_args): Improve error diagnostics: when a
      sprung trap or an interpolation fails because it's being attempted on
      a request, say so explicitly and _name_ it.  If the argument to the
      trap-planting request or to a string interpolation escape sequence is
      itself an interpolation, this name might not be obvious.  Consider:
        .wh \n[pos] \*[mac]
        .em \*[mac]
        .itc 1 \*[mac]
        \*[\*[mac]]
      Supplying this information requires no additional overhead.
---
 ChangeLog                | 15 +++++++++++++++
 src/roff/troff/input.cpp |  9 ++++++---
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index cbe85964a..113b065b2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2022-09-28  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       * src/roff/troff/input.cpp (spring_trap, interpolate_string)
+       (interpolate_string_with_args): Improve error diagnostics: when
+       a sprung trap or an interpolation fails because it's being
+       attempted on a request, say so explicitly and _name_ it.  If the
+       argument to the trap-planting request or to a string
+       interpolation escape sequence is itself an interpolation, this
+       name might not be obvious.  Consider:
+         .wh \n[pos] \*[mac]
+         .em \*[mac]
+         .itc 1 \*[mac]
+         \*[\*[mac]]
+       Supplying this information requires no additional overhead.
+
 2022-09-28  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * src/roff/troff/input.cpp (interpolate_string): Trivially
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 8ae239971..b2179919d 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -4090,11 +4090,14 @@ void spring_trap(symbol nm)
   static char buf2[2] = { END_TRAP, '\0' };
   input_stack::push(make_temp_iterator(buf2));
   request_or_macro *p = lookup_request(nm);
+  // We don't perform this validation at the time the trap is planted
+  // because a request name might be replaced by a macro by the time the
+  // trap springs.
   macro *m = p->to_macro();
   if (m)
     input_stack::push(new macro_iterator(nm, *m, "trap-called macro"));
   else
-    error("you can't invoke a request with a trap");
+    error("trap failed to spring: '%1' is a request", nm.contents());
   input_stack::push(make_temp_iterator(buf));
 }
 
@@ -4327,7 +4330,7 @@ static void interpolate_string(symbol nm)
   request_or_macro *p = lookup_request(nm);
   macro *m = p->to_macro();
   if (!m)
-    error("you can only invoke a string or macro using escaped '*'");
+    error("cannot interpolate request '%1'", nm.contents());
   else {
     if (m->is_string()) {
       string_iterator *si = new string_iterator(*m, "string", nm);
@@ -4347,7 +4350,7 @@ static void interpolate_string_with_args(symbol nm)
   request_or_macro *p = lookup_request(nm);
   macro *m = p->to_macro();
   if (!m)
-    error("you can only invoke a string or macro using escaped '*'");
+    error("cannot interpolate request '%1'", nm.contents());
   else {
     macro_iterator *mi = new macro_iterator(nm, *m);
     decode_string_args(mi);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]