[gtksourceview] Improve sh syntax variable highlighting
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] Improve sh syntax variable highlighting
- Date: Fri, 15 May 2015 18:17:02 +0000 (UTC)
commit 835df2b3774c478847a7e06032ebc5caf4dfc7cb
Author: Ilya Novoselov <ilya novoselov gmail com>
Date: Mon May 11 16:50:01 2015 +0500
Improve sh syntax variable highlighting
Replace naive match of anything behind $ with contexts, based on posix
shell syntax specifications.
https://bugzilla.gnome.org/show_bug.cgi?id=749221
data/language-specs/sh.lang | 22 ++++++++++++++++++++--
tests/syntax-highlighting/file.sh | 29 +++++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 2 deletions(-)
---
diff --git a/data/language-specs/sh.lang b/data/language-specs/sh.lang
index 1f19f7a..bd242c3 100644
--- a/data/language-specs/sh.lang
+++ b/data/language-specs/sh.lang
@@ -180,8 +180,26 @@
<keyword>\-ge\b</keyword>
</context>
- <context id="variable" style-ref="variable">
- <match>\$+[! ?*#\${a-zA-Z0-9_][}a-zA-Z0-9_]*</match>
+ <context id="short-parameter-expansion" style-ref="variable">
+ <match>\$([! ?*#\$0-9]|[a-zA-Z0-9_]+)</match>
+ </context>
+
+ <context id="parameter-expansion" style-ref="variable">
+ <start>\$\{</start>
+ <end>\}</end>
+ <include>
+ <context ref="single-quoted-string"/>
+ <context ref="double-quoted-string"/>
+ <context ref="variable"/>
+ <context ref="backtick-subshell"/>
+ </include>
+ </context>
+
+ <context id="variable">
+ <include>
+ <context ref="short-parameter-expansion"/>
+ <context ref="parameter-expansion"/>
+ </include>
</context>
<context id="variable-definition">
diff --git a/tests/syntax-highlighting/file.sh b/tests/syntax-highlighting/file.sh
index 92b60f0..10d6392 100644
--- a/tests/syntax-highlighting/file.sh
+++ b/tests/syntax-highlighting/file.sh
@@ -1,2 +1,31 @@
#!/bin/bash
echo "Hi there!"
+
+# Parameter Expansion
+
+xxx${xxx}xxx # parameter in braces
+xxx${"{"}xxx xxx${"}"}xxx # brace in quoted string
+
+xxx$0000 # one digit parameter
+
+xxx${parameter:-word}xxx${parameter-word}xxx # Use Default Values
+xxx${parameter:=word}xxx${parameter=word}xxx # Assign Default Values
+xxx${parameter:?word}xxx${parameter?word}xxx # Indicate Error if Null or Unset
+xxx${parameter:?}xxx${parameter?}xxx # Indicate Error if Null or Unset
+xxx${parameter:+word}xxx${parameter+word}xxx # Use Alternative Value
+
+xxx${#parameter}xxx # String Length
+xxx${parameter%word}xxx # Remove Smallest Suffix Pattern
+xxx${parameter%%word}xxx # Remove Largest Suffix Pattern
+xxx${parameter#word}xxx # Remove Smallest Prefix Pattern
+xxx${parameter##word}xxx # Remove Largest Prefix Pattern
+
+xxx${x:-$(ls)}xxx
+xxx${posix:?}xxx
+xxx${3:+posix}xxx
+xxx${#HOME}xxx
+xxx${x%.c}.oxxx
+xxx${x#$HOME}xxx
+xxx${x##*/}xxx
+xxx${x#*}xxx
+xxx${x#"*"}xxx
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]