Unfortunately it is not the Highlighters job.
The highlighter is doing the basic parsing. Though the line is not 100% clear in this case. But the Markup is match better suited.
The Paint class paints the text token by token. It pulls them from the HL but they have a long way.
unit LazSytTextArea
function TLazSynPaintTokenBreaker.GetNextHighlighterTokenFromView(out
ATokenInfo: TLazSynDisplayTokenInfoEx; APhysEnd: Integer; ALogEnd: Integer): Boolean;
...
function MaybeFetchToken: Boolean; inline;
begin
....
while FCurViewToken.TokenLength = 0 do begin // Todo: is SyncroEd-test a zero size token is returned
Result := FDisplayView.GetNextHighlighterToken(FCurViewToken);
FDisplayView is a TLazSynDisplayView
It comes from the Highlighter and passes through the TextBuffer and various Views (such as FoldedView). On each step it can be modified, or even tokens be added.
unit LazSytTextArea
function TLazSynPaintTokenBreaker.GetNextHighlighterTokenEx(out
ATokenInfo: TLazSynDisplayTokenInfoEx): Boolean;
...
FMarkupManager.GetNextMarkupColAfterRowCol(FCurTxtLineIdx+1,
Calls the markup manager, to apply final markup.
This includes selection, visible whitespace-color, current word markup, ....
Now nested begin end can be seen as pascal grammar specific, but the kind of markup can work with any HL that has folding. It could work with LFM too.
So it really should be in a Markup.
Also you have markup on lines that between the keywords. The HL has no business to calculate them, and the painter should neither. This calculation goes into the Markup class.
--------------
The markup can and should find all blocks surrounding the line currently painted.
It can then:
- modify tokens for begin/end (as SynEditMarkupWordGroup does)
- modify tokens on the line between, that need a vertical line.
--------------
When this works there may be a need to add things to the painter, because if a vertical line is dotted or dashed, it will not look good. A new fragment of it is painted for each text line, and that resets the dotted pattern.
This needs to be fixed in the painter, but this is for the very end.