All of lore.kernel.org
 help / color / mirror / Atom feed
* [GSoC][PATCH] userdiff: funcname and word patterns for sh
@ 2015-03-09 16:36 Adrien Schildknecht
  2015-03-09 16:36 ` [PATCH] " Adrien Schildknecht
  0 siblings, 1 reply; 7+ messages in thread
From: Adrien Schildknecht @ 2015-03-09 16:36 UTC (permalink / raw)
  To: git; +Cc: Adrien Schildknecht

Hi,
I'm a french student from EPITA and I plan to apply for the GSoC.

Adrien Schildknecht (1):
  userdiff: funcname and word patterns for sh

 Documentation/gitattributes.txt |  2 ++
 t/t4018-diff-funcname.sh        |  1 +
 t/t4018/sh-function             |  4 ++++
 t/t4018/sh-function-comment     |  6 ++++++
 t/t4018/sh-function-nested      |  7 +++++++
 t/t4018/sh-function-prefix      |  4 ++++
 t/t4018/sh-function-string      |  4 ++++
 t/t4034-diff-words.sh           |  1 +
 t/t4034/sh/expect               | 46 +++++++++++++++++++++++++++++++++++++++++
 t/t4034/sh/post                 | 36 ++++++++++++++++++++++++++++++++
 t/t4034/sh/pre                  | 36 ++++++++++++++++++++++++++++++++
 userdiff.c                      |  7 +++++++
 12 files changed, 154 insertions(+)
 create mode 100644 t/t4018/sh-function
 create mode 100644 t/t4018/sh-function-comment
 create mode 100644 t/t4018/sh-function-nested
 create mode 100644 t/t4018/sh-function-prefix
 create mode 100644 t/t4018/sh-function-string
 create mode 100644 t/t4034/sh/expect
 create mode 100644 t/t4034/sh/post
 create mode 100644 t/t4034/sh/pre

-- 
Adrien Schildknecht
http://schischi.me

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

* [PATCH] userdiff: funcname and word patterns for sh
  2015-03-09 16:36 [GSoC][PATCH] userdiff: funcname and word patterns for sh Adrien Schildknecht
@ 2015-03-09 16:36 ` Adrien Schildknecht
  2015-03-09 20:34   ` Matthieu Moy
  2015-03-09 23:40   ` [PATCH v2] " Adrien Schildknecht
  0 siblings, 2 replies; 7+ messages in thread
From: Adrien Schildknecht @ 2015-03-09 16:36 UTC (permalink / raw)
  To: git; +Cc: Adrien Schildknecht

Add regexp based on the "Shell Command Language" specifications.
Because of the lax syntax of sh, some corner cases may not be
handled properly.

Signed-off-by: Adrien Schildknecht <adrien+dev@schischi.me>
---
 Documentation/gitattributes.txt |  2 ++
 t/t4018-diff-funcname.sh        |  1 +
 t/t4018/sh-function             |  4 ++++
 t/t4018/sh-function-comment     |  6 ++++++
 t/t4018/sh-function-nested      |  7 +++++++
 t/t4018/sh-function-prefix      |  4 ++++
 t/t4018/sh-function-string      |  4 ++++
 t/t4034-diff-words.sh           |  1 +
 t/t4034/sh/expect               | 46 +++++++++++++++++++++++++++++++++++++++++
 t/t4034/sh/post                 | 36 ++++++++++++++++++++++++++++++++
 t/t4034/sh/pre                  | 36 ++++++++++++++++++++++++++++++++
 userdiff.c                      |  7 +++++++
 12 files changed, 154 insertions(+)
 create mode 100644 t/t4018/sh-function
 create mode 100644 t/t4018/sh-function-comment
 create mode 100644 t/t4018/sh-function-nested
 create mode 100644 t/t4018/sh-function-prefix
 create mode 100644 t/t4018/sh-function-string
 create mode 100644 t/t4034/sh/expect
 create mode 100644 t/t4034/sh/post
 create mode 100644 t/t4034/sh/pre

diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index c892ffa..fb13761 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -545,6 +545,8 @@ patterns are available:
 
 - `ruby` suitable for source code in the Ruby language.
 
+- `sh` suitable for source code in the Shell language.
+
 - `tex` suitable for source code for LaTeX documents.
 
 
diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
index 1dbaa38..960b6e4 100755
--- a/t/t4018-diff-funcname.sh
+++ b/t/t4018-diff-funcname.sh
@@ -40,6 +40,7 @@ diffpatterns="
 	php
 	python
 	ruby
