groff
[Top][All Lists]
Advanced

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

Re: Warnings of dangling .el with bracket-less nesting


From: Tadziu Hoffmann
Subject: Re: Warnings of dangling .el with bracket-less nesting
Date: Fri, 19 Mar 2021 17:12:21 +0100
User-agent: Mutt/1.11.4 (2019-03-13)


> > The warnings do not happen if the "else" statements are
> > wrapped in \{\ ...  \} but is this supposed to be necessary?

> No.  It may be sanity-preserving to use the brace escapes but
> they are not syntactically required.

I will argue that they *are* necessary.  The code might appear
to be syntactically correct, but in general it might not do
what you want it to do.  This particular code:

  .de mymac
  .ie     '\\$1'a' CASE a
  .el .ie '\\$1'b' CASE b
  .el .ie '\\$1'c' CASE c
  .el              CASE z
  ..
  .mymac a
  .mymac b
  .mymac c
  .mymac d

only works because it is a linear "select first true of" switch
without branches, and an ".el" without an executed ".ie" is not taken.
(Remember that the decision logic is internally coded as a stack,
and an empty stack [which should not happen, and therefore
prints a warning] acts like "false".)

However, a branching switch like

  .de mymak
  .ie       '\\$1'a' \{.ie '\\$2'1' CASE a
  .el                \{.ie '\\$2'2' CASE b
  .el                               CASE x\}\}
  .el \{.ie '\\$1'b' \{.ie '\\$2'1' CASE c
  .el                \{.ie '\\$2'2' CASE d
  .el                               CASE y\}\}
  .el                               CASE z\}
  ..
  .mymak a 1
  .mymak a 2
  .mymak a 3
  .mymak b 1
  .mymak b 2
  .mymak b 3
  .mymak c 1
  .mymak c 2
  .mymak c 3

will not work without the braces.

You can of course also use macros for grouping, and thereby
avoid the use of braces altogether.  Note that here it becomes
very evident that there is an ".el" for every ".ie":

  .de mymax
  .ie '\\$1'a' .mymax1a      \\$2
  .el          .mymax2  \\$1 \\$2
  ..
  .de mymax2
  .ie '\\$1'b' .mymax2a      \\$2
  .el          CASE z
  ..
  .de mymax1a
  .ie '\\$1'1' CASE a
  .el          .mymax1b \\$1
  ..
  .de mymax1b
  .ie '\\$1'2' CASE b
  .el          CASE x
  ..
  .de mymax2a
  .ie '\\$1'1' CASE c
  .el          .mymax2b \\$1
  ..
  .de mymax2b
  .ie '\\$1'2' CASE d
  .el          CASE y
  ..
  .mymax a 1
  .mymax a 2
  .mymax a 3
  .mymax b 1
  .mymax b 2
  .mymax b 3
  .mymax c 1
  .mymax c 2
  .mymax c 3

This style of coding might appear a bit long-winded at first,
but actually becomes more convenient when lots of non-trivial
processing must be done in the different branches.





reply via email to

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