Innovative Computer Solutions,
Development & Technical Support

07975 997026 • enquiries[delete-me]@[delete-me]harpanet.com

User Tools

Site Tools


blog:2013:06:creating-a-new-sublimetext-3-syntax-highlighting-language

Creating a new SublimeText 3 Syntax Highlighting Language

~~DRAFT~~

First, create a new package in: SublimeText3/Data/Packages with a relevant name, eg. myLang

SublimeText3/Data/Packages/myLang

Second, create a new language file(this is simply a text file containing XML) in your new package, eg. myLang.tmLanguage

SublimeText3/Data/Packages/myLang/mylang.tmLanguage

The .tmLanguage extension comes from the TextMate text editor, which SublimeText adheres to as far as possible. The .tmLanguage files themselves are 'plist' (property list) formatted XML files which were popularised by Apple.

Most discussions and web resources regarding tmLanguage files use the JSON format, then use a converter to create the PLIST formatted XML file. Here, we're going to write the XML directly and save installing/running any converter.

A tmLanguage SKELETON in PLIST FORMAT

Let's first create the basic XML skeleton that all PLIST files require.

skeleton.tmLanguage
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>name</key>
    <string>##LANGUAGE NAME##</string>
 
    <key>fileTypes</key>
    <array>
        <string>##FILE EXTENSION##</string>
    </array>
 
    ##LANGUAGE PATTERNS##
 
    <key>scopeName</key>
    <string>text.html.##LANGUAGE IDENTIFIER##</string>
 
    <key>uuid</key>
    <string>##UNIQUE UUID##</string>
  </dict>
</plist>

I have included some ##PLACEHOLDERS## in the above skeleton which are not part of the PLIST language, but I will use them in the text below to indicate what goes where.

The structure of the PLIST file is basically an outer <dict>...</dict> containing multiple <key>...</key> and <string>...</string> tags, where the key contains names that SublimeText needs to recognise to identify what is contained in the next string (or other) tag.

This is fine for some instances, but in a number of cases the key requires multiple values. In the skeleton, we can see that this is achieved for the <key>fileTypes</key> by adding the strings inside <array>...</array> tags.

<key>name</key>

The name key and associated string entity appears once within a <dict> entity, and is used to give a unique name to the <dict> in which it exists. In our skeleton, the outermost <dict> will be identified by the name that we give for ##LANGUAGE NAME##.

myLang - a fictional language

To fill out the ##PLACEHOLDER## tags, we need to agree some parameters for our new language syntax.

  1. we need a name for the language, so let's call it: myLang
  2. is myLang a scripting language (like PHP, javascript, etc.) or a markup language (like HTML, XML, etc.). Let's say myLang is a markup language.
  3. what file extension will myLang files have when stored on disk. Let's use: .mylang

Now we can complete the ##PLACEHOLDERS## in the skeleton.

##LANGUAGE NAME##

<key>name</key>

The name key specifies the string for our syntax language that will be shown in the Syntax list within SublimeText.

##FILE EXTENSION##

We have already decided on a file extension, so just replace the placeholder with the correct value.

  <string>myLang</string>

Notice that you do not include the dot . in the file extension.

##UNIQUE UUID##

FIXME

Comments



U​ K D D Q V Q S​ Y C N I
blog/2013/06/creating-a-new-sublimetext-3-syntax-highlighting-language.txt · Last modified: 15/06/2013 16:30 (external edit)