Sublime Forum

Bash syntax highlighting 13th case statement breaks coloring

#1

Hi Jon, All,

I’ve recently purchased sublimetext 2 (for my company, 10 licences, yay :wink: and am really happy with how it works. However, we run into an annoying bug with Bash / Shell syntax highlighting when it comes to case statements.

We see that the syntax highlighter gets confused when parsing multiple case statements in a Shell Script file, but we also see that the Solarized Dark and Light themes get confused in a strange way!

With all themes except Solarized (including the default Monokai themes) we see that with a test file (see svn.openpcf.org/session/trunk/do … oloring.sh) syntax coloring breaks down after line 110 (funnily enough the 13th case statement… eerie).

With Solarized themes, we see the 5th case statement being uncolored, then a strangely colored case statement (the 6th), then the 10th becomes blue with again the 11th strangely colored and finaly total uncolored breakdown at the 13th case statement.

Since we do quite a lot of work with bash, it would be really helpful if this (somewhat spooky) bug was fixed!

Kind regards!

Rubin!
RAAF Technology

PS: The test file is here: svn.openpcf.org/session/trunk/do … oloring.sh

0 Likes

#2

Mmm, it seems to me that this way things that need to be fixed get lost. Additionally, it looks like paying for Sublime Text does not mean support, but more of a donation instead of a commercial transaction (payment <-> service)?

0 Likes

#3

Interesting Bug.

If you look at the Language-definitions for the Case-Keywords in the sourcecode you provided, you can see that this causes some kind of loop of death
(select the case-keyword, press Shift+Ctrl+Alt+p, and look at the Statusbar in the Bottom, with each case-keyword the list gets longer and longer).
My guess is that Sublime text caps at too many of these Scope-Words and then just does not highlight them.

If you want, you can try and fix this bug yourself; look in the Shell-Unix-Generic.tmLanguage, which defines these Scope-Words and finds occurences in the Sourcecode using Regex.
Somewhere around there should be the Problem.

0 Likes

#4

Aha, found the / a fix!

In Shell-Unix-Generic.tmLanguage, you want to comment out the lines 1378 to 1431
(The lines beginning with

begin
\b(case)\b
)
Unfortunately I dont know the side-effects of this edit, but its better than no highlighting at all :smile:

0 Likes

#5

I’m not great with the syntax highlighting stuff nor am I familiar with proper bash syntax, so I held off on answering. But I’ll expand a bit on Voelkerball’s answer. The problem, from what I can tell, is the recognition of the closing of a case statement. For example, if you look at the scope between two case statements, a “case” scope still exists.

Anyways, the nested reference is being used to identify “in” as a shell keyword and create an additional space for A further dive into the actual syntax file reveals it looks for “ecas” as the closing to two sets of patterns. My guess is only the nested pattern is being closed properly. With that being said, I’m not great with regular expressions either so I can’t offer a better solution.

Simply commenting out that section may prevent some syntax coloring within the case statements. But then again, it might not depending on where else they are defined.

0 Likes

#6

The commenting out of the case section in the tmLanguage file works, syntax highlighting seems to keep working too, I can’t see a difference, except that all case statements in the test file now color correctly.

Thanks!

0 Likes