Skip to content

Commit 635c20e

Browse files
committed
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 an updated documentation. The xfuncname regex finds functions, structs and interfaces. The word_regex pattern finds identifiers, integers, floats, complex numbers and operators, according to the go specification. Signed-off-by: Alban Gruin <alban.gruin@gmail.com>
1 parent e3a8078 commit 635c20e

File tree

8 files changed

+37
-0
lines changed

8 files changed

+37
-0
lines changed

Documentation/gitattributes.txt

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

715715
- `fountain` suitable for Fountain documents.
716716

717+
- `golang` suitable for source code in the Go language.
718+
717719
- `html` suitable for HTML/XHTML documents.
718720

719721
- `java` suitable for source code in the Java language.

t/t4018-diff-funcname.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ diffpatterns="
3333
css
3434
fortran
3535
fountain
36+
golang
3637
html
3738
java
3839
matlab

t/t4018/golang-complex-function

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
type Test struct {
2+
a Type
3+
}
4+
5+
func (t *Test) RIGHT(a Type) (Type, error) {
6+
t.a = a
7+
return ChangeMe, nil
8+
}

t/t4018/golang-func

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
func RIGHT() {
2+
a := 5
3+
b := ChangeMe
4+
}

t/t4018/golang-interface

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
type RIGHT interface {
2+
a() Type
3+
b() ChangeMe
4+
}

t/t4018/golang-long-func

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
func RIGHT(aVeryVeryVeryLongVariableName AVeryVeryVeryLongType,
2+
anotherLongVariableName AnotherLongType) {
3+
a := 5
4+
b := ChangeMe
5+
}

t/t4018/golang-struct

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
type RIGHT struct {
2+
a Type
3+
b ChangeMe
4+
}

userdiff.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ IPATTERN("fortran",
3838
"|//|\\*\\*|::|[/<>=]="),
3939
IPATTERN("fountain", "^((\\.[^.]|(int|ext|est|int\\.?/ext|i/e)[. ]).*)$",
4040
"[^ \t-]+"),
41+
PATTERNS("golang",
42+
/* Functions */
43+
"^[ \t]*(func[ \t]*.*(\\{[ \t]*)?)\n"
44+
/* Structs and interfaces */
45+
"^[ \t]*(type[ \t].*(struct|interface)[ \t]*(\\{[ \t]*)?)",
46+
/* -- */
47+
"[a-zA-Z_][a-zA-Z0-9_]*"
48+
"|[-+0-9.eE]+i?|0[xX]?[0-9a-fA-F]+i?"
49+
"|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&\\^=?|&&|\\|\\||<-|\\.{3}"),
4150
PATTERNS("html", "^[ \t]*(<[Hh][1-6]([ \t].*)?>.*)$",
4251
"[^<>= \t]+"),
4352
PATTERNS("java",

0 commit comments

Comments
 (0)