Home Download Buy Blog Forum Support

tmLanguage syntax rules -- multiple scopes?

tmLanguage syntax rules -- multiple scopes?

Postby maxedison on Wed Oct 09, 2013 4:49 pm

I am trying to create my own syntax definition. Consider the following:

Code: Select all
      <dict>
         <key>name</key>
         <string>eb.detail</string>
         <key>begin</key>
         <string>\|</string>
         <key>end</key>
         <string>\||$</string>
      </dict>
      <dict>
         <key>name</key>
         <string>eb.trigger</string>
         <key>match</key>
         <string>\|</string>
      </dict>


The first rule matches something like |hello|, including the pipe characters. The second rule matches just the pipe characters. Ultimately, I would like those pipe characters to get BOTH scopes assigned to it. How would I accomplish that in the tmLanguage file?
maxedison
 
Posts: 5
Joined: Mon Sep 19, 2011 7:51 pm

Re: tmLanguage syntax rules -- multiple scopes?

Postby quodlibet on Mon Oct 14, 2013 12:46 pm

First of all you would switch to writing tmLanguage files in JSON and converting them with the wonderful PlistJsonConverter plugin. (Actually, this is optional, but _highly_ recommended if you value your sanity.)

Second you would use "captures" to break down a scope into components. These are reasonably well documented here:
http://docs.sublimetext.info/en/sublime ... xdefs.html
http://docs.sublimetext.info/en/sublime ... xdefs.html

Here's an example from my Markdown syntax for scoping `code` (in JSON):

Code: Select all
"inline-code":  {
   "name": "markup.raw.inline.markdown",
   "begin": "(`{1,2})(.*?)",
   "end": "(\\1)",
   "captures": {
      "1": { "name": "punctuation.definition.raw.inline.markdown" },
   },
},


The capture assigns the punctuation scope to the backticks.

Hope this helps,
Alex
quodlibet
 
Posts: 500
Joined: Sat Jun 18, 2011 5:53 pm


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 7 guests