SynEdit Highlighter TextMate

From Lazarus wiki
Jump to navigationJump to search
Light bulb  Note: This page is about the TSynTextMateSyn Highlighter in SynEdit and in the IDE.
Light bulb  Note: Lazarus 3.99 and up only


About

SynEdit supports highlighting based on TextMate grammar (as also used by VSCode).

Supported Grammar

The general documentation can be found with the TextMate project.

Match

Patterns defined using "Match" should fully work.

Begin , End

Patterns defined using "Begin" / "End" should fully work.

applyEndPatternLast

Should work.

Back-references in "End" patterns

According to the documentation those shall refer to capture groups in the "Begin" pattern.

This feature has experimental support.


While

Patterns defined using "while" / "end" will be accepted, but may not work. The original project supplies no documentation about them (other than that they exist).

Captures

Should work. The original project supplies no documentation on resolving conflicts. There may be differences in behaviour.

Regular expressions

Are based on TRegExpr (as in the fpc distro, but updated).


Adapting an existing Grammar

The below list is work in progress. Issue may/will be discovered/documented/fixed as the feature gets used.

"sampleText":

For the IDE color configurator:

   {
      "sampleText": "dorem ipsum foo bar"
   }

unsupported regex

The HL will return errors for them. The IDE can display them in Tools > Options: Editor > Display > Color > TML Setup

- [:alpha:] style groups are not supported

- Unicode features are limited/unavailable (depends on support by TRegExpr, when compiled for non-widestring).

Replacing "while" patterns

As needed...

Color names / Scopes

The IDE will display a configuration for each individual scope.

Unlike VSCode a color can not be defined for multiple scopes at once by matching them. It is therefore advisable to reduce the amount of scopes to whatever is really needed.

Some grammar may have different scope names for opening/closing brackets (or quotes). This interferes with SynEdits logic, which insists that matchig brackets (for highlighting, when at caret) must have the same scope. Scopes for open/closing brackets/quotes/... should be changed to have the same name.

IDE

To use a grammar file in the IDE copy it into the subfolder userschemes/tml in the primary-config-path.

The IDE will list the files under Tools > Options: Editor > Display > Color > TML Setup - Part 1: files currently loaded and active. - Part 2: files currently in the folder.

The active files (that can be chosen as HL) will only be loaded at IDE startup.

The "Reload" button will reload the files in the folder, but **not** make them active. It will merely show if they could be parsed, or do have errors. Once errors are removed the IDE must be restarted to use them.