+	sh
 	tex
 	custom1
 	custom2
diff --git a/t/t4018/sh-function b/t/t4018/sh-function
new file mode 100644
index 0000000..1d5096a
--- /dev/null
+++ b/t/t4018/sh-function
@@ -0,0 +1,4 @@
+RIGHT_foo()
+{
+	ChangeMe;
+}
diff --git a/t/t4018/sh-function-comment b/t/t4018/sh-function-comment
new file mode 100644
index 0000000..f340ee7
--- /dev/null
+++ b/t/t4018/sh-function-comment
@@ -0,0 +1,6 @@
+  RIGHT_foo() # echo 'foo'
+#bar()
+{
+	#bar()
+	ChangeMe;
+}
diff --git a/t/t4018/sh-function-nested b/t/t4018/sh-function-nested
new file mode 100644
index 0000000..d3263f3
--- /dev/null
+++ b/t/t4018/sh-function-nested
@@ -0,0 +1,7 @@
+foo (     )
+{
+	RIGHT_bar()
+	{
+		echo ChangeMe
+	}
+}
diff --git a/t/t4018/sh-function-prefix b/t/t4018/sh-function-prefix
new file mode 100644
index 0000000..e96eb7a
--- /dev/null
+++ b/t/t4018/sh-function-prefix
@@ -0,0 +1,4 @@
+function RIGHT_foo()
+{
+	ChangeMe;
+}
diff --git a/t/t4018/sh-function-string b/t/t4018/sh-function-string
new file mode 100644
index 0000000..f60a899
--- /dev/null
+++ b/t/t4018/sh-function-string
@@ -0,0 +1,4 @@
+RIGHT_foo() {
+	echo "bar()"
+	ChangeMe;
+}
diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh
index f2f55fc..24fd9aa 100755
--- a/t/t4034-diff-words.sh
+++ b/t/t4034-diff-words.sh
@@ -312,6 +312,7 @@ test_language_driver perl
 test_language_driver php
 test_language_driver python
 test_language_driver ruby
+test_language_driver sh
 test_language_driver tex
 
 test_expect_success 'word-diff with diff.sbe' '
diff --git a/t/t4034/sh/expect b/t/t4034/sh/expect
new file mode 100644
index 0000000..1c6de2d
--- /dev/null
+++ b/t/t4034/sh/expect
@@ -0,0 +1,46 @@
+<BOLD>diff --git a/pre b/post<RESET>
+<BOLD>index 20229c3..ab791db 100644<RESET>
+<BOLD>--- a/pre<RESET>
+<BOLD>+++ b/post<RESET>
+<CYAN>@@ -1,36 +1,36 @@<RESET>
+foo() {ls&echo}<RESET>
+$((<RED>a<RESET><GREEN>x<RESET>++))
+$((<RED>a<RESET><GREEN>x<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>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>**<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>/<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>%<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>+<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>-<RED>b<RESET><GREEN>y<RESET>))
+[ <RED>a<RESET><GREEN>x<RESET><=<RED>b<RESET><GREEN>y<RESET> ]
+[ <RED>a<RESET><GREEN>x<RESET>>=<RED>b<RESET><GREEN>y<RESET> ]
+[ <RED>a<RESET><GREEN>x<RESET>==<RED>b<RESET><GREEN>y<RESET> ]
+[ <RED>a<RESET><GREEN>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 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>
+<RED>a<RESET><GREEN>y<RESET>
+<GREEN>x<RESET>&<RED>b<RESET>
+<RED>a<RESET><GREEN>y<RESET>
+<GREEN>x<RESET>&&<RED>b<RESET>
+<RED>a<RESET><GREEN>y<RESET>
+<GREEN>x<RESET>|<RED>b<RESET>
+<RED>a<RESET><GREEN>y<RESET>
+<GREEN>x<RESET>||<RED>b<RESET>
+<RED>a<RESET><GREEN>y<RESET>
+<GREEN>x<RESET>=<RED>b<RESET><GREEN>y<RESET>
+$((<RED>a<RESET><GREEN>x<RESET>+=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>-=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>*=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>/=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>%=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET><<=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>>>=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>&=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>^=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>|=<RED>b<RESET><GREEN>y<RESET>))
+*)<RED>a<RESET><GREEN>b<RESET>;;ls
+FOO=42&<RED>foo<RESET><GREEN>fro<RESET>
+BAR=$(0)<RESET>
+[[ $<RED>a<RESET><GREEN>x<RESET> -eq $<RED>b<RESET><GREEN>y<RESET> ]]
diff --git a/t/t4034/sh/post b/t/t4034/sh/post
new file mode 100644
index 0000000..ab791db
--- /dev/null
+++ b/t/t4034/sh/post
@@ -0,0 +1,36 @@
+foo() {ls&echo}
+$((x++))
+$((x--))
+$((--x))
+$((++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 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))
+*)b;;ls
+FOO=42&fro
+BAR=$(0)
+[[ $x -eq $y ]]
diff --git a/t/t4034/sh/pre b/t/t4034/sh/pre
new file mode 100644
index 0000000..20229c3
--- /dev/null
+++ b/t/t4034/sh/pre
@@ -0,0 +1,36 @@
+foo() {ls&echo}
+$((a++))
+$((a--))
+$((--a))
+$((++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 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))
+$((a&=b))
+$((a^=b))
+$((a|=b))
+*)a;;ls
+FOO=42&foo
+BAR=$(0)
+[[ $a -eq $b ]]
diff --git a/userdiff.c b/userdiff.c
index 2ccbee5..40b3dc0 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -146,6 +146,13 @@ PATTERNS("csharp",
 	 "[a-zA-Z_][a-zA-Z0-9_]*"
 	 "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
 	 "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
+PATTERNS("sh",
+	"^([ \t]*(function[ \t]*)?[a-zA-Z_][a-zA-Z0-9_]*[ \t]*\\([ \t]*\\).*)$",
+	/* -- */
+	 "[a-zA-Z0-9_]+"
+	 "|[-+0-9]+"
+	 "|[-+*/<>%&^|=!]=|>>=?|<<=?|\\+\\+|--|\\*\\*|&&|\\|\\||\\[\\[|\\]\\]"
+	 "|>\\||[<>]+&|<>|<<-|;;"),
 { "default", NULL, -1, { NULL, 0 } },
 };
 #undef PATTERNS
