Skip to content

Commit 71a5d4b

Browse files
jrngitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 73e7b2e commit 71a5d4b

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

Documentation/gitattributes.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ patterns are available:
494494

495495
- `pascal` suitable for source code in the Pascal/Delphi language.
496496

497+
- `perl` suitable for source code in the Perl language.
498+
497499
- `php` suitable for source code in the PHP language.
498500

499501
- `python` suitable for source code in the Python language.

t/t4018-diff-funcname.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ EOF
3232

3333
sed 's/beer\\/beer,\\/' < Beer.java > Beer-correct.java
3434

35-
builtin_patterns="bibtex cpp csharp fortran html java objc pascal php python ruby tex"
35+
builtin_patterns="bibtex cpp csharp fortran html java objc pascal perl php python ruby tex"
3636
for p in $builtin_patterns
3737
do
3838
test_expect_success "builtin $p pattern compiles" '

userdiff.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,21 @@ PATTERNS("pascal",
6161
"|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+"
6262
"|<>|<=|>=|:=|\\.\\."
6363
"|[^[:space:]]|[\x80-\xff]+"),
64+
PATTERNS("perl",
65+
"^[ \t]*package .*;\n"
66+
"^[ \t]*sub .* \\{",
67+
/* -- */
68+
"[[:alpha:]_'][[:alnum:]_']*"
69+
"|0[xb]?[0-9a-fA-F_]*"
70+
/* taking care not to interpret 3..5 as (3.)(.5) */
71+
"|[0-9a-fA-F_]+(\\.[0-9a-fA-F_]+)?([eE][-+]?[0-9_]+)?"
72+
"|=>|-[rwxoRWXOezsfdlpSugkbctTBMAC>]|~~|::"
73+
"|&&=|\\|\\|=|//=|\\*\\*="
74+
"|&&|\\|\\||//|\\+\\+|--|\\*\\*|\\.\\.\\.?"
75+
"|[-+*/%.^&<>=!|]="
76+
"|=~|!~"
77+
"|<<|<>|<=>|>>"
78+
"|[^[:space:]]"),
6479
PATTERNS("php",
6580
"^[\t ]*(((public|protected|private|static)[\t ]+)*function.*)$\n"
6681
"^[\t ]*(class.*)$",

0 commit comments

Comments
 (0)