Sublime Forum

tmLanguage syntax rules -- multiple scopes?

#1

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

<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?

0 Likes

#2

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:
docs.sublimetext.info/en/sublime … xdefs.html
docs.sublimetext.info/en/sublime … xdefs.html

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

"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

0 Likes