summaryrefslogtreecommitdiff
path: root/examples/apps/ide
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graeme@mastermaths.co.za>2011-08-11 00:43:50 +0200
committerGraeme Geldenhuys <graeme@mastermaths.co.za>2011-08-11 00:43:50 +0200
commit66e27c681a2c3155e84d3c1101b939d7ba702b33 (patch)
treea023cd237f4b2523f95789469a8e856edcfbd35e /examples/apps/ide
parentb3c343d81685b2a8bc46b26ca524a0bf95cc5804 (diff)
downloadfpGUI-66e27c681a2c3155e84d3c1101b939d7ba702b33.tar.xz
ide: improved syntax highlighting, and extending it.
We now support comments correctly, compiler defines, strings, decimal and hex numbers.
Diffstat (limited to 'examples/apps/ide')
-rw-r--r--examples/apps/ide/src/frm_main.pas117
1 files changed, 88 insertions, 29 deletions
diff --git a/examples/apps/ide/src/frm_main.pas b/examples/apps/ide/src/frm_main.pas
index 36b3e473..8bab2913 100644
--- a/examples/apps/ide/src/frm_main.pas
+++ b/examples/apps/ide/src/frm_main.pas
@@ -142,14 +142,23 @@ const
cProjectFiles = '*.project';
{ nicely working so far }
- cKeywords = '\b(begin|end|read|write|with|try|finally|except|uses|interface'
+ cKeywords1 = '\b(begin|end|read|write|with|try|finally|except|uses|interface'
+ '|implementation|procedure|function|constructor|destructor|property|operator'
+ '|private|protected|public|published|type|virtual|abstract|overload'
- + '|override|class|unit|program|set|of|if|then|for|downto|to|as|div|mod'
+ + '|override|class|unit|program|library|set|of|if|then|for|downto|to|as|div|mod|shr|shl'
+ '|do|else|while|and|inherited|const|var|initialization|finalization'
- + '|on|or|in|raise|not|case|record|array|out|resourcestring|default)\b'; //[^0-9a-zA-Z:=;\)\( ]*';
+ + '|on|or|in|raise|not|case|record|array|out|resourcestring|default'
+ + '|xor|repeat|until|constref|stdcall|cdecl|external)\b';
- cComments1 = '(\s*\/\/.*$)|(\s*\{.*\})';
+ cComments1 = '(\s*\/\/.*$)|(\{[^\{]*\})';
+ cComments2 = '\{[^\{]*\}';
+
+ cDefines1 = '\{\$[^\{]*\}';
+
+ cString1 = '''.*''';
+
+ cDecimal = '\b(([0-9]+)|([0-9]+\.[0-9]+([Ee][-]?[0-9]+)?))\b';
+ cHexidecimal = '\b\$[0-9a-fA-F]*\b';
{@VFD_NEWFORM_IMPL}
@@ -667,7 +676,7 @@ begin
if not Assigned(FKeywordFont) then
FKeywordFont := fpgGetFont(edt.FontDesc + ':bold');
ACanvas.Font := FKeywordFont;
- FRegex.Expression := cKeywords;
+ FRegex.Expression := cKeywords1;
FRegex.ModifierI := True;
if FRegex.Exec(ALineText) then
begin
@@ -683,38 +692,89 @@ begin
until not FRegex.ExecNext;
end;
- { syntax highlighting for: comments }
ACanvas.Font := oldfont;
+
+ { syntax highlighting for: cDecimal }
+ ACanvas.TextColor := clNavy;
+ FRegex.Expression := cDecimal;
+ if FRegex.Exec(ALineText) then
+ begin
+ repeat
+ lMatchPos := FRegex.MatchPos[0];
+ lOffset := FRegex.MatchLen[0];
+ s := FRegex.Match[0];
+ j := Length(s);
+ r.SetRect(ATextRect.Left + (edt.FontWidth * (lMatchPos-1)), ATextRect.Top,
+ (edt.FontWidth * j), ATextRect.Height);
+ ACanvas.FillRectangle(r);
+ ACanvas.DrawText(r, s);
+ until not FRegex.ExecNext;
+ end;
+
+ { syntax highlighting for: comments2 }
ACanvas.TextColor := clDarkCyan;
- FRegex.Expression := cComments1;
+ FRegex.Expression := cComments2;
if FRegex.Exec(ALineText) then
begin
- if FRegex.SubExprMatchCount = 0 then
- begin
- i := 0;
- lMatchPos := FRegex.MatchPos[i];
- lOffset := FRegex.MatchLen[i];
- s := FRegex.Match[i];
+ repeat
+ lMatchPos := FRegex.MatchPos[0];
+ lOffset := FRegex.MatchLen[0];
+ s := FRegex.Match[0];
j := Length(s);
r.SetRect(ATextRect.Left + (edt.FontWidth * (lMatchPos-1)), ATextRect.Top,
(edt.FontWidth * j), ATextRect.Height);
ACanvas.FillRectangle(r);
ACanvas.DrawText(r, s);
- end
- else
- begin
- for i := 1 to FRegex.SubExprMatchCount do
- begin
- lMatchPos := FRegex.MatchPos[i];
- lOffset := FRegex.MatchLen[i];
- s := FRegex.Match[i];
- j := Length(s);
- r.SetRect(ATextRect.Left + (edt.FontWidth * (lMatchPos-1)), ATextRect.Top,
- (edt.FontWidth * j), ATextRect.Height);
- ACanvas.FillRectangle(r);
- ACanvas.DrawText(r, s);
- end;
- end;
+ until not FRegex.ExecNext;
+ end;
+
+ { syntax highlighting for: cDefines1 }
+ ACanvas.TextColor := clRed;
+ FRegex.Expression := cDefines1;
+ if FRegex.Exec(ALineText) then
+ begin
+ repeat
+ lMatchPos := FRegex.MatchPos[0];
+ lOffset := FRegex.MatchLen[0];
+ s := FRegex.Match[0];
+ j := Length(s);
+ r.SetRect(ATextRect.Left + (edt.FontWidth * (lMatchPos-1)), ATextRect.Top,
+ (edt.FontWidth * j), ATextRect.Height);
+ ACanvas.FillRectangle(r);
+ ACanvas.DrawText(r, s);
+ until not FRegex.ExecNext;
+ end;
+
+ { syntax highlighting for: cString1 }
+ ACanvas.TextColor := clOlive;
+ FRegex.Expression := cString1;
+ if FRegex.Exec(ALineText) then
+ begin
+ repeat
+ lMatchPos := FRegex.MatchPos[0];
+ lOffset := FRegex.MatchLen[0];
+ s := FRegex.Match[0];
+ j := Length(s);
+ r.SetRect(ATextRect.Left + (edt.FontWidth * (lMatchPos-1)), ATextRect.Top,
+ (edt.FontWidth * j), ATextRect.Height);
+ ACanvas.FillRectangle(r);
+ ACanvas.DrawText(r, s);
+ until not FRegex.ExecNext;
+ end;
+
+ { syntax highlighting for: comments1 }
+ ACanvas.TextColor := clDarkCyan;
+ FRegex.Expression := cComments1;
+ if FRegex.Exec(ALineText) then
+ begin
+ lMatchPos := FRegex.MatchPos[1];
+ lOffset := FRegex.MatchLen[1];
+ s := FRegex.Match[1];
+ j := Length(s);
+ r.SetRect(ATextRect.Left + (edt.FontWidth * (lMatchPos-1)), ATextRect.Top,
+ (edt.FontWidth * j), ATextRect.Height);
+ ACanvas.FillRectangle(r);
+ ACanvas.DrawText(r, s);
end;
ACanvas.Font := oldfont;
@@ -738,7 +798,6 @@ begin
// apply editor settings
pcEditor.TabPosition := TfpgTabPosition(gINI.ReadInteger(cEditor, 'TabPosition', 0));
FRegex := TRegExpr.Create;
- FRegex.Expression := cKeywords;
TextEditor.Clear;
TextEditor.SetFocus;