bug-m4
[Top][All Lists]
Advanced

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

m4 regexp documentation is misleading trash


From: Van de Bugger
Subject: m4 regexp documentation is misleading trash
Date: Sat, 12 Nov 2022 00:04:43 +0300
User-agent: Evolution 3.44.4 (3.44.4-2.fc36)

M4 manual does not describe regular expressions, but refers to GNU
Emacs Manual instead. But actually, m4 does not recognize Emacs variant
of regular expressions.


Character classes
-----------------

The GNU Emacs Manual states:

\sc

    matches any character whose syntax is c. Here c is a
    character that designates a particular syntax class: thus, 
    ‘w’ for word constituent, ‘-’ or ‘ ’ for whitespace, ‘.’
    for ordinary punctuation, etc. See Syntax Class Table in The
    Emacs Lisp Reference Manual.

—
https://www.gnu.org/software/emacs/manual/html_node/emacs/Regexp-Backslash.html

Ok, lets try it:

$ m4 --version
m4 (GNU M4) 1.4.19
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by René Seindal.

$ cat ./test.m4
=patsubst(`  Hello!  ', `\sw+')=
Expected result: =  !  =

=patsubst(`  Hello!  ', `\s.+')=
Expected result: =  Hello  =

=patsubst(`  Hello!  ', `\s-+')=
Expected result: =Hello!=

$ m4 ./test.m4
=  Hello!  =
Expected result: =  !  =

==
Expected result: =  Hello  =

=  Hello!  =
Expected result: =Hello!=

Bang! M4 does not recognize \sw for word constituent, \s. for
punctuation, \s- for whitespace.

It seems M4 recognizes just \s for whitespace:

$ cat ./test.m4
=patsubst(`  Hello!  ', `\s')=

$ m4 ./test.m4
=Hello!=


Shy groups
----------

GNU Emacs manual:

\(?: … \)

    specifies a shy group that does not record the matched substring;
    you can’t refer back to it with ‘\d’ (see below). This is useful
    in mechanically combining regular expressions, so that you can add
    groups for syntactic purposes without interfering with the
    numbering of the groups that are meant to be referred to.

\(?:...\) is not recognized by M4:

$ cat ./test.m4
=patsubst(`  Hello!  ', `\(?:ll\)')=

$ m4 ./test.m4
=  Hello!  =






reply via email to

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