[gtksourceview] sh.lang: Fix parameter detection in parameter expansion



commit bb6e6adb27f08c430e43e825eab3bd43a719dc7e
Author: neyfag <11970-neyfag users noreply gitlab gnome org>
Date:   Wed Apr 1 00:08:20 2020 +0200

    sh.lang: Fix parameter detection in parameter expansion

 data/language-specs/sh.lang       | 27 +++++++++++++--------------
 tests/syntax-highlighting/file.sh |  2 +-
 2 files changed, 14 insertions(+), 15 deletions(-)
---
diff --git a/data/language-specs/sh.lang b/data/language-specs/sh.lang
index 88adc473..c62b80f7 100644
--- a/data/language-specs/sh.lang
+++ b/data/language-specs/sh.lang
@@ -436,23 +436,22 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="variable"/>
         <context sub-pattern="0" where="end" style-ref="variable"/>
-        <!-- The order of the two following contexts matters -->
-        <context id="array-variable" once-only="true">
-          <start>([!#])?(\%{identifier})(\[)</start>
-          <end>\]</end>
+        <context id="parameter" once-only="true">
+          <start>(?&lt;=\$\{)([!#]?)(\%{identifier}|\%{special-parameter})</start>
+          <end>\%{def:always-match}</end>
           <include>
             <context sub-pattern="1" where="start" style-ref="keyword"/>
             <context sub-pattern="2" where="start" style-ref="variable"/>
-            <context sub-pattern="3" where="start" style-ref="keyword"/>
-            <context sub-pattern="0" where="end" style-ref="keyword"/>
-            <context ref="expansion-nesting"/>
-            <context ref="expansion-precedence"/>
-          </include>
-        </context>
-        <context id="simple-variable" once-only="true" style-ref="variable">
-          <match>([!#])?\%{identifier}|\%{special-parameter}</match>
-          <include>
-            <context sub-pattern="1" style-ref="keyword"/>
+            <context id="array-part" once-only="true">
+              <start>\[</start>
+              <end>\]</end>
+              <include>
+                <context sub-pattern="0" where="start" style-ref="keyword"/>
+                <context sub-pattern="0" where="end" style-ref="keyword"/>
+                <context ref="expansion-nesting"/>
+                <context ref="expansion-precedence"/>
+              </include>
+            </context>
           </include>
         </context>
         <!-- Must be included first, to ensure unescaped boundaries -->
diff --git a/tests/syntax-highlighting/file.sh b/tests/syntax-highlighting/file.sh
index 8362978d..90586387 100644
--- a/tests/syntax-highlighting/file.sh
+++ b/tests/syntax-highlighting/file.sh
@@ -10,7 +10,7 @@ xxx${var\
 
 xxx$0000 # One digit parameter
 xxx$-xxx xxx$$xxx xxx$@xxx # Special parameters
-xxx${!array[@]}xxx${#array[-1]}xxx${array[0x1+var/2*$(cmd)]}xxx # Arrays
+xxx${!array[@]}xxx${#array[-1]}xxx${array[0x1+var/2*$(cmd)]/a/b}xxx # Arrays
 
 xxx${parameter:-word}xxx${parameter-word}xxx # Use Default Values
 xxx${parameter:=word}xxx${parameter=word}xxx # Assign Default Values


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]