-- 
Adrien Schildknecht
http://schischi.me

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

* Re: [PATCH] userdiff: funcname and word patterns for sh
  2015-03-09 16:36 ` [PATCH] " Adrien Schildknecht
@ 2015-03-09 20:34   ` Matthieu Moy
  2015-03-09 23:40   ` [PATCH v2] " Adrien Schildknecht
  1 sibling, 0 replies; 7+ messages in thread
From: Matthieu Moy @ 2015-03-09 20:34 UTC (permalink / raw)
  To: Adrien Schildknecht; +Cc: git

Adrien Schildknecht <adrien+dev@schischi.me> writes:

> +	"^([ \t]*(function[ \t]*)?[a-zA-Z_][a-zA-Z0-9_]*[ \t]*\\([ \t]*\\).*)$",

I guess this should be 'function[ \t]+' (+, not *).

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

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

* [PATCH v2] userdiff: funcname and word patterns for sh
  2015-03-09 16:36 ` [PATCH] " Adrien Schildknecht
  2015-03-09 20:34   ` Matthieu Moy
@ 2015-03-09 23:40   ` Adrien Schildknecht
  2015-03-14  5:13     ` Junio C Hamano
                       ` (2 more replies)
  1 sibling, 3 replies; 7+ messages in thread
From: Adrien Schildknecht @ 2015-03-09 23:40 UTC (permalink / raw)
  To: git; +Cc: Matthieu.Moy, Adrien Schildknecht

Add regexp based on the "Shell Command Language" specifications.
Because of the lax syntax of sh, some corner cases may not be
handled properly.

Signed-off-by: Adrien Schildknecht <adrien+dev@schischi.me>
---
 Documentation/gitattributes.txt |  2 ++
 t/t4018-diff-funcname.sh        |  1 +
 t/t4018/sh-function             |  4 ++++
 t/t4018/sh-function-comment     |  6 ++++++
 t/t4018/sh-function-nested      |  7 +++++++
 t/t4018/sh-function-prefix      |  4 ++++
 t/t4018/sh-function-string      |  4 ++++
 t/t4034-diff-words.sh           |  1 +
 t/t4034/sh/expect               | 46 +++++++++++++++++++++++++++++++++++++++++
 t/t4034/sh/post                 | 36 ++++++++++++++++++++++++++++++++
 t/t4034/sh/pre                  | 36 ++++++++++++++++++++++++++++++++
 userdiff.c                      |  7 +++++++
 12 files changed, 154 insertions(+)
 create mode 100644 t/t4018/sh-function
 create mode 100644 t/t4018/sh-function-comment
 create mode 100644 t/t4018/sh-function-nested
 create mode 100644 t/t4018/sh-function-prefix
 create mode 100644 t/t4018/sh-function-string
 create mode 100644 t/t4034/sh/expect
 create mode 100644 t/t4034/sh/post
 create mode 100644 t/t4034/sh/pre

diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index c892ffa..fb13761 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -545,6 +545,8 @@ patterns are available:
 
 - `ruby` suitable for source code in the Ruby language.
 
+- `sh` suitable for source code in the Shell language.
+
 - `tex` suitable for source code for LaTeX documents.
 
 
diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
index 1dbaa38..960b6e4 100755
--- a/t/t4018-diff-funcname.sh
+++ b/t/t4018-diff-funcname.sh
@@ -40,6 +40,7 @@ diffpatterns="
 	php
 	python
 	ruby
+	sh
 	tex
 	custom1
 	custom2
diff --git a/t/t4018/sh-function b/t/t4018/sh-function
new file mode 100644
index 0000000..1d5096a
--- /dev/null
+++ b/t/t4018/sh-function
@@ -0,0 +1,4 @@
+RIGHT_foo()
+{
+	ChangeMe;
+}
diff --git a/t/t4018/sh-function-comment b/t/t4018/sh-function-comment
new file mode 100644
index 0000000..f340ee7
--- /dev/null
+++ b/t/t4018/sh-function-comment
@@ -0,0 +1,6 @@
+  RIGHT_foo() # echo 'foo'
+#bar()
+{
+	#bar()
+	ChangeMe;
+}
diff --git a/t/t4018/sh-function-nested b/t/t4018/sh-function-nested
new file mode 100644
index 0000000..d3263f3
--- /dev/null
+++ b/t/t4018/sh-function-nested
@@ -0,0 +1,7 @@
+foo (     )
+{
+	RIGHT_bar()
+	{
+		echo ChangeMe
+	}
+}
diff --git a/t/t4018/sh-function-prefix b/t/t4018/sh-function-prefix
new file mode 100644
index 0000000..e96eb7a
--- /dev/null
+++ b/t/t4018/sh-function-prefix
@@ -0,0 +1,4 @@
+function RIGHT_foo()
+{
+	ChangeMe;
+}
diff --git a/t/t4018/sh-function-string b/t/t4018/sh-function-string
new file mode 100644
index 0000000..f60a899
--- /dev/null
+++ b/t/t4018/sh-function-string
@@ -0,0 +1,4 @@
+RIGHT_foo() {
+	echo "bar()"
+	ChangeMe;
+}
diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh
index f2f55fc..24fd9aa 100755
--- a/t/t4034-diff-words.sh
+++ b/t/t4034-diff-words.sh
@@ -312,6 +312,7 @@ test_language_driver perl
 test_language_driver php
 test_language_driver python
 test_language_driver ruby
+test_language_driver sh
 test_language_driver tex
 
 test_expect_success 'word-diff with diff.sbe' '
