Skip to content
This repository was archived by the owner on Nov 19, 2019. It is now read-only.

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Swift Mode Tutorial Step 1

Getting Started

The first step in creating a custom mode for a language or filetype is to gather information and create your .seemode bundle.

Creating the mode bundle

The minimal information you need to create your bundle is the name of your mode and the file extensions files of that type can have. In our case that is simple. Our mode shall be called Swift and the only extension Swift currently employs is .swift.

Having gathered this minimal information we can go ahead and use the nice CreateModeBundle.rb helper script to generate a skeleton mode bundle. During development time I recommend to work in the User Modes directory of your SubEthaEdit - if you are familiar with versioning you should also make the modes directory a git repository so your changes don't get lost.

The quickest way to get to that directory is via the mode menu of SubEthaEdit. Hold the option button, click the Mode menu and go to the Open User Modes Folder Item all the way at the bottom of the Show in Finder submenu.

This opens your User Modes folder in the finder. If not already open, open your Terminal.app and drag the little folder icon in the finder's window title onto the Terminal.app icon in the Dock. This conveniently opens up this directory in a new Terminal window.

Now you can go ahead and use our little helper script to generate the .seemode Bundle

ruby -e "$(curl -fsSL https://raw.github.com/codingmonkeys/SubEthaEdit/master/bin/CreateModeBundle.rb)" Swift swift

This creates your Mode Skeleton for our new Swift.seemode and also conveniently opens it's contents in a new finder window.

Switch the finder into list view and do an option-click on the little triangle in front of Resource to unfold it's directory structure.

Now go back to SubEthaEdit and click the Reload Modes item in the Modes menu. The Swift mode should now appear in the Modes menu and also in the File -> New submenu.

Gathering examples

Now that we have verfied the mode is in the right place and we can generate and save files of that type, it is time to collect some basic sample code and paste it into the ExampleSyntax.swift file so we have something to work with. This file is shown to the User in the Styles Preferences of SubEthaEdit. And for us it should be a meaningful collection of elements of the language that we want to highlight and recognize.

As a rule of thumb I would recommend searching the net for suitable sample code, maybe even reference code from other highlighters. Since Swift is quite a new language, let's go with some Apple Sample code for now.

As the skeleton already imports some basic states from other languages as example, you can see that numbers, comments, strings and function calls already have a little bit of highlighting.

In the next step we will add the basic language keywords and constructs to the SyntaxDefinition.xml file. However, to do that we actually need to know the exact definition of all of these. Luckily for us Swift has quite a nice iBook which also has a nice HTML variant that describes all this in detail. For other languages you'll need to get prepared and find a good resource for it. It's often astounding what you can learn about a language when making a mode for it.

Overview - Step 2 - Basic Language Features