Ok, I made quite some changes....
First of all, I realized the tutorial has a flaw.
In real live, when you write a HL based on ContextHl, you do not want to inherit from SimpleHL. You want the 2 classes be merged into one single class.
In the example it is not a problem, because the changes are very small. But in real live you want one HL that has you full logic in it. Not distribute your logic over several classes.
So ContextHL should be
TSynDemoHlContext = class(TSynCustomHighlighter)
And the code from SimpleHL should be copied into it.
If I find time, I will improve the tutorial. But that may be a good while before it happens.
I did not fix that for your example either.
I do recommend you merge the 2 classes. But all your code into ContextHL.
I dropped the 2 variables, and kept the state in a set.
That set will also represent whatever the current token should be.
SynEdit uses the methods
function GetToken: String; virtual; abstract;
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); virtual; abstract;
function GetEndOfLineAttribute: TSynHighlighterAttributes; virtual; // valid after line was scanned to EOL
function GetTokenAttribute: TSynHighlighterAttributes; virtual; abstract;
function GetTokenKind: integer; virtual; abstract;
function GetTokenPos: Integer; virtual; abstract; // 0-based
to find out what attributes to use for each token, and where it start and ends.
SynEdit loops for each line approx like
while not HL.GetEOL do begin
hl.GetTokenEx
hl.GetTokenAttribute
hl.next
end
For a line like
" abc [bb] def"
this would get the following tokens
" abc " textAttri
"[" bracketAttri
"bb" chordAttri
"]" bracketAttri
" def" textAttri
Hope that explains a bit of how it works