bug-m4
[Top][All Lists]
Advanced

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

\{n\} are not recognized as repetition counter in regular expressions.


From: Van de Bugger
Subject: \{n\} are not recognized as repetition counter in regular expressions.
Date: Fri, 04 Nov 2022 04:25:45 +0300
User-agent: Evolution 3.44.4 (3.44.4-2.fc36)

M4 documentation for regular expressions is extremely short:
https://www.gnu.org/software/m4/manual/html_node/Regexp.html
No regular expression syntax is explained, it just refers to GNU Emacs
Manual. In turn, GNU Emacs Manual: 
https://www.gnu.org/software/emacs/manual/html_node/emacs/Regexps.html
states that \{n\} is repetition counter:

> For example, ‘x\{4\}’ matches the string ‘xxxx’ and nothing else. 

However, m4 recognizes neither \{n\} nor {n}.

System info, m4 version and steps to reproduce the problem:

$ cat /etc/system-release
Fedora release 36 (Thirty Six)

$ rpm -q m4
m4-1.4.19-3.fc36.x86_64

$ 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 ./input 
Test 1: patsubst(`aaa', `^a', `X')
Exp. output: Xaa

Test 2: patsubst(`aaa', `^a\{2\}', `X')
Exp. output: Xa if \{2\} respected, aaa otherwise.

Test 3: patsubst(`aaa', `^a{2}', `X')
Exp. output: Xa if {2} respected, aaa otherwise.

$ m4 ./input 
Test 1: Xaa
Exp. output: Xaa

Test 2: aaa
Exp. output: Xa if \{2\} respected, aaa otherwise.

Test 3: aaa
Exp. output: Xa if {2} respected, aaa otherwise.

***

I was able to build m4 from the sources. I found regcomp.c file with
the regular expression compiler. The regular expression syntax is
controlled by re_syntax_options file scope variable, which can be set
by re_set_syntax function. In my experiments, re_set_syntax is not
called, re_syntax_options is always zero, so braces are treated
literally.

If I initialize re_syntax_options to RE_INTERVALS, e. g.:

reg_syntax_t re_syntax_options = RE_INTERVALS;

m4 recognizes \{n\} as repetition counter.

Thus, m4 is able to recognize \{n\} as repetition counter, but (for
unknown to me reason) this feature is disabled. I failed to trace it
further.

m4 manual does not document if this feature can be enabled or disabled
at build or run time, so I assume it should be enabled, as the \{n\}
construct is documented in GNU Emacs Manual, referred by GNU m4 Manual.

BTW, the fixed m4 passes 247 tests, skips 20 tests, and fails no tests
on my system. Original m4 shows exactly the same results.




reply via email to

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