Sublime Forum

Help with fixing syntax highlighter definition

#1

Hi,
I’m working with the MATLAB tmLanguage file, trying to fix a minor bug.

Problem is that strings are wrapped in single-quotes (‘sample string’) but a single single-quote is also used as a transpose operator ( array3 = array1’ + array2’ ). Problem is that the tmLanguage file assumes that a single-quote is ALWAYS starting a new string, even if there is no matching single-quote. I want to change this so that it is only highlighted as a string if there is both an open and close single-quote present. Below is the relevant portion of the tmLanguage file… can someone help suggest a change?

<dict> <key>begin</key> <string>'</string> <key>beginCaptures</key> <dict> <key>0</key> <dict> <key>name</key> <string>punctuation.definition.string.begin.matlab</string> </dict> </dict> <key>end</key> <string>(')|\n</string> <key>endCaptures</key> <dict> <key>0</key> <dict> <key>name</key> <string>punctuation.definition.string.end.matlab</string> </dict> </dict> <key>name</key> <string>string.quoted.single.matlab</string> <key>patterns</key> <array> <dict> <key>match</key> <string>\\.</string> <key>name</key> <string>constant.character.escape.matlab</string> </dict> </array> </dict>

0 Likes

#2

Maybe try changing:

<key>begin</key> <string>'</string> <key>beginCaptures</key>
to something like:

<key>begin</key> <string>(?<!\w)'</string> <key>beginCaptures</key> This way only a quote mark that isn’t immediately following a letter, number, or underscore will count as starting a string. (I think this should be valid in .tmlanguage files. Give it a shot?)

0 Likes

#3

That didn’t work - got a parse error for some reason.

I removed the begin and end thing and made it a simple match, though now I don’t have the special coloring of the escape charaters, it’s not a big loss:

<key>match</key> <string>'((\\')|^'])*'</string> <key>name</key> <string>string.quoted.single.matlab</string>

If anyone solves this properly, it would be good to wrap into the official distribution.

0 Likes

#4

The Matlab.tmLanguage shipped with Sublime Text is older than the version at svn.textmate.org/trunk/Bundles/M … es/M.plist, which appears to have fixed the problem.

Try downloading that one and replacing Matlab.tmLanguage with it. In any case, I’ll put the updated version in the next build.

0 Likes

#5

Oh, of course – the code I threw out there needed to have been ?<! instead of ?<!

0 Likes