Skip to content

Commit

Permalink
Add built-in diff patterns for MATLAB code
Browse files Browse the repository at this point in the history
MATLAB is often used in industry and academia for scientific
computations motivating it being included as a built-in pattern.

Signed-off-by: Gustaf Hendeby <hendeby@isy.liu.se>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Gustaf Hendeby authored and Junio C Hamano committed Nov 16, 2011
1 parent bc1bbe0 commit 53b10a1
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Documentation/gitattributes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ patterns are available:

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

- `matlab` suitable for source code in the MATLAB language.

- `objc` suitable for source code in the Objective-C language.

- `pascal` suitable for source code in the Pascal/Delphi language.
Expand Down
2 changes: 1 addition & 1 deletion t/t4018-diff-funcname.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ test_expect_funcname () {
grep "^@@.*@@ $1" diff
}

for p in bibtex cpp csharp fortran html java objc pascal perl php python ruby tex
for p in bibtex cpp csharp fortran html java matlab objc pascal perl php python ruby tex
do
test_expect_success "builtin $p pattern compiles" '
echo "*.java diff=$p" >.gitattributes &&
Expand Down
1 change: 1 addition & 0 deletions t/t4034-diff-words.sh
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ test_language_driver csharp
test_language_driver fortran
test_language_driver html
test_language_driver java
test_language_driver matlab
test_language_driver objc
test_language_driver pascal
test_language_driver perl
Expand Down
14 changes: 14 additions & 0 deletions t/t4034/matlab/expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<BOLD>diff --git a/pre b/post<RESET>
<BOLD>index dc204db..70e05f0 100644<RESET>
<BOLD>--- a/pre<RESET>
<BOLD>+++ b/post<RESET>
<CYAN>@@ -1,9 +1,9 @@<RESET>
(<RED>1<RESET><GREEN>0<RESET>) (<RED>-1e10<RESET><GREEN>-0e10<RESET>) '<RED>b<RESET><GREEN>y<RESET>';
[<RED>a<RESET><GREEN>x<RESET>] {<RED>a<RESET><GREEN>x<RESET>} <RED>a<RESET><GREEN>x<RESET>.<RED>b<RESET><GREEN>y<RESET>;
~<RED>a<RESET><GREEN>x<RESET>;
<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 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>a<RESET><GREEN>x<RESET>+<RED>b a<RESET><GREEN>y x<RESET>-<RED>b<RESET><GREEN>y<RESET>;
<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><GREEN>y<RESET>;
<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><GREEN>y<RESET>;
<RED>a<RESET><GREEN>x<RESET>==<RED>b a<RESET><GREEN>y x<RESET>~=<RED>b<RESET><GREEN>y<RESET>;
<RED>a<RESET><GREEN>x<RESET>,<RED>b<RESET><GREEN>y<RESET>;
9 changes: 9 additions & 0 deletions t/t4034/matlab/post
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(0) (-0e10) 'y';
[x] {x} x.y;
~x;
x*y x.*y x/y x./y x^y x.^y x.\y x.';
x+y x-y;
x&y x&&y x|y x||y;
x<y x<=y x>y x>=y;
x==y x~=y;
x,y;
9 changes: 9 additions & 0 deletions t/t4034/matlab/pre
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(1) (-1e10) 'b';
[a] {a} a.b;
~a;
a*b a.*b a/b a./b a^b a.^b a.\b a.';
a+b a-b;
a&b a&&b a|b a||b;
a<b a<=b a>b a>=b;
a==b a~=b;
a,b;
3 changes: 3 additions & 0 deletions userdiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ PATTERNS("java",
"|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
"|[-+*/<>%&^|=!]="
"|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
PATTERNS("matlab",
"^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
"[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
PATTERNS("objc",
/* Negate C statements that can look like functions */
"!^[ \t]*(do|for|if|else|return|switch|while)\n"
Expand Down

0 comments on commit 53b10a1

Please sign in to comment.