Home Download Buy Blog Forum Support

Help with fixing syntax highlighter definition

Help with fixing syntax highlighter definition

Postby oats on Mon Jan 10, 2011 6:10 pm

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?

Code: Select all
      <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>
oats
 
Posts: 101
Joined: Mon Nov 09, 2009 4:39 pm

Re: Help with fixing syntax highlighter definition

Postby adzenith on Mon Jan 10, 2011 6:21 pm

Maybe try changing:
Code: Select all
         <key>begin</key>
         <string>'</string>
         <key>beginCaptures</key>

to something like:
Code: Select all
         <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?)
adzenith
 
Posts: 1216
Joined: Mon Oct 19, 2009 9:12 pm

Re: Help with fixing syntax highlighter definition

Postby oats on Mon Jan 10, 2011 6:51 pm

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:
Code: Select all
         <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.
oats
 
Posts: 101
Joined: Mon Nov 09, 2009 4:39 pm

Re: Help with fixing syntax highlighter definition

Postby jps on Mon Jan 10, 2011 9:15 pm

The Matlab.tmLanguage shipped with Sublime Text is older than the version at http://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.
jps
Site Admin
 
Posts: 3067
Joined: Wed Mar 19, 2008 12:33 pm

Re: Help with fixing syntax highlighter definition

Postby adzenith on Mon Jan 10, 2011 9:54 pm

Oh, of course -- the code I threw out there needed to have been ?&lt;! instead of ?<!
adzenith
 
Posts: 1216
Joined: Mon Oct 19, 2009 9:12 pm


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot] and 22 guests