Menu

[r2903]: / trunk / Src / Hiliter.UGlobals.pas  Maximize  Restore  History

Download this file

196 lines (178 with data), 8.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
{
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/
*
* Copyright (C) 2005-2013, Peter Johnson (www.delphidabbler.com).
*
* $Rev$
* $Date$
*
* Declares various types that describe syntax hilighters and and defines
* interfaces to various syntax highlighters and highlighter attributes.
}
unit Hiliter.UGlobals;
interface
uses
// Delphi
Classes, Graphics,
// Project
UEncodings;
type
/// <summary>Enumeration defining the different elements that can be
/// highlighted in Pascal source code.</summary>
THiliteElement = (
heWhitespace, // white space
heComment, // comments: in (* .. *), { .. } or // styles
heReserved, // reserved word (keyword or directives)
heIdentifier, // an identifier that is not "reserved"
heSymbol, // punctuation symbol or symbol group
heString, // string or character literal preceeded by #
heNumber, // whole number
heFloat, // floating point number (may be in scientific format)
heHex, // hexadecimal integer
hePreProcessor, // compiler directive: {$..} and (*$..*) styles supported
heAssembler, // assembler code between asm ... end keywords
heError // an unrecognised piece of code (shouldn't happen)
);
type
/// <summary>Interface supported by objects that store style attributes
/// applicable to various source code elements used in syntax highlighting.
/// </summary>
IHiliteElemAttrs = interface(IInterface)
['{297A2F3D-77A8-45F9-A147-22A53791F114}']
/// <summary>Checks whether an element's attributes are "null" - i.e. all
/// properties have default values.</summary>
/// <remarks>Use to determine whether to output formatting information for
/// an element or not.</remarks>
function IsNul: Boolean;
/// <summary>Returns the font style to use for a source code element.
/// </summary>
function GetFontStyle: TFontStyles;
/// <summary>Sets the font style to use for a source code element.
/// </summary>
/// <param name="AFontStyle">TFontStyles [in] Required font style.</param>
procedure SetFontStyle(const AFontStyle: TFontStyles);
/// <summary>Returns the foreground (i.e. text) colour to use for a source
/// code element.</summary>
function GetForeColor: TColor;
/// <summary>Sets the foreground (i.e. text) colour to use for a source
/// code element.</summary>
/// <param name="AColor">TColor [in] Required colour.</param>
procedure SetForeColor(const AColor: TColor);
/// <summary>Set of font styles to use for a source code element.</summary>
property FontStyle: TFontStyles read GetFontStyle write SetFontStyle;
/// <summary>Foreground (i.e. Text) colour to use for a source code
/// element.</summary>
property ForeColor: TColor read GetForeColor write SetForeColor;
end;
type
/// <summary>Interface implemented by objects that store style attributes
/// that are used in a syntax highlighter.</summary>
IHiliteAttrs = interface(IInterface)
['{25570AEE-3225-42A7-A534-3D27357EEA2E}']
/// <summary>Returns name of font to use for all source code.</summary>
function GetFontName: string;
/// <summary>Sets name of font to use for all source code.</summary>
/// <param name="AFontName">string [in] Name of required font.</param>
procedure SetFontName(const AFontName: string);
/// <summary>Returns size of font to use for all source code.</summary>
/// <remarks>Font size is in points.</remarks>
function GetFontSize: Integer;
/// <summary>Sets size of font to use for all source code.</summary>
/// <param name="AFontSize">Integer [in] Required font size in points.
/// </param>
procedure SetFontSize(const AFontSize: Integer);
/// <summary>Resets name and size of font used for all source code to
/// default value.</summary>
procedure ResetDefaultFont;
/// <summary>Returns style attributes for a source code element.</summary>
/// <param name="Elem">THiliteElement [in] Specifies required attribute.
/// </param>
/// <returns>IHiliteElemAttrs [in] Interface to object providing required
/// style attributes.</returns>
function GetElement(const Elem: THiliteElement): IHiliteElemAttrs;
/// <summary>Name of font used for all source code.</summary>
property FontName: string read GetFontName write SetFontName;
/// <summary>Size of font used for all soure code.</summary>
property FontSize: Integer read GetFontSize write SetFontSize;
/// <summary>List of style attributes for each source code element.
/// </summary>
property Elements[const Elem: THiliteElement]: IHiliteElemAttrs
read GetElement; default;
end;
type
/// <summary>Enumeration of identifiers for the various predefined
/// highlighter styles.</summary>
TPredefinedHiliteStyle = (
hsNul, // nul highlighter style
hsCodeSnip, // original codesnip default style
hsDelphi7, // Delphi 7 default style
hsRADStudio, // RAD Studio default style
hsVisualStudio // Microsoft Visual Studio default style
);
type
/// <summary>Interface implemented by objects that format different source
/// code elements on behalf of syntax highlighter.</summary>
/// <remarks>Implement this interface for each required output format.
/// Syntax highlighter calls the methods of this interface.</remarks>
IHiliteRenderer = interface(IInterface)
['{791CE200-C614-40FC-B93D-744ED2984755}']
/// <summary>Called by syntax highlighter before any source code is
/// processed.</summary>
procedure Initialise;
/// <summary>Called by syntax highlighter after all source code has been
/// processed.</summary>
procedure Finalise;
/// <summary>Called by syntax highlighter when a new line of source code
/// is started.</summary>
procedure BeginLine;
/// <summary>Called by syntax highlighter after a line of souce code is
/// complete.</summary>
procedure EndLine;
/// <summary>Called by syntax highlighter just before a source code
/// element is to be output.</summary>
/// <param name="Elem">THiliteElement [in] Type of element to be output.
/// </param>
procedure BeforeElem(Elem: THiliteElement);
/// <summary>Called by syntax highlighter for each element of source code
/// read. All the given text should be formatted in same style.</summary>
/// <remarks>Type of the element will have been specified in prior call to
/// BeforeElem.</remarks>
procedure WriteElemText(const Text: string);
/// <summary>Called by syntax highlighter just after an element of source
/// code has been written.</summary>
/// <param name="Elem">THiliteElement [in] Type of element that has just
/// been output.</param>
procedure AfterElem(Elem: THiliteElement);
end;
type
/// <summary>Interface implemented by objects that manage a list of named
/// syntax highlighter attributes.</summary>
INamedHiliteAttrs = interface(IInterface)
['{6F18CD62-111A-4CE8-924C-88DE7D82A19F}']
/// <summary>Getter for Hiliters property.</summary>
function GetHiliter(const Name: string): IHiliteAttrs;
/// <summary>Setter for Hiliters property.</summary>
procedure SetHiliter(const Name: string; Hiliter: IHiliteAttrs);
/// <summary>Getter for Names property.</summary>
function GetNames: TArray<string>;
/// <summary>Deletes highlighter attributes with given name.</summary>
procedure Delete(const Name: string);
/// <summary>Clears list of highlighter attributes.</summary>
procedure Clear;
/// <summary>Checks if highlighter attributes with given name exists.
/// </summary>
function Contains(const Name: string): Boolean;
/// <summary>Checks if list is empty.</summary>
function IsEmpty: Boolean;
/// <summary>Map of highlighter names to associated highlighter attributes.
/// </summary>
property Hiliters[const Name: string]: IHiliteAttrs
read GetHiliter write SetHiliter; default;
/// <summary>Array of highlighter names.</summary>
property Names: TArray<string>
read GetNames;
end;
implementation
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.