diff: funcname and word patterns for perl
The default function name discovery already works quite well for Perl
code... with the exception of here-documents (or rather their ending).
sub foo {
print <<END
here-document
END
return 1;
}
The default funcname pattern treats the unindented END line as a
function declaration and puts it in the @@ line of diff and "grep
--show-function" output.
With a little knowledge of perl syntax, we can do better. You can
try it out by adding "*.perl diff=perl" to the gitattributes file.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
73e7b2ef6c
commit
71a5d4bc0e
@ -494,6 +494,8 @@ patterns are available:
|
|||||||
|
|
||||||
- `pascal` suitable for source code in the Pascal/Delphi language.
|
- `pascal` suitable for source code in the Pascal/Delphi language.
|
||||||
|
|
||||||
|
- `perl` suitable for source code in the Perl language.
|
||||||
|
|
||||||
- `php` suitable for source code in the PHP language.
|
- `php` suitable for source code in the PHP language.
|
||||||
|
|
||||||
- `python` suitable for source code in the Python language.
|
- `python` suitable for source code in the Python language.
|
||||||
|
|||||||
@ -32,7 +32,7 @@ EOF
|
|||||||
|
|
||||||
sed 's/beer\\/beer,\\/' < Beer.java > Beer-correct.java
|
sed 's/beer\\/beer,\\/' < Beer.java > Beer-correct.java
|
||||||
|
|
||||||
builtin_patterns="bibtex cpp csharp fortran html java objc pascal php python ruby tex"
|
builtin_patterns="bibtex cpp csharp fortran html java objc pascal perl php python ruby tex"
|
||||||
for p in $builtin_patterns
|
for p in $builtin_patterns
|
||||||
do
|
do
|
||||||
test_expect_success "builtin $p pattern compiles" '
|
test_expect_success "builtin $p pattern compiles" '
|
||||||
|
|||||||
15
userdiff.c
15
userdiff.c
@ -61,6 +61,21 @@ PATTERNS("pascal",
|
|||||||
"|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+"
|
"|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+"
|
||||||
"|<>|<=|>=|:=|\\.\\."
|
"|<>|<=|>=|:=|\\.\\."
|
||||||
"|[^[:space:]]|[\x80-\xff]+"),
|
"|[^[:space:]]|[\x80-\xff]+"),
|
||||||
|
PATTERNS("perl",
|
||||||
|
"^[ \t]*package .*;\n"
|
||||||
|
"^[ \t]*sub .* \\{",
|
||||||
|
/* -- */
|
||||||
|
"[[:alpha:]_'][[:alnum:]_']*"
|
||||||
|
"|0[xb]?[0-9a-fA-F_]*"
|
||||||
|
/* taking care not to interpret 3..5 as (3.)(.5) */
|
||||||
|
"|[0-9a-fA-F_]+(\\.[0-9a-fA-F_]+)?([eE][-+]?[0-9_]+)?"
|
||||||
|
"|=>|-[rwxoRWXOezsfdlpSugkbctTBMAC>]|~~|::"
|
||||||
|
"|&&=|\\|\\|=|//=|\\*\\*="
|
||||||
|
"|&&|\\|\\||//|\\+\\+|--|\\*\\*|\\.\\.\\.?"
|
||||||
|
"|[-+*/%.^&<>=!|]="
|
||||||
|
"|=~|!~"
|
||||||
|
"|<<|<>|<=>|>>"
|
||||||
|
"|[^[:space:]]"),
|
||||||
PATTERNS("php",
|
PATTERNS("php",
|
||||||
"^[\t ]*(((public|protected|private|static)[\t ]+)*function.*)$\n"
|
"^[\t ]*(((public|protected|private|static)[\t ]+)*function.*)$\n"
|
||||||
"^[\t ]*(class.*)$",
|
"^[\t ]*(class.*)$",
|
||||||
|
|||||||
Reference in New Issue
Block a user