git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Add built-in diff patterns for MATLAB code
@ 2011-11-13 13:42 Gustaf Hendeby
  2011-11-15 12:37 ` Thomas Rast
  0 siblings, 1 reply; 5+ messages in thread
From: Gustaf Hendeby @ 2011-11-13 13:42 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano, Gustaf Hendeby

MATLAB is often used in industry and academia for scientific
computations motivating it being included as a build in pattern.

Signed-off-by: Gustaf Hendeby <hendeby@isy.liu.se>
---
 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 deletions(-)
 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 25e46ae..a85b187 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 b68c56b..4bd2a1c 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 c374aa4..6f1e5a2 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 0000000..d846ce9
--- /dev/null
+++ b/t/t4034/matlab/expect
@@ -0,0 +1,14 @@
+<BOLD>diff --git a/pre b/post<RESET>
+<BOLD>index ac2af08..0f07497 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<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 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>;
+<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>;
diff --git a/t/t4034/matlab/post b/t/t4034/matlab/post
new file mode 100644
index 0000000..0f07497
--- /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-y;
+x&y x&&y x|y x||y;
+x<y x<=y x>y 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 0000000..ac2af08
--- /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-b;
+a&b a&&b a|b a||b;
+a<b a<=b a>b a>=b;
+==b a~=b;
+a,b;
diff --git a/userdiff.c b/userdiff.c
index bf553ad..e0948e6 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"
-- 
1.7.8.rc1.222.g29897

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Add built-in diff patterns for MATLAB code
  2011-11-13 13:42 [PATCH] Add built-in diff patterns for MATLAB code Gustaf Hendeby
@ 2011-11-15 12:37 ` Thomas Rast
  2011-11-15 12:47   ` Gustaf Hendeby
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Rast @ 2011-11-15 12:37 UTC (permalink / raw)
  To: Gustaf Hendeby; +Cc: Git List, Junio C Hamano

Gustaf Hendeby wrote:
> +PATTERNS("matlab",
> +	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
> +	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\|\\||&&"),

Shouldn't you, for matlab, ensure that ./ "sticks" as a single word
since it is an operator?  At least we used the same logic for the C ||
and && operators, which you copied.

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Add built-in diff patterns for MATLAB code
  2011-11-15 12:37 ` Thomas Rast
@ 2011-11-15 12:47   ` Gustaf Hendeby
  2011-11-15 13:14     ` Thomas Rast
  0 siblings, 1 reply; 5+ messages in thread
From: Gustaf Hendeby @ 2011-11-15 12:47 UTC (permalink / raw)
  To: Thomas Rast; +Cc: Git List, Junio C Hamano

 On Tue, 15 Nov 2011 13:37:06 +0100, Thomas Rast wrote:
> Gustaf Hendeby wrote:
>> +PATTERNS("matlab",
>> +	 
>> "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
>> +	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\|\\||&&"),
>
> Shouldn't you, for matlab, ensure that ./ "sticks" as a single word
> since it is an operator?  At least we used the same logic for the C 
> ||
> and && operators, which you copied.

 Good point Thomas, I forgot all about the .-operators.  I will add 
 \.[*/^'] as words, are there any other ones to consider?  Thanks for 
 paying attention!

 /Gustaf

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Add built-in diff patterns for MATLAB code
  2011-11-15 12:47   ` Gustaf Hendeby
@ 2011-11-15 13:14     ` Thomas Rast
  2011-11-15 20:15       ` [PATCH v2] " Gustaf Hendeby
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Rast @ 2011-11-15 13:14 UTC (permalink / raw)
  To: Gustaf Hendeby; +Cc: Git List, Junio C Hamano

Gustaf Hendeby wrote:
>  On Tue, 15 Nov 2011 13:37:06 +0100, Thomas Rast wrote:
> > Gustaf Hendeby wrote:
> >> +PATTERNS("matlab",
> >> +	 
> >> "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
> >> +	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\|\\||&&"),
> >
> > Shouldn't you, for matlab, ensure that ./ "sticks" as a single word
> > since it is an operator?  At least we used the same logic for the C 
> > ||
> > and && operators, which you copied.
> 
>  Good point Thomas, I forgot all about the .-operators.  I will add 
>  \.[*/^'] as words, are there any other ones to consider?  Thanks for 
>  paying attention!

Uh, I'm afraid it's been years since I did matlab.  But

  http://www.mathworks.ch/help/techdoc/matlab_prog/f0-40063.html

seems to indicate you forgot '.\'.

Please also update the testcases to whether this splits correctly,
e.g., by changing './' to '/'.

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] Add built-in diff patterns for MATLAB code
  2011-11-15 13:14     ` Thomas Rast
@ 2011-11-15 20:15       ` Gustaf Hendeby
  0 siblings, 0 replies; 5+ messages in thread
From: Gustaf Hendeby @ 2011-11-15 20:15 UTC (permalink / raw)
  To: Thomas Rast; +Cc: Git List, Junio C Hamano, Gustaf Hendeby

MATLAB is often used in industry and academia for scientific
computations motivating it being included as a build in pattern.

Signed-off-by: Gustaf Hendeby <hendeby@isy.liu.se>
---

This version of this commit adds the missing patterns to make the
.-operators words and adds these to the test.  Lots of thanks Thomas
for keeping your eyes open and catching this.

/Gustaf

 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 deletions(-)
 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 25e46ae..a85b187 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 b68c56b..4bd2a1c 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 c374aa4..6f1e5a2 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 0000000..72cf3e9
--- /dev/null
+++ b/t/t4034/matlab/expect
@@ -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>;
diff --git a/t/t4034/matlab/post b/t/t4034/matlab/post
new file mode 100644
index 0000000..70e05f0
--- /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;
+x<y x<=y x>y 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 0000000..dc204db
--- /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;
+a<b a<=b a>b a>=b;
+a==b a~=b;
+a,b;
diff --git a/userdiff.c b/userdiff.c
index bf553ad..7c983c1 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"
-- 
1.7.8.rc2.209.geddc4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-11-15 20:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-13 13:42 [PATCH] Add built-in diff patterns for MATLAB code Gustaf Hendeby
2011-11-15 12:37 ` Thomas Rast
2011-11-15 12:47   ` Gustaf Hendeby
2011-11-15 13:14     ` Thomas Rast
2011-11-15 20:15       ` [PATCH v2] " Gustaf Hendeby

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).