From 53b10a140527253f61cfc209a4e85e132c0bc4ee Mon Sep 17 00:00:00 2001 From: Gustaf Hendeby Date: Tue, 15 Nov 2011 21:15:03 +0100 Subject: [PATCH] Add built-in diff patterns for MATLAB code 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 Signed-off-by: Junio C Hamano --- Documentation/gitattributes.txt | 2 ++ t/t4018-diff-funcname.sh | 2 +- t/t4034-diff-words.sh | 1 + t/t4034/matlab/expect | 14 ++++++++++++++ t/t4034/matlab/post | 9 +++++++++ t/t4034/matlab/pre | 9 +++++++++ userdiff.c | 3 +++ 7 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 t/t4034/matlab/expect create mode 100644 t/t4034/matlab/post create mode 100644 t/t4034/matlab/pre diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt index 25e46aeb7..a85b187e0 100644 --- a/Documentation/gitattributes.txt +++ b/Documentation/gitattributes.txt @@ -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. diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh index b68c56b68..4bd2a1c83 100755 --- a/t/t4018-diff-funcname.sh +++ b/t/t4018-diff-funcname.sh @@ -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 && diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh index c374aa4c1..6f1e5a2a1 100755 --- a/t/t4034-diff-words.sh +++ b/t/t4034-diff-words.sh @@ -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 diff --git a/t/t4034/matlab/expect b/t/t4034/matlab/expect new file mode 100644 index 000000000..72cf3e93a --- /dev/null +++ b/t/t4034/matlab/expect @@ -0,0 +1,14 @@ +diff --git a/pre b/post +index dc204db..70e05f0 100644 +--- a/pre ++++ b/post +@@ -1,9 +1,9 @@ +(10) (-1e10-0e10) 'by'; +[ax] {ax} ax.by; +~ax; +ax*b ay x.*b ay x/b ay x./b ay x^b ay x.^b ay x.\b ay x.'; +ax+b ay x-by; +ax&b ay x&&b ay x|b ay x||by; +ax<b ay x<=b ay x>b ay x>=by; +ax==b ay x~=by; +ax,by; diff --git a/t/t4034/matlab/post b/t/t4034/matlab/post new file mode 100644 index 000000000..70e05f075 --- /dev/null +++ b/t/t4034/matlab/post @@ -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; +xy x>=y; +x==y x~=y; +x,y; diff --git a/t/t4034/matlab/pre b/t/t4034/matlab/pre new file mode 100644 index 000000000..dc204db48 --- /dev/null +++ b/t/t4034/matlab/pre @@ -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; +ab a>=b; +a==b a~=b; +a,b; diff --git a/userdiff.c b/userdiff.c index bf553ad91..7c983c14f 100644 --- a/userdiff.c +++ b/userdiff.c @@ -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" -- 2.26.2