Home Download Buy Blog Forum Support

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

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

Postby electronico on Fri Apr 20, 2012 3:17 am

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:
Code: Select all
#!/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
shell_2012-04-20.png
shell_2012-04-20.png (28.17 KiB) Viewed 1527 times

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 :
Code: Select all
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
Last edited by electronico on Wed May 02, 2012 9:45 pm, edited 1 time in total.
electronico
 
Posts: 3
Joined: Fri Apr 20, 2012 2:21 am

Re: Shell string replacement syntax BUG

Postby electronico on Tue May 01, 2012 10:50 pm

bump
electronico
 
Posts: 3
Joined: Fri Apr 20, 2012 2:21 am

Re: Shell string replacement syntax BUG

Postby nick. on Wed May 02, 2012 1:45 pm

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

Add the following after line 1823 of Shell-Unix-Generic.tmLanguage:
Code: Select all
<dict>
    <key>include</key>
    <string>#nested_braces</string>
</dict>


Then add the following after line line 91:
Code: Select all
<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>
nick.
 
Posts: 266
Joined: Wed Jan 18, 2012 3:45 am

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

Postby electronico on Wed May 02, 2012 9:42 pm

Thanks a lot Nick !! :P
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:
Code: Select all
               <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>
electronico
 
Posts: 3
Joined: Fri Apr 20, 2012 2:21 am

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

Postby CdR on Mon Mar 04, 2013 9:04 am

Can someone please post a working Shell-Unix-Generic.tmLanguage or further instructions? I can't seem to edit mine properly.
CdR
 
Posts: 5
Joined: Mon Mar 04, 2013 9:02 am

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

Postby CdR on Sun Mar 17, 2013 9:39 am

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?
CdR
 
Posts: 5
Joined: Mon Mar 04, 2013 9:02 am

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

Postby CdR on Tue May 07, 2013 12:39 pm

Anyone?
CdR
 
Posts: 5
Joined: Mon Mar 04, 2013 9:02 am

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

Postby CdR on Mon Jul 01, 2013 9:12 am

Still looking for a solution.
CdR
 
Posts: 5
Joined: Mon Mar 04, 2013 9:02 am


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot], Jibz and 23 guests