tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
* if/ie d condition always true
@ 2023-08-05 13:37 наб
  2023-08-08 18:05 ` Ingo Schwarze
  0 siblings, 1 reply; 2+ messages in thread
From: наб @ 2023-08-05 13:37 UTC (permalink / raw)
  To: tech

[-- Attachment #1: Type: text/plain, Size: 901 bytes --]

Happens on 1.14.6-1+b1 and some CVS HEAD version I have dated "Oct 26  2022":
  $ printf '%s\n' '.ds ABCD zupaninka 3' '.ie dABCD "\*[ABCD]".' '.el noabcd' | mandoc
  ()                                                                          ()
  
  "zupaninka 3".
  
                                                                              ()
  $ printf '%s\n' '.ie dABCD "\*[ABCD]".' '.el noabcd' | mandoc
  ()                                                                          ()
  
  "".
  
                                                                              ()

At least -Tlint also warns for this since it's using an undefined
variable. But it probably shouldn't since mandoc_roff(7) says
  • If the first character of condition is ‘d’, it evaluates to
    true if the rest of condition is the name of an existing user
    defined macro or string;

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: if/ie d condition always true
  2023-08-05 13:37 if/ie d condition always true наб
@ 2023-08-08 18:05 ` Ingo Schwarze
  0 siblings, 0 replies; 2+ messages in thread
From: Ingo Schwarze @ 2023-08-08 18:05 UTC (permalink / raw)
  To: nabijaczleweli; +Cc: tech

Hello Nab,

Nab wrote on Sat, Aug 05, 2023 at 03:37:43PM +0200:

> Happens on 1.14.6-1+b1 and some CVS HEAD version I have
> dated "Oct 26  2022":
>   $ printf '%s\n' '.ie dABCD "\*[ABCD]".' '.el noabcd' | mandoc
[...]
>   "".

Confirmed on OpenBSD-current, thanks for the report.

Testing with groff proves that mandoc ought to print

  noabcd

instead.  And indead, the following input file produces the correct
output with mandoc:

  .ie dABCD \{
  \*[ABCD] \}
  .el noabcd

The bug in mandoc is caused by the order of evaluation.
When mandoc processes the line

  .ie dABCD "\*[ABCD]".

it first calls roff_expand(), where it expands the string
using roff_getstrn(), which calls roff_setstrn() because expanding
an undefined string is required to define that string to empty.

Unfortunately, stuff like this also needs to work:

  .ds c x
  .ie d\*c\*c \*(\*c\*c
  .el not yet;
  .ds \*c\*c bingo
  .ie d\*c\*c \*(\*c\*c
  .el oops

This is supposed to print "not yet; bingo".

Consequently, part of the substitutions have to be done
before parsing the request (namely, in the request identifier
and in the first request argument), whereas the rest of the
substitutions, namely those in the further request arguments,
have to be done after interpreting the request - and only
if the request ends up with a true value.

This totally breaks the parsing paradigm in mandoc(1), which
always does all substitutions first, before parsing any requests
or macros.  I'm sorry i so far failed to find any idea for
a quick fix.

Consequently, i'll add this to the TODO file for now.

Yours,
  Ingo
--
 To unsubscribe send an email to tech+unsubscribe@mandoc.bsd.lv


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-08 18:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-05 13:37 if/ie d condition always true наб
2023-08-08 18:05 ` Ingo Schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).