Sublime Forum

[solved] Shell string replacement syntax BUG // nested brace

#1

Hello all,
First I’ve just discovered SublimeText a few days ago, and use it as a basic end-user.
I have troubles to find the way to make this code with proper syntax highlighting:

#!/bin/bash declare -a substring=( "11" "22" "33" ) declare -a replacement=( "44" "55" "66" ) TEXT="11 and 22" for (( i=0 ; i<${#substring*]} ; i++ )); do if ( `echo ${TEXT} | grep "${substring$i]}" 1>/dev/null 2>&1` ); then TEXT=${TEXT//"${substring$i]}"/"${replacement$i]}"}; fi done echo $TEXT



I feel that ShellScript.sublime-package needs adjustment or a custom syntax definition needs to be added but haven’t succeed to find the good syntax.
Thanks in advance if you could give me some track.

Edition : to clarify, this line cause the syntax highlighting to stop : TEXT=${TEXT//"${substring$i]}"/"${replacement$i]}"}; if double quotes from 1st argument ( ${substring$i]} ) are removed, it is OK

Edition2 : changed title with [solved], added “nested braces” in title

0 Likes

Oniguruma syntax definition help
#2

bump

0 Likes

#3

It’s the nested braces that are breaking the syntax.

Add the following after line 1823 of Shell-Unix-Generic.tmLanguage:

<dict> <key>include</key> <string>#nested_braces</string> </dict>

Then add the following after line line 91:

<key>nested_braces</key> <dict> <key>begin</key> <string>\{</string> <key>end</key> <string>\}</string> <key>patterns</key> <array> <dict> <key>include</key> <string>#nested_braces</string> </dict> </array> </dict>

0 Likes

#4

Thanks a lot Nick !! :stuck_out_tongue:
It works OK !

We might not have the same Shell-Unix-Generic-tmLanguage, so I have inserted the code around line 1823 just after the array element so it is now: <array> <dict> <key>include</key> <string>#nested_braces</string> </dict> <dict> <key>match</key> <string>!|:-=?]?|\*|@|#{1,2}|%{1,2}|/</string> <key>name</key> <string>keyword.operator.expansion.shell</string> </dict>

0 Likes

#5

Can someone please post a working Shell-Unix-Generic.tmLanguage or further instructions? I can’t seem to edit mine properly.

0 Likes

#6

I tried to edit Shell-Unix-Generic.tmLanguage again, and reached a point where nested brackets work but everything inside functions isn’t highlighted. It’s all seen as source.shell meta.function.shell. Does it really have to be one or the other?

0 Likes

#7

Anyone?

0 Likes

#8

Still looking for a solution.

0 Likes