Skip to content

Commit 557ea2f

Browse files
committed
Merge branch 'md/userdiff-bash-shell-function' into jch
The userdiff pattern for shell scripts has been updated to cope with more bash-isms. Comments? * md/userdiff-bash-shell-function: userdiff: extend Bash pattern to cover more shell function forms
2 parents ae6c28a + 19a1ade commit 557ea2f

File tree

8 files changed

+110
-6
lines changed

8 files changed

+110
-6
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function RIGHT \
2+
{
3+
echo 'ChangeMe'
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RIGHT() \
2+
{
3+
ChangeMe
4+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
RIGHT() echo "hello"
2+
3+
ChangeMe

t/t4034-diff-words.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ test_expect_success 'unset default driver' '
320320

321321
test_language_driver ada
322322
test_language_driver bibtex
323+
test_language_driver bash
323324
test_language_driver cpp
324325
test_language_driver csharp
325326
test_language_driver css

t/t4034/bash/expect

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<BOLD>diff --git a/pre b/post<RESET>
2+
<BOLD>index 09ac008..60ba6a2 100644<RESET>
3+
<BOLD>--- a/pre<RESET>
4+
<BOLD>+++ b/post<RESET>
5+
<CYAN>@@ -1,25 +1,25 @@<RESET>
6+
<RED>my_var<RESET><GREEN>new_var<RESET>=10
7+
x=<RED>123<RESET><GREEN>456<RESET>
8+
y=<RED>3.14<RESET><GREEN>2.71<RESET>
9+
z=<RED>.5<RESET><GREEN>.75<RESET>
10+
echo <RED>$USER<RESET><GREEN>$USERNAME<RESET>
11+
${<RED>HOME<RESET><GREEN>HOMEDIR<RESET>}
12+
if [ "<RED>$a<RESET><GREEN>$x<RESET>" == "<RED>$b<RESET><GREEN>$y<RESET>" ] || [ "<RED>$c<RESET><GREEN>$x<RESET>" != "<RED>$d<RESET><GREEN>$y<RESET>" ]; then echo "OK"; fi
13+
((<RED>a<RESET><GREEN>x<RESET>+=<RED>b<RESET><GREEN>y<RESET>))
14+
((<RED>a<RESET><GREEN>x<RESET>-=<RED>b<RESET><GREEN>y<RESET>))
15+
$((<RED>a<RESET><GREEN>x<RESET><<<RED>b<RESET><GREEN>y<RESET>))
16+
$((<RED>a<RESET><GREEN>x<RESET>>><RED>b<RESET><GREEN>y<RESET>))
17+
${<RED>a<RESET><GREEN>x<RESET>:-<RED>b<RESET><GREEN>y<RESET>}
18+
${<RED>a<RESET><GREEN>x<RESET>:=<RED>b<RESET><GREEN>y<RESET>}
19+
${<RED>a<RESET><GREEN>x<RESET>##*/}
20+
${<RED>a<RESET><GREEN>x<RESET>%.*}
21+
${<RED>a<RESET><GREEN>x<RESET>%%.*}
22+
${<RED>a<RESET><GREEN>x<RESET>^^}
23+
${<RED>a<RESET><GREEN>x<RESET>,}
24+
${<RED>a<RESET><GREEN>x<RESET>,,}
25+
${!<RED>a<RESET><GREEN>x<RESET>}
26+
${<RED>a<RESET><GREEN>x<RESET>[@]}
27+
${<RED>a<RESET><GREEN>x<RESET>:?error message}
28+
${<RED>a<RESET><GREEN>x<RESET>:2:3}
29+
ls <RED>-a<RESET><GREEN>-x<RESET>
30+
ls <RED>--a<RESET><GREEN>--x<RESET>

t/t4034/bash/post

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
new_var=10
2+
x=456
3+
y=2.71
4+
z=.75
5+
echo $USERNAME
6+
${HOMEDIR}
7+
if [ "$x" == "$y" ] || [ "$x" != "$y" ]; then echo "OK"; fi
8+
((x+=y))
9+
((x-=y))
10+
$((x<<y))
11+
$((x>>y))
12+
${x:-y}
13+
${x:=y}
14+
${x##*/}
15+
${x%.*}
16+
${x%%.*}
17+
${x^^}
18+
${x,}
19+
${x,,}
20+
${!x}
21+
${x[@]}
22+
${x:?error message}
23+
${x:2:3}
24+
ls -x
25+
ls --x

t/t4034/bash/pre

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
my_var=10
2+
x=123
3+
y=3.14
4+
z=.5
5+
echo $USER
6+
${HOME}
7+
if [ "$a" == "$b" ] || [ "$c" != "$d" ]; then echo "OK"; fi
8+
((a+=b))
9+
((a-=b))
10+
$((a << b))
11+
$((a >> b))
12+
${a:-b}
13+
${a:=b}
14+
${a##*/}
15+
${a%.*}
16+
${a%%.*}
17+
${a^^}
18+
${a,}
19+
${a,,}
20+
${!a}
21+
${a[@]}
22+
${a:?error message}
23+
${a:2:3}
24+
ls -a
25+
ls --a

userdiff.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,27 @@ PATTERNS("bash",
6464
/* Bashism identifier with optional parentheses */
6565
"(function[ \t]+[a-zA-Z_][a-zA-Z0-9_]*(([ \t]*\\([ \t]*\\))|([ \t]+))"
6666
")"
67-
/* Optional whitespace */
68-
"[ \t]*"
69-
/* Compound command starting with `{`, `(`, `((` or `[[` */
70-
"(\\{|\\(\\(?|\\[\\[)"
67+
/* Everything after the function header is captured */
68+
".*$"
7169
/* End of captured text */
7270
")",
7371
/* -- */
74-
/* Characters not in the default $IFS value */
75-
"[^ \t]+"),
72+
/* Identifiers: variable and function names */
73+
"[a-zA-Z_][a-zA-Z0-9_]*"
74+
/* Numeric constants: integers and decimals */
75+
"|[0-9]+(\\.[0-9]*)?|[-+]?\\.[0-9]+"
76+
/* Shell variables: $VAR, ${VAR} */
77+
"|\\$[a-zA-Z_][a-zA-Z0-9_]*|\\$\\{"
78+
/* Logical and comparison operators */
79+
"|\\|\\||&&|<<|>>|==|!=|<=|>="
80+
/* Assignment and arithmetic operators */
81+
"|[-+*/%&|^!=<>]=?"
82+
/* Additional parameter expansion operators */
83+
"|:?=|:-|:\\+|:\\?|:|#|##|%|%%|/[a-zA-Z0-9_-]+|\\^\\^?|,|,,?|!|@|:[0-9]+(:[0-9]+)?"
84+
/* Command-line options (to avoid splitting -option) */
85+
"|--?[a-zA-Z0-9_-]+"
86+
/* Brackets and grouping symbols */
87+
"|\\(|\\)|\\{|\\}|\\[|\\]"),
7688
PATTERNS("bibtex",
7789
"(@[a-zA-Z]{1,}[ \t]*\\{{0,1}[ \t]*[^ \t\"@',\\#}{~%]*).*$",
7890
/* -- */

0 commit comments

Comments
 (0)