TSynAnySyn highlighter for any language

Jan Verhoeven - Januari 2001, website email

syntax

Introduction

TSynEdit comes with many highlighters, including a general highlighter where you can define your own keywords. TSynAnySyn is a descendant of TSynCustomHighlighter that allows the end user of a program to define his or her own highlighter properties in a .ini file and load it into TSynAnySyn.

Besides a list of keywords you can also define a list of constants and objects that can have their own highlighting attributes.

The component comes with some ready to use highlighter files for most commonly used programming languages.

Installation

Copy SynHighlighterAny.pas to your SynEdit source directory. Add TSynAnySyn to the SynEdit package and include registration in the SynEditReg.pas file. Also add the TSYNANYSYN bitmap to SynEditReg.dcr

Component Reference

Only additional methods and properties are shown.

TSynAnySyn is based on TSynCustomHighlighter.

Methods

LoadHighlighter

procedure LoadHighlighter(AFile:string);

Loads the highlighter from a .ini file. See syntax for details on creating a highlighter file.

Properties

ActiveDot:boolean

When ActiveDot is true properties and methods of objects after the dot are highlighted, e.g. myobject.method

ConstantAttri:TSynHighlighterAttributes

Holds the attributes for constant words defined in the Constants property.

Constants:TStrings

Holds the words defined as constants.

DollarVariables:boolean

When DollarVariables is true symbols preceeded by the sign will be highlighted using the VariableAttri settings. You can use this for variable highlighting in languages like php and perl

DotAttri:TSynHighlighterAttributes

Holds the attributes for objects properties and methods after a dot character, in case Activedot is true.

Entity:boolean

When Entity is true entity symbols like & will be highlighted. You can use this for e.g. HTML and XML highlighting.

EntityAttri:TSynHighlighterAttributes

Holds the attributes for Entities when the Entity property is true.

IdentifierAttri:TSynHighlighterAttributes

Holds the attributes for identifiers, symbols that begin with a letter and are followed by more letters or figures.

KeyAttri:TSynHighlighterAttributes

Holds the attributes for keyword words defined in the Keywords property.

Keywords:TStrings

Holds the words defined as keywords.

Markup:boolean

When markup is true, words between < and > will be highlighted. You can use this for markup languages liken HTML, XML and XSLT

NumberAttri:TSynHighlighterAttributes

Holds the attributes for numbers

ObjectAttri:TSynHighlighterAttributes

Holds the attributes for object words defined in the Objects property.

Objects:TStrings

Holds the words defined as objects.

SpaceAttri:TSynHighlighterAttributes

Holds the attributes for spaces

StringAttri:TSynHighlighterAttributes

Holds the attributes for strings, double or single quoted depending on the StringDelim property.

StringDelim:[sdSingleQuote,sdDoubleQuote

Defines whether strings are single or double quoted.

SymbolAttri:TSynHighlighterAttributes

Holds the attributes for symbols like + and *.

VariableAttri:TSynHighlighterAttributes

Holds the attributes for vatiables, words preceeded by a $, in case DollarVariables is true.


Syntax of highlighter files

Highlighter files are .ini style files that the end user of your program can create in any text editor. In your program you can provide the option of loading such a file into TSynAnySyn using the LoadHighlighter method.

For colors you can use the Delphi color constants or a $BBGGRR (blue, green, red) color triplet.

For font style you can use normal or a (comma seperated) combination of bold, italic or underline. For example:

Style=bold,italic

For booleans you use true or false

Use the code below as the template for new highlighter files. It contains all available options.

[CommentStyle]
ansi=false
asm=false
bas=false
c=false
pas=false
vb=false

[String Delimiter]
Double Quotes=true

[Switches]
markup=false
entity=false
dollarvariables=false
ActiveDot=false

[Comment]
Foreground=clblue
Background=clwhite
Style=italic

[Constant]
Foreground=clblack
Background=clwhite
Style=bold

[Entity]
Foreground=clblack
Background=clwhite
Style=normal

[Identifier]
Foreground=clblack
Background=clwhite
Style=normal

[Dot]
Foreground=clblack
Background=clwhite
Style=normal

[Keywords]
Foreground=$FF0080
Background=clwhite
Style=bold

[Number]
Foreground=clblack
Background=clwhite
Style=normal

[Space]
Foreground=clblack
Background=clwhite
Style=normal

[String]
Foreground=$FF8000
Background=clwhite
Style=normal

[Symbol]
Foreground=clblack
Background=clwhite
Style=normal

[Object]
Foreground=clblack
Background=clwhite
Style=normal

[Variables]
Foreground=clpurple
Background=clwhite
Style=bold


[Objects]
object1
object2

[Constants]
constant1
constant2

[Keys]
key1
key2