Re: [PATCH v1] checkpatch: Add context-analysis attributes
From: Joe Perches
Date: Sun Nov 15 2026 - 23:19:06 EST
On Sun, 2026-11-15 at 16:39 +0000, Vincent Donnefort wrote:
> On Sat, Nov 14, 2026 at 06:57:39AM -0800, Joe Perches wrote:
> > On Sat, 2026-11-14 at 06:26 -0800, Joe Perches wrote:
> > > > How about matching one internal () pair?
> > > >
> > > > __guarded_by\s*\(
> > > > (?:
> > > > [^()]++ |
> > > > \([^()]*+\)
> > > > )*+
> > > > \)
> > >
> > > Sure.
> > > Please add and use another variable so it's not repeated everywhere.
> >
> > Reading a bit about balanced parentheses in perl '(?R)'
> > non capturing recursion works since 5.10.0
> >
> > Maybe instead use
> >
> > /\((?:[^()]++|(?R))*\)/
>
> Somehow it doesn't work. I have tried the following:
>
> my $p = qr/\((?:[^()]++|(?R))*\)/;
> my $a = qr/__guarded_by\s*$p/;
> for my $s ("__guarded_by(&mutex)", "__guarded_by(foobar())") {
> print "$s:", ($s =~ /^$a$/ ? "ok" : "nope"), "\n";
> }'
>
> __guarded_by(&mutex): ok
> __guarded_by(foobar()): nope
>
> Did I miss something?
Dunno.
The only thing I got to work was using a capture group
in the additional string.
my $balanced_parens = qr{\s*((?x: \( (?: [^()]++ | (?-1) )* \) ))};
for my $s ("__guarded_by (&mutex)", "__guarded_by(foobar(qux(baz())))") {
if ($s =~ /__guarded_by$balanced_parens/) {
print("ok: $s: <$1>\n");
} else {
print("nope: $s: <$1>\n");
}
}