path: root/userdiff.c
diff options
authorAlban Gruin <>2018-03-01 11:19:07 (GMT)
committerJunio C Hamano <>2018-03-01 21:36:49 (GMT)
commit1dbf0c0ad6cabfc35aa1896b4d94f4ee811ba803 (patch)
treeb987310dcd5bda9990ccb1c76dcd327a494048c1 /userdiff.c
parent7e31236f652ad9db221511eaf157ce0ef55585d6 (diff)
userdiff: add built-in pattern for golang
This adds xfuncname and word_regex patterns for golang, a quite popular programming language. It also includes test cases for the xfuncname regex (t4018) and updated documentation. The xfuncname regex finds functions, structs and interfaces. Although the Go language prohibits the opening brace from being on its own line, the regex does not makes it mandatory, to be able to match `func` statements like this: func foo(bar int, baz int) { } This is covered by the test case t4018/golang-long-func. The word_regex pattern finds identifiers, integers, floats, complex numbers and operators, according to the go specification. Signed-off-by: Alban Gruin <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'userdiff.c')
1 files changed, 9 insertions, 0 deletions
diff --git a/userdiff.c b/userdiff.c
index dbfb4e1..8f5028f 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -38,6 +38,15 @@ IPATTERN("fortran",
IPATTERN("fountain", "^((\\.[^.]|(int|ext|est|int\\.?/ext|i/e)[. ]).*)$",
"[^ \t-]+"),
+ /* Functions */
+ "^[ \t]*(func[ \t]*.*(\\{[ \t]*)?)\n"
+ /* Structs and interfaces */
+ "^[ \t]*(type[ \t].*(struct|interface)[ \t]*(\\{[ \t]*)?)",
+ /* -- */
+ "[a-zA-Z_][a-zA-Z0-9_]*"
+ "|[-+0-9.eE]+i?|0[xX]?[0-9a-fA-F]+i?"
+ "|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&\\^=?|&&|\\|\\||<-|\\.{3}"),
PATTERNS("html", "^[ \t]*(<[Hh][1-6]([ \t].*)?>.*)$",
"[^<>= \t]+"),