Skip to content

LangDefs Quick Start

tajmone edited this page Jan 11, 2019 · 1 revision
Highlight v3.48

A Quick-Start Guide to Language Definitions

This page provides some helpful information on how to start working on your first Highlight syntax definition.


Table of Contents


Introduction

Highlight language definitions are Lua scripts defining the various elements of a syntax. You'll find all the language definition files that ship with Highlight inside the langDefs subfolder of your local Highlight installation folder.

You can also view the contents of that folder on Highlight repository:

Editor Setup

You should configure your code editor to associate the .lang and .theme extension to the Lua language, for language definitions, themes and plugin files are just plain Lua scripts (plugins retain the .lua extension).

If your editor doesn't natively support Lua you should look for an addon to enable Lua support, or find a dedicated Lua editor. You can find a comprehensive list of Lua IDEs and editors addons at:

Highlight uses Lua 5.3, so you might want to check that the editor correctly supports that version of the language — i.e. if the editor offers code validation, linting and other useful functionality which might come handy, especially if you write custom hook functions in language definitions, or create Highlight plugins.

But ultimately, any plain text editor will do — language definitions don't require full fledged Lua programming, you'll be just defining some variables, lists, tables, strings and regular expressions; but sometimes you'll need to write custom hook functions to implement advanced functionality. Nevertheless, an editor supporting syntax highlighting of Lua code will make your work more pleasant; and if the editor can spot problems in the code for you that's an added bonus.

LangDef Boilerplates

In the langDefs-resources/ folder of Highlight you'll find two language definitions boilerplates which you can use as blueprints to write your custom syntax:

Both boilerplates are intended as a starting point to build your own custom language definition, but they offer two different approaches:

  • The template.lang boilerplate offers an "example based" approach: all possible syntax elements definitions are provided with some dummy values or useful presets. Ideal for newbies to Highlight langDefs.
  • The cleanslate.lang boilerplate is based on a "clean slate" approach: all possible syntax elements definitions are present, but they are set to a never matching regular expression, so nothing gets highlighted. Ideal for experienced langDef developers who just need a skeleton to build upon, starting from the ground up.

In other words, the "template" is a working syntax example, based on common presets which you then edit and adapt to your language; the "cleanslate" is a syntax that doesn't match anything, allowing you to introduce one element at the time.

Both boilerplates contain comments with useful hints and reminders on each syntax element, but in template.lang the help is more extensive and also provides lookup links for various topics. So, if you're creating your first language definition, you should consider using template.lang.

Full usage instructions on how to use them can be found in the comments inside the boilerplates sources.

Related Wiki Pages

Clone this wiki locally