Create your Highlighter
There are three ways to get a highlighter for a language that is not in the list:
TSynGeneralSyn(andTSynOmniSyn): configurable highlighters. You define keywords, comments and strings with properties, without writing code.- SynGen: a generator that creates the source of a highlighter from a grammar file.
- Write the unit by hand, deriving from
TSynCustomHighlighter(or fromTSynCustomCodeFoldingHighlighterif the language has foldable blocks): the easiest way is to start from the source of a similar highlighter.
SynGen
SynGen is in the SynGen folder of the library (SynGen.dpr). It reads a grammar file (.msg) and generates the unit of a highlighter. For simple keyword based highlighters the result can be used as it is; for the others it is the starting point.
The grammar file
Text between { and } is a comment. The first lines are:
- the name of the class of the highlighter (for example
TSynSampleSyn); - the prefix of the enumeration of the token types (
tkin all the highlighters of the library); - the characters that can start and compose an identifier.
Then come the sections: TOKENTYPES, KEYS, CHARS, and the ENCLOSEDBY ones for comments and strings. A sample:
TSynSampleSyn {first Identifier is considered to be the Class Name }
tk {second Identifier is considered to be the Identifier Prefix }
IdentStart '_', 'a'..'z', 'A'..'Z':: '_', '0'..'9', 'a'..'z', 'A'..'Z'::
TOKENTYPES
Identifier
Comment Style=[fsItalic]|Foreground=clNavy
Space
String Foreground=clRed
Key Style=[fsBold]
Test Background=clSilver|Foreground=clBlue|Style=[fsUnderline, fsItalic]
|><|
KEYS
Hello
World
|><|
KEYS Test
SynEdit
|><|TOKENTYPESlists the kinds of tokens, each one with its default attributes (Style,Foreground,Background).KEYSlists the keywords of a token type (KEYSis theKeytype,KEYS TesttheTesttype).CHARSlinks the characters to the procedures that read the tokens.
The full description of the format is in the document SynGen\Highlighters-HowTo.htm.
Generated unit names
The unit generated by SynGen has to follow the naming rule of Ethea SynEdit: SynEdit.Highlighter.<Language>. Rename the generated file and the unit clause accordingly, and add it to the packages if you want it in the library.
Demo
See the Highlighter demo, which uses a grammar file to build a sample highlighter.
