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
|
unit ContextHL;
(*
This is an example how to implement your own highlighter.
This example extends the Simple HL:
- The token -- and ++ (must be surrounded by space or line-begin/end to be
a token of their own) will toggle words that start with a,e,i,o,u
Multply ++ and -- can be nested. Then for each -- a ++ must be given,
before the words highlicht again
See comments below and http://wiki.lazarus.freepascal.org/SynEdit_Highlighter
*)
{$mode objfpc}{$H+}
interface
uses
SynEditHighlighter, SimpleHl;
type
{ TSynDemoHlContext }
TSynDemoHlContext = class(TSynDemoHl)
protected
FCurRange: Integer;
public
procedure Next; override;
function GetTokenAttribute: TSynHighlighterAttributes; override;
public
procedure SetRange(Value: Pointer); override;
procedure ResetRange; override;
function GetRange: Pointer; override;
end;
implementation
{ TSynDemoHlContext }
procedure TSynDemoHlContext.Next;
begin
inherited Next;
if (copy(FLineText, FTokenPos, FTokenEnd - FTokenPos) = '--') then
inc(FCurRange);
if (copy(FLineText, FTokenPos, FTokenEnd - FTokenPos) = '++') and (FCurRange > 0) then
dec(FCurRange);
end;
function TSynDemoHlContext.GetTokenAttribute: TSynHighlighterAttributes;
begin
Result := inherited GetTokenAttribute;
if (Result = SpecialAttri) and (FCurRange > 0) then
Result := IdentifierAttribute;
end;
procedure TSynDemoHlContext.SetRange(Value: Pointer);
begin
// Set the current range (for current line)
// The value is provided from an internal storage, where it was kept since the last scan
// This is the and value of the previous line, which is used as start for the new line
FCurRange := PtrInt(Value);
end;
procedure TSynDemoHlContext.ResetRange;
begin
FCurRange := 0;
end;
function TSynDemoHlContext.GetRange: Pointer;
begin
// Get a storable copy of the cuurent (working) range
Result := Pointer(PtrInt(FCurRange));
end;
end.
|