Skip to content

[PATCH] allow a tokeniser to use TStrings if it wants to #187

@andrewd207

Description

@andrewd207

I started writing a sort of code aware parser to see if I could but it uses the text of the edit directly.
Yours is much faster 😄 But anyway, maybe it doesn't hurt to be able to use the Lines directly. By default it calls Tokenise(Lines.Text) so there's no fundamental change.

As a postscript, The one I wrote is keeping track of the state and reporting errors it finds. I'll share it in the coming days.

diff --git a/ide/src/main/pascal/ide.highlight.renderer.pas b/ide/src/main/pascal/ide.highlight.renderer.pas
index d4ece69a..c0da9912 100644
--- a/ide/src/main/pascal/ide.highlight.renderer.pas
+++ b/ide/src/main/pascal/ide.highlight.renderer.pas
@@ -154,7 +154,7 @@ procedure THighlighterCache.EnsurePascalTokenised(AEditor: TObject; ALines: TStr
   begin
     FPascalEditor := AEditor;
     if Assigned(ALines) then
-      FPascalHighlighter.Tokenise(ALines.Text);
+      FPascalHighlighter.Tokenise(ALines);
   end;
 end;
 
diff --git a/ide/src/main/pascal/ide.highlighter.pas b/ide/src/main/pascal/ide.highlighter.pas
index 446ca200..a36674de 100644
--- a/ide/src/main/pascal/ide.highlighter.pas
+++ b/ide/src/main/pascal/ide.highlighter.pas
@@ -83,10 +83,12 @@   TEditorHighlighter = class(TObject)
     procedure AddToken(ALine, AColumn, ALength: Integer; ACategory: THighlightCategory);
     procedure EnsureLineCount(ACount: Integer);
     procedure DoTokenise(const AText: string); virtual; abstract;
+    procedure DoTokenise(const ALines: TStrings); virtual;
   public
     constructor Create; virtual;
     destructor Destroy; override;
     procedure Tokenise(const AText: string);
+    procedure Tokenise(const ALines: TStrings);
     function LineCount: Integer;
     function GetLineTokens(ALine: Integer): THighlightTokenArray;
     function GetLineTokenCount(ALine: Integer): Integer;
@@ -157,6 +159,11 @@ procedure TEditorHighlighter.EnsureLineCount(ACount: Integer);
   end;
 end;
 
+procedure TEditorHighlighter.DoTokenise(const ALines: TStrings);
+begin
+  DoTokenise(ALines.Text);
+end;
+
 procedure TEditorHighlighter.AddToken(ALine, AColumn, ALength: Integer;
   ACategory: THighlightCategory);
 var
@@ -186,6 +193,13 @@ procedure TEditorHighlighter.Tokenise(const AText: string);
     DoTokenise(AText);
 end;
 
+procedure TEditorHighlighter.Tokenise(const ALines: TStrings);
+begin
+  ClearLines;
+  if ALines.Count > 0 then
+    DoTokenise(ALines);
+end;
+
 function TEditorHighlighter.LineCount: Integer;
 begin
   Result := FLines.Count;

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions