userdiff: add builtin diff driver for kotlin language.
The xfuncname pattern finds func/class declarations in diffs to display as a hunk header. The word_regex pattern finds individual tokens in Kotlin code to generate appropriate diffs. This patch adds xfuncname regex and word_regex for Kotlin language. Signed-off-by: Jaydeep P Das <jaydeepjd.8914@gmail.com> Acked-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jaydeep P Das committed
Mar 12, 2022 at 10:18 UTC
09188ed930bcb08e56d1846fbf9f5cb972a2d188
15 files changed
+167
Documentation/gitattributes.txt
+2
@@ -829,6 +829,8 @@ patterns are available:
829
830
- `java` suitable for source code in the Java language.
831
832
+- `kotlin` suitable for source code in the Kotlin language.
833
+
834
- `markdown` suitable for Markdown documents.
835
836
- `matlab` suitable for source code in the MATLAB and Octave languages.
t/t4018/kotlin-class
new
+5
@@ -0,0 +1,5 @@
1
+class RIGHT {
2
+ //comment
3
+ //comment
4
+ return ChangeMe
5
+}
t/t4018/kotlin-enum-class
new
+5
@@ -0,0 +1,5 @@
1
+enum class RIGHT{
2
+ // Left
3
+ // a comment
4
+ ChangeMe
5
+}
t/t4018/kotlin-fun
new
+5
@@ -0,0 +1,5 @@
1
+fun RIGHT(){
2
+ //a comment
3
+ //b comment
4
+ return ChangeMe()
5
+}
t/t4018/kotlin-inheritace-class
new
+5
@@ -0,0 +1,5 @@
1
+open class RIGHT{
2
+ // a comment
3
+ // b comment
4
+ // ChangeMe
5
+}
t/t4018/kotlin-inline-class
new
+5
@@ -0,0 +1,5 @@
1
+value class RIGHT(Args){
2
+ // a comment
3
+ // b comment
4
+ ChangeMe
5
+}
t/t4018/kotlin-interface
new
+5
@@ -0,0 +1,5 @@
1
+interface RIGHT{
2
+ //another comment
3
+ //another comment
4
+ //ChangeMe
5
+}
t/t4018/kotlin-nested-fun
new
+9
@@ -0,0 +1,9 @@
1
+class LEFT{
2
+ class CENTER{
3
+ fun RIGHT( a:Int){
4
+ //comment
5
+ //comment
6
+ ChangeMe
7
+ }
8
+ }
9
+}
t/t4018/kotlin-public-class
new
+5
@@ -0,0 +1,5 @@
1
+public class RIGHT{
2
+ //comment1
3
+ //comment2
4
+ ChangeMe
5
+}
t/t4018/kotlin-sealed-class
new
+5
@@ -0,0 +1,5 @@
1
+sealed class RIGHT {
2
+ // a comment
3
+ // b comment
4
+ ChangeMe
5
+}
t/t4034-diff-words.sh
+1
@@ -324,6 +324,7 @@ test_language_driver dts
324
test_language_driver fortran
325
test_language_driver html
326
test_language_driver java
327
+test_language_driver kotlin
328
test_language_driver matlab
329
test_language_driver objc
330
test_language_driver pascal
t/t4034/kotlin/expect
new
+43
@@ -0,0 +1,43 @@
1
+<BOLD>diff --git a/pre b/post<RESET>
2
+<BOLD>index 11ea3de..2e1df4c 100644<RESET>
3
+<BOLD>--- a/pre<RESET>
4
+<BOLD>+++ b/post<RESET>
5
+<CYAN>@@ -1,30 +1,30 @@<RESET>
6
+println("Hello World<RED>!\n<RESET><GREEN>?<RESET>")
7
+<GREEN>(<RESET>1<GREEN>) (<RESET>-1e10<GREEN>) (<RESET>0xabcdef<GREEN>)<RESET> '<RED>x<RESET><GREEN>y<RESET>'
8
+[<RED>a<RESET><GREEN>x<RESET>] <RED>a<RESET><GREEN>x<RESET>-><RED>b a<RESET><GREEN>y x<RESET>.<RED>b<RESET><GREEN>y<RESET>
9
+!<RED>a a<RESET><GREEN>x x<RESET>.inv() <RED>a<RESET><GREEN>x<RESET>*<RED>b a<RESET><GREEN>y x<RESET>&<RED>b<RESET>
10
+<RED>a<RESET><GREEN>y<RESET>
11
+<GREEN>x<RESET>*<RED>b a<RESET><GREEN>y x<RESET>/<RED>b a<RESET><GREEN>y x<RESET>%<RED>b<RESET>
12
+<RED>a<RESET><GREEN>y<RESET>
13
+<GREEN>x<RESET>+<RED>b a<RESET><GREEN>y x<RESET>-<RED>b<RESET><GREEN>y<RESET>
14
+a <RED>shr<RESET><GREEN>shl<RESET> b
15
+<RED>a<RESET><GREEN>x<RESET><<RED>b a<RESET><GREEN>y x<RESET><=<RED>b a<RESET><GREEN>y x<RESET>><RED>b a<RESET><GREEN>y x<RESET>>=<RED>b<RESET>
16
+<RED>a<RESET><GREEN>y<RESET>
17
+<GREEN>x<RESET>==<RED>b a<RESET><GREEN>y x<RESET>!=<RED>b a<RESET><GREEN>y x<RESET>===<RED>b<RESET>
18
+<RED>a<RESET><GREEN>y<RESET>
19
+<GREEN>x<RESET> and <RED>b<RESET>
20
+<RED>a<RESET><GREEN>y<RESET>
21
+<GREEN>x<RESET>^<RED>b<RESET>
22
+<RED>a<RESET><GREEN>y<RESET>
23
+<GREEN>x<RESET> or <RED>b<RESET>
24
+<RED>a<RESET><GREEN>y<RESET>
25
+<GREEN>x<RESET>&&<RED>b a<RESET><GREEN>y x<RESET>||<RED>b<RESET>
26
+<RED>a<RESET><GREEN>y<RESET>
27
+<GREEN>x<RESET>=<RED>b a<RESET><GREEN>y x<RESET>+=<RED>b a<RESET><GREEN>y x<RESET>-=<RED>b a<RESET><GREEN>y x<RESET>*=<RED>b a<RESET><GREEN>y x<RESET>/=<RED>b a<RESET><GREEN>y x<RESET>%=<RED>b a<RESET><GREEN>y x<RESET><<=<RED>b a<RESET><GREEN>y x<RESET>>>=<RED>b a<RESET><GREEN>y x<RESET>&=<RED>b a<RESET><GREEN>y x<RESET>^=<RED>b a<RESET><GREEN>y x<RESET>|=<RED>b<RESET><GREEN>y<RESET>
28
+a<RED>=<RESET><GREEN>+=<RESET>b c<RED>+=<RESET><GREEN>=<RESET>d e<RED>-=<RESET><GREEN><=<RESET>f g<RED>*=<RESET><GREEN>>=<RESET>h i<RED>/=<RESET><GREEN>/<RESET>j k<RED>%=<RESET><GREEN>%<RESET>l m<RED><<=<RESET><GREEN><<<RESET>n o<RED>>>=<RESET><GREEN>>><RESET>p q<RED>&=<RESET><GREEN>&<RESET>r s<RED>^=<RESET><GREEN>^<RESET>t u<RED>|=<RESET><GREEN>|<RESET>v
29
+a<RED><<=<RESET><GREEN><=<RESET>b
30
+a<RED>||<RESET><GREEN>|<RESET>b a<RED>&&<RESET><GREEN>&<RESET>b
31
+<RED>a<RESET><GREEN>x<RESET>,y
32
+--a<RED>==<RESET><GREEN>!=<RESET>--b
33
+a++<RED>==<RESET><GREEN>!=<RESET>++b
34
+<RED>0xFF_EC_DE_5E 0b100_000 100_000<RESET><GREEN>0xFF_E1_DE_5E 0b100_100 200_000<RESET>
35
+a<RED>==<RESET><GREEN>===<RESET>b
36
+a<RED>!!<RESET><GREEN>!=<RESET>b
37
+<RED>_32<RESET><GREEN>_33<RESET>.find(arr)
38
+X.<RED>fill<RESET><GREEN>find<RESET>()
39
+X.<RED>u<RESET><GREEN>f<RESET>+1
40
+X.u<RED>-<RESET><GREEN>+<RESET>2
41
+a<RED>.<RESET><GREEN>..<RESET>b
42
+a<RED>?.<RESET><GREEN>?:<RESET>b
43
+<RED>.32_00_456<RESET><GREEN>.32_00_446<RESET>
t/t4034/kotlin/post
new
+30
@@ -0,0 +1,30 @@
1
+println("Hello World?")
2
+(1) (-1e10) (0xabcdef) 'y'
3
+[x] x->y x.y
4
+!x x.inv() x*y x&y
5
+x*y x/y x%y
6
+x+y x-y
7
+a shl b
8
+x<y x<=y x>y x>=y
9
+x==y x!=y x===y
10
+x and y
11
+x^y
12
+x or y
13
+x&&y x||y
14
+x=y x+=y x-=y x*=y x/=y x%=y x<<=y x>>=y x&=y x^=y x|=y
15
+a+=b c=d e<=f g>=h i/j k%l m<<n o>>p q&r s^t u|v
16
+a<=b
17
+a|b a&b
18
+x,y
19
+--a!=--b
20
+a++!=++b
21
+0xFF_E1_DE_5E 0b100_100 200_000
22
+a===b
23
+a!=b
24
+_33.find(arr)
25
+X.find()
26
+X.f+1
27
+X.u+2
28
+a..b
29
+a?:b
30
+.32_00_446
t/t4034/kotlin/pre
new
+30
@@ -0,0 +1,30 @@
1
+println("Hello World!\n")
2
+1 -1e10 0xabcdef 'x'
3
+[a] a->b a.b
4
+!a a.inv() a*b a&b
5
+a*b a/b a%b
6
+a+b a-b
7
+a shr b
8
+a<b a<=b a>b a>=b
9
+a==b a!=b a===b
10
+a and b
11
+a^b
12
+a or b
13
+a&&b a||b
14
+a=b a+=b a-=b a*=b a/=b a%=b a<<=b a>>=b a&=b a^=b a|=b
15
+a=b c+=d e-=f g*=h i/=j k%=l m<<=n o>>=p q&=r s^=t u|=v
16
+a<<=b
17
+a||b a&&b
18
+a,y
19
+--a==--b
20
+a++==++b
21
+0xFF_EC_DE_5E 0b100_000 100_000
22
+a==b
23
+a!!b
24
+_32.find(arr)
25
+X.fill()
26
+X.u+1
27
+X.u-2
28
+a.b
29
+a?.b
30
+.32_00_456
userdiff.c
+12
@@ -168,6 +168,18 @@ PATTERNS("java",
168
"|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
169
"|[-+*/<>%&^|=!]="
170
"|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
171
+PATTERNS("kotlin",
172
+ "^[ \t]*(([a-z]+[ \t]+)*(fun|class|interface)[ \t]+.*)$",
173
+ /* -- */
174
+ "[a-zA-Z_][a-zA-Z0-9_]*"
175
+ /* hexadecimal and binary numbers */
176
+ "|0[xXbB][0-9a-fA-F_]+[lLuU]*"
177
+ /* integers and floats */
178
+ "|[0-9][0-9_]*([.][0-9_]*)?([Ee][-+]?[0-9]+)?[fFlLuU]*"
179
+ /* floating point numbers beginning with decimal point */
180
+ "|[.][0-9][0-9_]*([Ee][-+]?[0-9]+)?[fFlLuU]?"
181
+ /* unary and binary operators */
182
+ "|[-+*/<>%&^|=!]==?|--|\\+\\+|<<=|>>=|&&|\\|\\||->|\\.\\*|!!|[?:.][.:]"),
183
PATTERNS("markdown",
184
"^ {0,3}#{1,6}[ \t].*",
185
/* -- */