During identifier parsing, handle undefined escape sequences
authorschwarze <schwarze@openbsd.org>
Fri, 3 Jun 2022 11:50:25 +0000 (11:50 +0000)
committerschwarze <schwarze@openbsd.org>
Fri, 3 Jun 2022 11:50:25 +0000 (11:50 +0000)
commita72149c535858e8c6447105df6192e1459f98c38
treebe45ac903446d56bd03c1ec11446aa5c85faee3b
parent7ae9b579616454f76f794752986e0973ec31e6aa
During identifier parsing, handle undefined escape sequences
in the same way as groff:
* \\ is always reduced to \
* \. is always reduced to .
* other undefined escape sequences are usually reduced to the escape name,
for example \G to G, except during the expansion of expanding escape
sequences having the standard argument form (in particular \* and \n),
in which case the backslash is preserved literally.

Yes, this is confusing indeed.
For example, the following have the same meaning:
* .ds \.   and   .ds .     which is not the same as   .ds \\.
* \*[\.]   and   \*[.]     which is not the same as   \*[\\.]
* .ds \G   and   .ds G     which is not the same as   .ds \\G
* \*[\G]   and   \*[\\G]   which is not the same as   \*[G]   <- sic!

To feel less dirty, have a leaning toothpick, if you are so inclined.

This patch also slightly improves the string shown by the "escaped
character not allowed in a name" error message.
18 files changed:
regress/usr.bin/mandoc/roff/args/man.out_lint
regress/usr.bin/mandoc/roff/args/mdoc.out_lint
regress/usr.bin/mandoc/roff/cond/register.in
regress/usr.bin/mandoc/roff/cond/register.out_ascii
regress/usr.bin/mandoc/roff/cond/string.in
regress/usr.bin/mandoc/roff/cond/string.out_ascii
regress/usr.bin/mandoc/roff/de/escname.in
regress/usr.bin/mandoc/roff/de/escname.out_ascii
regress/usr.bin/mandoc/roff/de/escname.out_lint
regress/usr.bin/mandoc/roff/ds/Makefile
regress/usr.bin/mandoc/roff/nr/escname.in
regress/usr.bin/mandoc/roff/nr/escname.out_ascii
regress/usr.bin/mandoc/roff/nr/escname.out_lint
regress/usr.bin/mandoc/roff/string/Makefile
regress/usr.bin/mandoc/roff/string/name.in
regress/usr.bin/mandoc/roff/string/name.out_ascii
regress/usr.bin/mandoc/roff/string/name.out_lint
usr.bin/mandoc/roff.c