summaryrefslogtreecommitdiff
path: root/userdiff.c
diff options
context:
space:
mode:
authorVictor Engmark <victor@engmark.name>2020-10-21 23:45:08 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-10-22 17:29:30 (GMT)
commit2ff6c34612057baccbd841524106c5a05f6be6d6 (patch)
tree74d41a027c7ecc6297cc8553658006234cb93b44 /userdiff.c
parent69986e19ffcfb9af674ae5180689ab7bbf92ed28 (diff)
downloadgit-2ff6c34612057baccbd841524106c5a05f6be6d6.zip
git-2ff6c34612057baccbd841524106c5a05f6be6d6.tar.gz
git-2ff6c34612057baccbd841524106c5a05f6be6d6.tar.bz2
userdiff: support Bash
Support POSIX, bashism and mixed function declarations, all four compound command types, trailing comments and mixed whitespace. Even though Bash allows locale-dependent characters in function names <https://unix.stackexchange.com/a/245336/3645>, only detect function names with characters allowed by POSIX.1-2017 <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_235> for simplicity. This should cover the vast majority of use cases, and produces system-agnostic results. Since a word pattern has to be specified, but there is no easy way to know the default word pattern, use the default `IFS` characters for a starter. A later patch can improve this. Signed-off-by: Victor Engmark <victor@engmark.name> Acked-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'userdiff.c')
-rw-r--r--userdiff.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/userdiff.c b/userdiff.c
index fde02f2..eb698ea 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -23,6 +23,27 @@ IPATTERN("ada",
"[a-zA-Z][a-zA-Z0-9_]*"
"|[-+]?[0-9][0-9#_.aAbBcCdDeEfF]*([eE][+-]?[0-9_]+)?"
"|=>|\\.\\.|\\*\\*|:=|/=|>=|<=|<<|>>|<>"),
+PATTERNS("bash",
+ /* Optional leading indentation */
+ "^[ \t]*"
+ /* Start of captured text */
+ "("
+ "("
+ /* POSIX identifier with mandatory parentheses */
+ "[a-zA-Z_][a-zA-Z0-9_]*[ \t]*\\([ \t]*\\))"
+ "|"
+ /* Bashism identifier with optional parentheses */
+ "(function[ \t]+[a-zA-Z_][a-zA-Z0-9_]*(([ \t]*\\([ \t]*\\))|([ \t]+))"
+ ")"
+ /* Optional whitespace */
+ "[ \t]*"
+ /* Compound command starting with `{`, `(`, `((` or `[[` */
+ "(\\{|\\(\\(?|\\[\\[)"
+ /* End of captured text */
+ ")",
+ /* -- */
+ /* Characters not in the default $IFS value */
+ "[^ \t]+"),
PATTERNS("dts",
"!;\n"
"!=\n"