@matheusbsbs / matheus-bagliano / commits / 71a5d4bc0e
Fork 0

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>

Jonathan Nieder committed Dec 26, 2010 at 03:07 UTC 71a5d4bc0e4025b3fbdeed76052b39fcef284e8c
3 files changed +18 -1
Documentation/gitattributes.txt
+2
@@ -494,6 +494,8 @@ patterns are available:
494
495 - `pascal` suitable for source code in the Pascal/Delphi language.
496
497 +- `perl` suitable for source code in the Perl language.
498 +
499 - `php` suitable for source code in the PHP language.
500
501 - `python` suitable for source code in the Python language.
t/t4018-diff-funcname.sh
+1 -1
@@ -32,7 +32,7 @@ EOF
32
33 sed 's/beer\\/beer,\\/' < Beer.java > Beer-correct.java
34
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"
36 for p in $builtin_patterns
37 do
38 test_expect_success "builtin $p pattern compiles" '
userdiff.c
+15
@@ -61,6 +61,21 @@ PATTERNS("pascal",
61 "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+"
62 "|<>|<=|>=|:=|\\.\\."
63 "|[^[: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:]]"),
79 PATTERNS("php",
80 "^[\t ]*(((public|protected|private|static)[\t ]+)*function.*)$\n"
81 "^[\t ]*(class.*)$",