Skip to content

Commit d74e786

Browse files
Marc-André Lureaugitster
Marc-André Lureau
authored andcommitted
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 <[email protected]> Signed-off-by: Marc-André Lureau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ab15ad1 commit d74e786

File tree

7 files changed

+30
-0
lines changed

7 files changed

+30
-0
lines changed

Documentation/gitattributes.txt

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

834834
- `ruby` suitable for source code in the Ruby language.
835835

836+
- `rust` suitable for source code in the Rust language.
837+
836838
- `tex` suitable for source code for LaTeX documents.
837839

838840

t/t4018-diff-funcname.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ diffpatterns="
4343
php
4444
python
4545
ruby
46+
rust
4647
tex
4748
custom1
4849
custom2

t/t4018/rust-fn

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ PATTERNS("ruby", "^[ \t]*((class|module|def)[ \t].*)$",
130130
"(@|@@|\\$)?[a-zA-Z_][a-zA-Z0-9_]*"
131131
"|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\?(\\\\C-)?(\\\\M-)?."
132132
"|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\.{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}|::"),
133140
PATTERNS("bibtex", "(@[a-zA-Z]{1,}[ \t]*\\{{0,1}[ \t]*[^ \t\"@',\\#}{~%]*).*$",
134141
"[={}\"]|[^={}\" \t]+"),
135142
PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",

0 commit comments

Comments
 (0)