diff --git a/t/t4034/sh/expect b/t/t4034/sh/expect
new file mode 100644
index 0000000..1c6de2d
--- /dev/null
+++ b/t/t4034/sh/expect
@@ -0,0 +1,46 @@
+<BOLD>diff --git a/pre b/post<RESET>
+<BOLD>index 20229c3..ab791db 100644<RESET>
+<BOLD>--- a/pre<RESET>
+<BOLD>+++ b/post<RESET>
+<CYAN>@@ -1,36 +1,36 @@<RESET>
+foo() {ls&echo}<RESET>
+$((<RED>a<RESET><GREEN>x<RESET>++))
+$((<RED>a<RESET><GREEN>x<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>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>**<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>/<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>%<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>+<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>-<RED>b<RESET><GREEN>y<RESET>))
+[ <RED>a<RESET><GREEN>x<RESET><=<RED>b<RESET><GREEN>y<RESET> ]
+[ <RED>a<RESET><GREEN>x<RESET>>=<RED>b<RESET><GREEN>y<RESET> ]
+[ <RED>a<RESET><GREEN>x<RESET>==<RED>b<RESET><GREEN>y<RESET> ]
+[ <RED>a<RESET><GREEN>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 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>
+<RED>a<RESET><GREEN>y<RESET>
+<GREEN>x<RESET>&<RED>b<RESET>
+<RED>a<RESET><GREEN>y<RESET>
+<GREEN>x<RESET>&&<RED>b<RESET>
+<RED>a<RESET><GREEN>y<RESET>
+<GREEN>x<RESET>|<RED>b<RESET>
+<RED>a<RESET><GREEN>y<RESET>
+<GREEN>x<RESET>||<RED>b<RESET>
+<RED>a<RESET><GREEN>y<RESET>
+<GREEN>x<RESET>=<RED>b<RESET><GREEN>y<RESET>
+$((<RED>a<RESET><GREEN>x<RESET>+=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>-=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>*=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>/=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>%=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET><<=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>>>=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>&=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>^=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>|=<RED>b<RESET><GREEN>y<RESET>))
+*)<RED>a<RESET><GREEN>b<RESET>;;ls
+FOO=42&<RED>foo<RESET><GREEN>fro<RESET>
+BAR=$(0)<RESET>
+[[ $<RED>a<RESET><GREEN>x<RESET> -eq $<RED>b<RESET><GREEN>y<RESET> ]]
diff --git a/t/t4034/sh/post b/t/t4034/sh/post
new file mode 100644
index 0000000..ab791db
--- /dev/null
+++ b/t/t4034/sh/post
@@ -0,0 +1,36 @@
+foo() {ls&echo}
+$((x++))
+$((x--))
+$((--x))
+$((++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 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))
+*)b;;ls
+FOO=42&fro
+BAR=$(0)
+[[ $x -eq $y ]]
diff --git a/t/t4034/sh/pre b/t/t4034/sh/pre
new file mode 100644
index 0000000..20229c3
--- /dev/null
+++ b/t/t4034/sh/pre
@@ -0,0 +1,36 @@
+foo() {ls&echo}
+$((a++))
+$((a--))
+$((--a))
+$((++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 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))
+$((a&=b))
+$((a^=b))
+$((a|=b))
+*)a;;ls
+FOO=42&foo
+BAR=$(0)
+[[ $a -eq $b ]]
diff --git a/userdiff.c b/userdiff.c
index 2ccbee5..40b3dc0 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -146,6 +146,13 @@ PATTERNS("csharp",
 	 "[a-zA-Z_][a-zA-Z0-9_]*"
 	 "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
 	 "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
+PATTERNS("sh",
+	"^([ \t]*(function[ \t]+)?[a-zA-Z_][a-zA-Z0-9_]*[ \t]*\\([ \t]*\\).*)$",
+	/* -- */
+	 "[a-zA-Z0-9_]+"
+	 "|[-+0-9]+"
+	 "|[-+*/<>%&^|=!]=|>>=?|<<=?|\\+\\+|--|\\*\\*|&&|\\|\\||\\[\\[|\\]\\]"
+	 "|>\\||[<>]+&|<>|<<-|;;"),
 { "default", NULL, -1, { NULL, 0 } },
 };
 #undef PATTERNS
-- 
Adrien Schildknecht
http://schischi.me

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

* Re: [PATCH v2] userdiff: funcname and word patterns for sh
  2015-03-09 23:40   ` [PATCH v2] " Adrien Schildknecht
@ 2015-03-14  5:13     ` Junio C Hamano
  2015-03-14 17:19     ` Matthieu Moy
  2015-03-25 21:36     ` Junio C Hamano
  2 siblings, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2015-03-14  5:13 UTC (permalink / raw)
  To: Adrien Schildknecht; +Cc: git, Matthieu.Moy

Adrien Schildknecht <adrien+dev@schischi.me> writes:

> Add regexp based on the "Shell Command Language" specifications.
> Because of the lax syntax of sh, some corner cases may not be
> handled properly.
>
> Signed-off-by: Adrien Schildknecht <adrien+dev@schischi.me>
> ---

Those of you who helped in the first round of review, any comments,
"This round looks good"'s, ...?

