[gtksourceview: 1/2] sh.lang: Improve and homogenize boundaries; cleaning
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview: 1/2] sh.lang: Improve and homogenize boundaries; cleaning
- Date: Tue, 12 Nov 2019 18:20:50 +0000 (UTC)
commit 62f31b4451cd4dbb356f374df7c1a070877b6c3d
Author: neyfag <11970-neyfag users noreply gitlab gnome org>
Date: Tue Nov 12 18:05:52 2019 +0100
sh.lang: Improve and homogenize boundaries; cleaning
data/language-specs/sh.lang | 56 +++++++++++++++------------------------
tests/syntax-highlighting/file.sh | 7 ++++-
2 files changed, 28 insertions(+), 35 deletions(-)
---
diff --git a/data/language-specs/sh.lang b/data/language-specs/sh.lang
index 1b09ad7a..9590369d 100644
--- a/data/language-specs/sh.lang
+++ b/data/language-specs/sh.lang
@@ -42,16 +42,17 @@
<style id="subshell" name="Subshell" map-to="def:preprocessor"/>
</styles>
+<keyword-char-class>[^()`&|;]</keyword-char-class>
+
<definitions>
- <define-regex id="assignment">\+?=</define-regex>
- <define-regex id="boundary-operator">[()`&|;]</define-regex>
<define-regex id="identifier">[a-zA-Z_][a-zA-Z0-9_]*</define-regex>
+ <define-regex id="unescaped-space">(?<!\\)\s</define-regex>
<!-- we cannot use def:shell-like-comment, because
m4.lang needs to replace this context -->
<context id="line-comment" style-ref="comment" end-at-line-end="true" class="comment"
class-disabled="no-spell-check">
- <start>(?<!\S)#</start>
+ <start>(?<=\s)#</start>
<include>
<context ref="def:in-comment"/>
</include>
@@ -109,22 +110,16 @@
</context>
<context id="function" style-ref="function">
- <match>\b\%{identifier}[ \t]*\(\)</match>
+ <match>(?<=\%{unescaped-space}|\%[)\%{identifier}\s*\(\)</match>
</context>
<context id="redirection" style-ref="others">
- <keyword>>&+[0-9]</keyword>
- <keyword>\b[0-9]+>&</keyword>
- <keyword>\b[0-9]+>&+[0-9]</keyword>
- <keyword>\b[0-9]+></keyword>
- <keyword>>></keyword>
- <keyword>\b[0-9]+>></keyword>
- <keyword><&[0-9]</keyword>
- <keyword>\b[0-9]+<&</keyword>
- <keyword>\b[0-9]+<&[0-9]</keyword>
- <keyword>\b[0-9]+<</keyword>
- <keyword><<+[0-9]</keyword>
- <keyword>\b[0-9]+<<</keyword>
+ <prefix></prefix>
+ <suffix></suffix>
+ <!-- The order of the two following keywords matters -->
+ <keyword>([0-9]+)?[<>](&)?([0-9]+)?-?</keyword>
+ <keyword>(&|[0-9]+)?>{1,2}([0-9]+)?-?</keyword>
+ <keyword>([0-9]+)?(<>|>\|)</keyword>
</context>
<context id="here-doc">
@@ -207,15 +202,7 @@
</context>
<context id="stand-alone-variable-definition">
- <match extended="true">
- (?:
- ^ \s* |
- (?<=\%{boundary-operator}) \s* |
- (?<=if|then|else|while|until|do|{) \s+
- )
- (\%{identifier})
- \%{assignment}
- </match>
+ <match>(?<=\%{unescaped-space}|\%[)(\%{identifier})\+?=</match>
<include>
<context sub-pattern="1" style-ref="variable-definition"/>
</include>
@@ -223,11 +210,11 @@
<context id="variable-definition-command" end-at-line-end="true" extend-parent="false">
<start extended="true">
- (?<=\%{boundary-operator}|^|\s)
+ (?<=\%{unescaped-space}|\%[)
(declare|local|typeset|readonly|export)
- (?=\%{boundary-operator}|$|\s)
+ (?=\s|\%])
</start>
- <end>>|\%{boundary-operator}</end>
+ <end>\%]</end>
<include>
<context sub-pattern="0" where="start" style-ref="keyword"/>
<context sub-pattern="0" where="end" style-ref="keyword"/>
@@ -236,11 +223,12 @@
<context ref="line-comment"/>
<context ref="single-quoted-string"/>
<context ref="double-quoted-string"/>
+ <context ref="redirection"/>
<context ref="backtick-subshell"/>
<context ref="subshell"/>
<context ref="variable"/>
<context style-ref="variable-definition">
- <match>(?<=(?<!\\)\s)\%{identifier}</match>
+ <match>(?<=\%{unescaped-space})\%{identifier}</match>
</context>
</include>
</context>
@@ -265,8 +253,8 @@
<!-- To prevent conflicts, keywords below should be removed from the list
before being used in any container context -->
<context id="built-in-command-2" style-ref="keyword">
- <prefix>(?<![^\s;\(\)\`])</prefix>
- <suffix>(?![^\s;\(\)\`])</suffix>
+ <prefix>(?<=\%{unescaped-space}|\%[)</prefix>
+ <suffix>(?=\s|\%])</suffix>
<keyword>do</keyword>
<keyword>done</keyword>
<keyword>elif</keyword>
@@ -327,8 +315,8 @@
</context>
<context id="case-command">
- <start>\bcase\b</start>
- <end>\besac\b</end>
+ <start>(?<=\%{unescaped-space}|\%[)case(?=\s)</start>
+ <end>(?<=\%{unescaped-space}|\%[)esac(?=\s|\%])</end>
<include>
<context sub-pattern="0" where="start" style-ref="keyword"/>
<context sub-pattern="0" where="end" style-ref="keyword"/>
@@ -337,7 +325,7 @@
</context>
<context id="for-command" end-at-line-end="true">
- <start>\bfor\b</start>
+ <start>(?<=\%{unescaped-space}|\%[)for(?=\s)</start>
<end>(?=\S)</end>
<include>
<context sub-pattern="0" where="start" style-ref="keyword"/>
diff --git a/tests/syntax-highlighting/file.sh b/tests/syntax-highlighting/file.sh
index 5cb714e0..68a35b26 100644
--- a/tests/syntax-highlighting/file.sh
+++ b/tests/syntax-highlighting/file.sh
@@ -31,7 +31,7 @@ xxx${x#*}xxx
xxx${x#"*"}xxx
# Variable definitions
-var1=val1; var2=val2
+var1=val1; var2=val2 var3=val3
if var=$(cmd); then some; fi
test -f xxx && var=xxx || var=yyy
echo text | var=xxx cmd & var=yyy
@@ -56,3 +56,8 @@ arg; do echo $arg; done
echo Look for file
echo Look for; echo Look for
echo next line
+
+# Redirections
+> >> 1>&2 &> 3>&-
+< 0<&3 3<&-
+3<> 1>|
\ No newline at end of file
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]