userdiff: add built-in pattern for rust
This adds xfuncname and word_regex patterns for Rust, a quite popular programming language. It also includes test cases for the xfuncname regex (t4018) and updated documentation. The word_regex pattern finds identifiers, integers, floats and operators, according to the Rust Reference Book. Cc: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Marc-André Lureau committed
May 17, 2019 at 01:58 UTC
d74e78602e3d562f5db64d553d4be21c201ef7b3
7 files changed
+30
Documentation/gitattributes.txt
+2
@@ -833,6 +833,8 @@ patterns are available:
833
834
- `ruby` suitable for source code in the Ruby language.
835
836
+- `rust` suitable for source code in the Rust language.
837
+
838
- `tex` suitable for source code for LaTeX documents.
839
840
t/t4018-diff-funcname.sh
+1
@@ -43,6 +43,7 @@ diffpatterns="
43
php
44
python
45
ruby
46
+ rust
47
tex
48
custom1
49
custom2
t/t4018/rust-fn
new
+5
@@ -0,0 +1,5 @@
1
+pub(self) fn RIGHT<T>(x: &[T]) where T: Debug {
2
+ let _ = x;
3
+ // a comment
4
+ let a = ChangeMe;
5
+}
t/t4018/rust-impl
new
+5
@@ -0,0 +1,5 @@
1
+impl<'a, T: AsRef<[u8]>> std::RIGHT for Git<'a> {
2
+
3
+ pub fn ChangeMe(&self) -> () {
4
+ }
5
+}
t/t4018/rust-struct
new
+5
@@ -0,0 +1,5 @@
1
+#[derive(Debug)]
2
+pub(super) struct RIGHT<'a> {
3
+ name: &'a str,
4
+ age: ChangeMe,
5
+}
t/t4018/rust-trait
new
+5
@@ -0,0 +1,5 @@
1
+unsafe trait RIGHT<T> {
2
+ fn len(&self) -> u32;
3
+ fn ChangeMe(&self, n: u32) -> T;
4
+ fn iter<F>(&self, f: F) where F: Fn(T);
5
+}
userdiff.c
+7
@@ -130,6 +130,13 @@ PATTERNS("ruby", "^[ \t]*((class|module|def)[ \t].*)$",
130
"(@|@@|\\$)?[a-zA-Z_][a-zA-Z0-9_]*"
131
"|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\?(\\\\C-)?(\\\\M-)?."
132
"|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\.{1,3}|::|[!=]~"),
133
+PATTERNS("rust",
134
+ "^[\t ]*((pub(\\([^\\)]+\\))?[\t ]+)?((async|const|unsafe|extern([\t ]+\"[^\"]+\"))[\t ]+)?(struct|enum|union|mod|trait|fn|impl(<.+>)?)[ \t]+[^;]*)$",
135
+ /* -- */
136
+ "[a-zA-Z_][a-zA-Z0-9_]*"
137
+ "|[-+_0-9.eE]+(f32|f64|u8|u16|u32|u64|u128|usize|i8|i16|i32|i64|i128|isize)?"
138
+ "|0[box]?[0-9a-fA-F_]+(u8|u16|u32|u64|u128|usize|i8|i16|i32|i64|i128|isize)?"
139
+ "|[-+*\\/<>%&^|=!:]=|<<=?|>>=?|&&|\\|\\||->|=>|\\.{2}=|\\.{3}|::"),
140
PATTERNS("bibtex", "(@[a-zA-Z]{1,}[ \t]*\\{{0,1}[ \t]*[^ \t\"@',\\#}{~%]*).*$",
141
"[={}\"]|[^={}\" \t]+"),
142
PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",