Re: [RFC/PATCH] diff: funcname and word patterns for perl
- From
Jakub Narebski <jnareb@gmail.com>
- Date
- Dec 27, 2010, 22:44 UTC
- Message-ID
- <201012272344.42657.jnareb@gmail.com>
- In-Reply-To
- <7vmxnrxhgm.fsf@alter.siamese.dyndns.org>
On Mon, 27 Dec 2010, Junio C Hamano wrote:
Show 12 quoted lines
> Jakub Narebski <jnareb@gmail.com> writes:
>
> > 2. sub foo {
> > FOO: while (1) {
> > ...
> > }
> > }
> >
> > which should be marked with 'sub foo {', I think
>
> I do not think Jonathan's patterns would be fooled by this; it wants to
> catch only "package <anything>;" and "sub <anything> {".All right.
Show 18 quoted lines
> Jonathan's pattern set allows them to be indented, and followed by some
> garbage at the end., which we might want to tighten. How many people
> start 'package' and the outermost 'sub' indented?
>
> userdiff.c | 6 ++++--
> 1 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/userdiff.c b/userdiff.c
> index fc2afe3..79569c4 100644
> --- a/userdiff.c
> +++ b/userdiff.c
> @@ -62,8 +62,10 @@ PATTERNS("pascal",
> "|<>|<=|>=|:=|\\.\\."
> "|[^[:space:]]|[\x80-\xff]+"),
> PATTERNS("perl",
> - "^[ \t]*package .*;\n"
> - "^[ \t]*sub .* \\{",
> + "^package .*;\n"Note that in future Perl 5.14 there would be 'package NAME {' form, so perhaps it would be better to future-proof and use
+ "^package .*[;{]\n"> + "^sub .* \\{\n"Using "sub foo {" is just a recommended programming convention (like e.g. GNU convention or K&R convention for C code). I think it would be better to relax it a bit, either
+ "^sub "
or
+ "^sub .*( \\{)?\n"> + "^[A-Z]+ \\{\n" /* BEGIN, END, ... */We won't list possible block here?
> + "^=head[0-9] ", /* POD */ > /* -- */ > "[[:alpha:]_'][[:alnum:]_']*" > "|0[xb]?[0-9a-fA-F_]*"
-- Jakub Narebski Poland