Sublime Forum

Syntax Definition referencing other syntax definitions

#1

I have my own custom file format that looks something like this… (oversimplified)

@module{module-name}

@section{section1}

@section{section2}

@code

@end

I’ve successfully made a .tmLanguage file for this, since it is very simple.
However, I want the parts to highlight as Markdown, and I want the parts to highlight as JavaScript.
But, I don’t want to copy/paste the .tmLanguage content for Markdown and JavaScript into my .tmLanguage file; instead, I just want to “include” them within a begin/end pattern.

Is this possible?

0 Likes

#2

Use “include” to include other syntaxes. For example with javascript in the patterns list:

			<key>patterns</key>
			<array>
				<dict>
					<key>include</key>
					<string>source.js</string>
				</dict>
			</array>

See sublime-text-unofficial-documen … xdefs.html
and manual.macromates.com/en/language_grammars
for more information on using “include” and grammars in general.

Also look at all the tmLanguage files that ship with Sublime. Many of them use includes to embed other languages.

0 Likes

#3

Hello.

I might be a little late on this one, but I wouldn’t want to start a new thread when this one already exists.

I’m working on a BBcode syntax based on the package from chipotle. I have this little bit of syntax definition:

[code]
begin
[code=html]
captures

0

name
meta.tag.code.html.bb.azuha


end
[/code]
name
text.html.embedded.bb.azuha
patterns


include
text.html.basic




name
text.url.embedded.bb.azuha
begin
[

The html part is from the original syntax, I didn’t touch it. The one I wrote is the one below involving urls.
Its goal is basically to treat the url in a url markup with a custom syntax I wrote, which works perfectly on a raw file and the scopeName of which is strictly the same as the one I include.

I know for a fact that the regexp are correct, the scopes are correctly computed outside of the url I want to parse. I also tried the html embedding and that works too.

The problem I have is the following :

it does not include.

My syntax exists. I tried putting it in the same folder as the html one. No success.

am I missing something ?
Is there something I don’t know about including syntaxes ? I searched but didn’t find, which is odd, I’ve been coding for 5 years and I’ve never been the only one with a problem before.](]+?(]))

0 Likes

#4

Normally I’d request you to upload the other syntax definition, but I think the issue is somewhere else – in your “end” pattern.

So your end pattern is currently this:

end: '^\]]+?(\])'

This will match … basically everything until the first closing bracket is found. The problem is that any patterns inside this begin-end match are only applied to the text within the matches. Since your end match will start matching at the very first character (of a new line) however, the include obviously won’t find anything since there is nothing to find.

Since simple matches like these (“begin”, “end”, “match”) will not cover multiple lines for the sake of efficiency in the algorithm, you should be able to confirm this by adding a newline right before the closing bracket. Such as:

[  blabla I'm not highlighted either way](http://www.sublimetext.com/forum/posting.php?mode=reply&f=6&t=16560)
0 Likes