mirror of
https://github.com/git/git.git
synced 2024-05-07 05:46:08 +02:00
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 <alban.gruin@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
7e31236f65
commit
1dbf0c0ad6
|
@ -714,6 +714,8 @@ patterns are available:
|
|||
|
||||
- `fountain` suitable for Fountain documents.
|
||||
|
||||
- `golang` suitable for source code in the Go language.
|
||||
|
||||
- `html` suitable for HTML/XHTML documents.
|
||||
|
||||
- `java` suitable for source code in the Java language.
|
||||
|
|
|
@ -33,6 +33,7 @@ diffpatterns="
|
|||
css
|
||||
fortran
|
||||
fountain
|
||||
golang
|
||||
html
|
||||
java
|
||||
matlab
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
type Test struct {
|
||||
a Type
|
||||
}
|
||||
|
||||
func (t *Test) RIGHT(a Type) (Type, error) {
|
||||
t.a = a
|
||||
return ChangeMe, nil
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
func RIGHT() {
|
||||
a := 5
|
||||
b := ChangeMe
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
type RIGHT interface {
|
||||
a() Type
|
||||
b() ChangeMe
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
func RIGHT(aVeryVeryVeryLongVariableName AVeryVeryVeryLongType,
|
||||
anotherLongVariableName AnotherLongType) {
|
||||
a := 5
|
||||
b := ChangeMe
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
type RIGHT struct {
|
||||
a Type
|
||||
b ChangeMe
|
||||
}
|
|
@ -38,6 +38,15 @@ IPATTERN("fortran",
|
|||
"|//|\\*\\*|::|[/<>=]="),
|
||||
IPATTERN("fountain", "^((\\.[^.]|(int|ext|est|int\\.?/ext|i/e)[. ]).*)$",
|
||||
"[^ \t-]+"),
|
||||
PATTERNS("golang",
|
||||
/* 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]+"),
|
||||
PATTERNS("java",
|
||||
|
|
Loading…
Reference in New Issue