On Fri, Nov 04, 2022 at 04:25:45AM +0300, Van de Bugger wrote:
> 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}.

This has bothered me too, over the years.

Even though it would be a new feature to enable \{\}, I can't see how
portable GNU m4 programs would have been relying on that matching
literal left curly brace.  I'm seriously thinking about turning this
feature on for 1.4.20.

> 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.
> 
> 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org


Reply via email to