[Top][All Lists]

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

Re: "grep '\]'" warnings suggest a Gnulib DFA patch

From: Paul Eggert
Subject: Re: "grep '\]'" warnings suggest a Gnulib DFA patch
Date: Sat, 4 Jun 2022 10:46:25 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1

On 6/3/22 20:08, Bruno Haible wrote:

But when I think about the thousands of people who use regular expressions
out there. How would they remember that in parentheses both should be
backslash-escaped in EREs
     \(   \)

It's even weirder, in that POSIX says unmatched ')' is treated like '\)' in an ERE, which is why gnulib/lib/dfa.c does not warn about it.

but brackets and braces are asymmetric
     \[   ]
     \{   }

Thanks, good catch about \}. We should treat it like \]. (And this means regex-quote.c is buggy in a different way, sigh....)

Even if the warning message you install in grep has 3 or 5 lines and goes
into all details, we are not serving the community if we force them to adhere
to asymmetric rules, where up to now they could use symmetric rules.

Thanks, and I see Jim agrees too. I installed the first two attached patches into Gnulib to do that and to fix regex-quote, propagated this into Grep, and installed the last attached patch to Grep to document this.

At some point the behavior of \], \}, and all the other stuff the Grep manuals new "Problematic Expressions" node should be documented in gnulib/doc/regex.texi too. I'll cc this to Reuben to see whether he has the time.

It might be useful for GNU grep to have a --pedantic flag to check regular expression portability, to reject unportable REs like '\]'. But any such feature can wait until after the next GNU grep release.

Attachment: 0001-dfa-do-not-warn-about-and.patch
Description: Text Data

Attachment: 0002-regex-quote-in-EREs.patch
Description: Text Data

Attachment: 0001-doc-document-and.patch
Description: Text Data

reply via email to

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