@matheusbsbs / matheus-bagliano / commits / 75c3b6b2e8
Fork 0

userdiff: improve Fortran xfuncname regex

The third part of the Fortran xfuncname regex wants to match the beginning of a subroutine or function, so it allows for all characters except `'`, `"` or whitespace before the keyword 'function' or 'subroutine'. This is meant to match the 'recursive', 'elemental' or 'pure' keywords, as well as function return types, and to prevent matches inside strings. However, the negated set does not contain the `!` comment character, so a line with an end-of-line comment containing the keyword 'function' or 'subroutine' followed by another word is mistakenly chosen as a hunk header. Improve the regex by adding `!` to the negated set. Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Philippe Blain committed Aug 12, 2020 at 22:30 UTC 75c3b6b2e8a72239fa23e039c46f9a5cf8c24142
2 files changed +1 -2
t/t4018/fortran-comment-keyword
-1
@@ -8,7 +8,6 @@
8 real funcB ! grid function b
9
10 real ChangeMe
11 - integer broken
11
12 end subroutine RIGHT
13
userdiff.c
+1 -1
@@ -53,7 +53,7 @@ IPATTERN("fortran",
53 /* Program, module, block data */
54 "^[ \t]*((END[ \t]+)?(PROGRAM|MODULE|BLOCK[ \t]+DATA"
55 /* Subroutines and functions */
56 - "|([^'\" \t]+[ \t]+)*(SUBROUTINE|FUNCTION))[ \t]+[A-Z].*)$",
56 + "|([^!'\" \t]+[ \t]+)*(SUBROUTINE|FUNCTION))[ \t]+[A-Z].*)$",
57 /* -- */
58 "[a-zA-Z][a-zA-Z0-9_]*"
59 "|\\.([Ee][Qq]|[Nn][Ee]|[Gg][TtEe]|[Ll][TtEe]|[Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee]|[Aa][Nn][Dd]|[Oo][Rr]|[Nn]?[Ee][Qq][Vv]|[Nn][Oo][Tt])\\."