> +PATTERNS("sh",
> +	"^([ \t]*(function[ \t]+)?[a-zA-Z_][a-zA-Z0-9_]*[ \t]*\\([ \t]*\\).*)$",
> +	/* -- */

I do not think it is wrong per-se to try to be as precise as
possible, but I wonder if it is sufficient to cheat and make these
"what is a word?" expressions a bit looser, by declaring that it is
OK if a simpler pattern allows something that are syntactically
illegal in shell, as long as it splits valid shell construct
correctly.  For example:

> +	 "[a-zA-Z0-9_]+"
> +	 "|[-+0-9]+"

The first one matches an identifier (e.g. If you have frotz="a b c"
and $frotz, two appearances of 'frotz' are matched) and the second
one I think is trying to catch possibly signed integers, but the
latter also matches 0+1+++2 which is already loose (but I do not
think it is a problem).  Perhaps it is sufficient to collapse the
above into a single "[-+a-zA-Z0-9_$]+"?

> +	 "|[-+*/<>%&^|=!]=|>>=?|<<=?|\\+\\+|--|\\*\\*|&&|\\|\\||\\[\\[|\\]\\]"
> +	 "|>\\||[<>]+&|<>|<<-|;;"),

Likewise.  I wonder if something like "[-~!@#%^&*+=|;/]+" gives too
many false matches.

>  { "default", NULL, -1, { NULL, 0 } },
>  };
>  #undef PATTERNS

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

* Re: [PATCH v2] userdiff: funcname and word patterns for sh
  2015-03-09 23:40   ` [PATCH v2] " Adrien Schildknecht
  2015-03-14  5:13     ` Junio C Hamano
@ 2015-03-14 17:19     ` Matthieu Moy
  2015-03-25 21:36     ` Junio C Hamano
  2 siblings, 0 replies; 7+ messages in thread
From: Matthieu Moy @ 2015-03-14 17:19 UTC (permalink / raw)
  To: Adrien Schildknecht; +Cc: git

On overall, the patch looks good. Some suggestions to improve the tests
and a minor nitpick below.

Adrien Schildknecht <adrien+dev@schischi.me> writes:

> +++ b/t/t4034/sh/post
> @@ -0,0 +1,36 @@
> +foo() {ls&echo}

This part is unchanged here and in the pre file. What does it test?

> +$((x++))
> +$((x--))
> +$((--x))
> +$((++x))
> +$((x*y))
> +$((x&y))
> +$((x**y))
> +$((x/y))
> +$((x%y))
> +$((x+y))
> +$((x-y))
> +[ x<=y ]
> +[ x>=y ]
> +[ x==y ]
> +[ x!=y ]

Not sure what the last ones are testing. If it's "[" as "the test
command, spelled as [", then spaces are mandatory around the operators
(and equality should be written =, not == in POSIX).

> +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))
> +$((x<<=y))
> +$((x>>=y))
> +$((x&=y))
> +$((x^=y))
> +$((x|=y))

I think you should test the case of multiple-letters identifiers. One of
the benefit of having a proper word-diff pattern is that e.g.

- pre=foo
+ post=bar

will consider the change "pre" -> "post", and not an unmodified "p" with
the change "re" -> "ost" (otherwise, --color-words=. just works).

> +PATTERNS("sh",
> +	"^([ \t]*(function[ \t]+)?[a-zA-Z_][a-zA-Z0-9_]*[ \t]*\\([ \t]*\\).*)$",
> +	/* -- */
> +	 "[a-zA-Z0-9_]+"

Nitpick: the indentation is not homogeneous. You should add a space
after the tab on the first two lines to get a correct alignment.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

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

* Re: [PATCH v2] userdiff: funcname and word patterns for sh
  2015-03-09 23:40   ` [PATCH v2] " Adrien Schildknecht
  2015-03-14  5:13     ` Junio C Hamano
  2015-03-14 17:19     ` Matthieu Moy
@ 2015-03-25 21:36     ` Junio C Hamano
  2 siblings, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2015-03-25 21:36 UTC (permalink / raw)
  To: Adrien Schildknecht; +Cc: git, Matthieu.Moy

Adrien Schildknecht <adrien+dev@schischi.me> writes:

> Add regexp based on the "Shell Command Language" specifications.
> Because of the lax syntax of sh, some corner cases may not be
> handled properly.
>
> Signed-off-by: Adrien Schildknecht <adrien+dev@schischi.me>
> ---

Is a reroll for this patch coming, or should I drop this from my
tree for now?

Thanks.

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

end of thread, other threads:[~2015-03-25 21:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-09 16:36 [GSoC][PATCH] userdiff: funcname and word patterns for sh Adrien Schildknecht
2015-03-09 16:36 ` [PATCH] " Adrien Schildknecht
2015-03-09 20:34   ` Matthieu Moy
2015-03-09 23:40   ` [PATCH v2] " Adrien Schildknecht
2015-03-14  5:13     ` Junio C Hamano
2015-03-14 17:19     ` Matthieu Moy
2015-03-25 21:36     ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.