[gtksourceview: 1/2] sh.lang: Complete variable definition command
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview: 1/2] sh.lang: Complete variable definition command
- Date: Tue, 12 Nov 2019 02:29:35 +0000 (UTC)
commit 53b090d3b1693c976bcdba45f2fe4965b872bc84
Author: neyfag <11970-neyfag users noreply gitlab gnome org>
Date: Fri Nov 8 23:35:04 2019 +0100
sh.lang: Complete variable definition command
data/language-specs/sh.lang | 31 +++++++++++++++++--------------
tests/syntax-highlighting/file.sh | 7 ++++---
2 files changed, 21 insertions(+), 17 deletions(-)
---
diff --git a/data/language-specs/sh.lang b/data/language-specs/sh.lang
index 9e99228d..1b09ad7a 100644
--- a/data/language-specs/sh.lang
+++ b/data/language-specs/sh.lang
@@ -45,7 +45,7 @@
<definitions>
<define-regex id="assignment">\+?=</define-regex>
- <define-regex id="boundary-operator">[&|;]</define-regex>
+ <define-regex id="boundary-operator">[()`&|;]</define-regex>
<define-regex id="identifier">[a-zA-Z_][a-zA-Z0-9_]*</define-regex>
<!-- we cannot use def:shell-like-comment, because
@@ -105,7 +105,7 @@
</context>
<context id="punctuator" style-ref="others">
- <match>\%{boundary-operator}|/</match>
+ <match>[&|;/]</match>
</context>
<context id="function" style-ref="function">
@@ -206,13 +206,12 @@
</include>
</context>
- <define-regex id="keyword">(?<=if|then|else|while|until|do)</define-regex>
<context id="stand-alone-variable-definition">
<match extended="true">
(?:
^ \s* |
(?<=\%{boundary-operator}) \s* |
- (?<=if|then|else|while|until|do) \s+
+ (?<=if|then|else|while|until|do|{) \s+
)
(\%{identifier})
\%{assignment}
@@ -222,16 +221,26 @@
</include>
</context>
- <context id="variable-definition-command" end-at-line-end="true">
- <start>\b(declare|local|typeset|readonly|export)\b</start>
+ <context id="variable-definition-command" end-at-line-end="true" extend-parent="false">
+ <start extended="true">
+ (?<=\%{boundary-operator}|^|\s)
+ (declare|local|typeset|readonly|export)
+ (?=\%{boundary-operator}|$|\s)
+ </start>
<end>>|\%{boundary-operator}</end>
<include>
<context sub-pattern="0" where="start" style-ref="keyword"/>
+ <context sub-pattern="0" where="end" style-ref="keyword"/>
+ <context ref="def:escape"/>
<context ref="def:line-continue"/>
- <context ref="double-quoted-string"/>
+ <context ref="line-comment"/>
<context ref="single-quoted-string"/>
+ <context ref="double-quoted-string"/>
+ <context ref="backtick-subshell"/>
+ <context ref="subshell"/>
+ <context ref="variable"/>
<context style-ref="variable-definition">
- <match>(?<=\s)\%{identifier}</match>
+ <match>(?<=(?<!\\)\s)\%{identifier}</match>
</context>
</include>
</context>
@@ -324,12 +333,6 @@
<context sub-pattern="0" where="start" style-ref="keyword"/>
<context sub-pattern="0" where="end" style-ref="keyword"/>
<context ref="sh"/>
- <context>
- <match>(?<=\))\s*(\%{identifier})(\%{assignment})</match>
- <include>
- <context sub-pattern="1" style-ref="variable-definition"/>
- </include>
- </context>
</include>
</context>
diff --git a/tests/syntax-highlighting/file.sh b/tests/syntax-highlighting/file.sh
index c6b9b172..5cb714e0 100644
--- a/tests/syntax-highlighting/file.sh
+++ b/tests/syntax-highlighting/file.sh
@@ -32,14 +32,15 @@ xxx${x#"*"}xxx
# Variable definitions
var1=val1; var2=val2
-local var=xxx
if var=$(cmd); then some; fi
test -f xxx && var=xxx || var=yyy
echo text | var=xxx cmd & var=yyy
-declare -i '-r' "-x" var1=val1 var2=val2
+declare -i '-r' "-x" var1=val1 var2=$val1 var3=`cmd1` \
+ var4=$(cmd2) var5=xxx\ yyy var6 #comment
+var+=xxx; (var=yyy); { var=zzz; }
case $1 in
item) var=xxx;;
- *)var=yyy;;
+ *)declare var=yyy;;
esac
# For statements
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]