UPDATE TIME!
Well, here it is after Christmas, and I'm here with another update. It's not a lot, but I figured you should have it. Here's a list of things I remembered doing to it:
Edit->Select All works now
Selected text is put into the fine/replace dialog when you do a search
Bracket matching! Please try and let me know how well it works on a large project.
Ability to turn off syntax highlighting (for those using screen reading software.)
Fixed problem of the dockable windows not reappearing with the view->
window command after they've been closed.
Added version information to the project manager so you can put all your cool company info, etc. in your final exe.
Added RGB color picker dialog. The keyboard shortcut is ctrl + i.
Added option for enabling/disabling the function parameter tooltip.
Added option to set the delay for the function tooltip
#constant and #gloabl now highlight
Then is now always highlighted, whether or not it happens to be in your keywords file. It seems that TGC have a bad habit of erasing it from the keywords file.
Known problems(off the top of my head):
Undo doesn't quite work right with the RGB color picker.
AS doesn't highlight properly sometimes. This is actually a very complex issue with the highlighting code. I can't tell you how many headaches DBP's multiple word keyword syntax has given me for highlighting.
Some people seem to not be getting their latest code compiled if they don't save first. I still don't know why.
I'm so close to a version 1.0 I can almost smell it.
I'm hoping the next update, I'll have all the features I want for 1.0, you guys test it, and then I'll post it over in program announcements.
Next update features:
CODE COMPLETION! It's almost there, just needs a little more work.
Fix known problems the best I can.
Printing support
Specify commandline parameters when you run your .exe so you can easily test if they work correctly.
A few more toolbar buttons for things like opening all files, etc.
@Phaelax,
Hmmm, I suppose I could if I have to.
I just don't like looking at the highlighting code any more than is absolutely necessary. Just for kicks, I'll post the main part of the highlighter code here:
{-------------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: SynHighlighterGeneral.pas, released 2000-04-07.
The Original Code is based on the mwGeneralSyn.pas file from the
mwEdit component suite by Martin Waldenburg and other developers, the Initial
Author of this file is Martin Waldenburg.
Portions written by Martin Waldenburg are copyright 1999 Martin Waldenburg.
All Rights Reserved.
Contributors to the SynEdit and mwEdit projects are listed in the
Contributors.txt file.
Alternatively, the contents of this file may be used under the terms of the
GNU General Public License Version 2 or later (the "GPL"), in which case
the provisions of the GPL are applicable instead of those above.
If you wish to allow use of your version of this file only under the terms
of the GPL and not to allow others to use your version of this file
under the MPL, indicate your decision by deleting the provisions above and
replace them with the notice and other provisions required by the GPL.
If you do not delete the provisions above, a recipient may use your version
of this file under either the MPL or the GPL.
$Id: SynHighlighterGeneral.pas,v 1.16 2005/01/28 16:53:22 maelh Exp $
You may retrieve the latest version of this file at the SynEdit home page,
located at http://SynEdit.SourceForge.net
Known Issues:
-------------------------------------------------------------------------------}
{
@Based off the SynHighlighterGeneral Class
@Modified by Hyrum Richter to create a highlighter for the DarkBASIC Programming language
@lastmod(Jan 2, 2006)
This file was last modified by Hyrum Richter on June 8, 2006 to create a syntax highlighter for the
DarkBASIC Professional language. It can also be used with other languages which have multiple word keywords.
}
{$IFNDEF QSYNHIGHLIGHTERGENERAL}
unit SynHighlighterGeneral;
{$ENDIF}
{$I SynEdit.inc}
interface
uses
{$IFDEF SYN_CLX}
QGraphics,
QSynEditTypes,
QSynEditHighlighter,
{$ELSE}
Windows,
Graphics,
SynEditTypes,
SynEditHighlighter,
{$ENDIF}
SysUtils,
Classes, Dialogs;
type TFunctionList = record
Title: string;
LineNum: integer;
end;
type
TtkTokenKind = (tkComment, tkIdentifier, tkKey, tkNull, tkNumber,
tkPreprocessor, tkSpace, tkString, tkSymbol, tkUnknown);
TCommentStyle = (csAnsiStyle, csPasStyle, csCStyle, csAsmStyle, csBasStyle,
csCPPStyle);
TCommentStyles = set of TCommentStyle;
TRangeState = (rsANil, rsAnsi, rsPasStyle, rsCStyle, rsMultiWord, rsUnKnown, rsDBStyle);
TStringDelim = (sdSingleQuote, sdDoubleQuote);
TProcTableProc = procedure of object;
type
TSynGeneralSyn = class(TSynCustomHighlighter)
private
fLine: PChar;
fProcTable: array[#0..#255] of TProcTableProc;
Run: LongInt;
fTokenPos: Integer;
fTokenID: TtkTokenKind;
fLineNumber : Integer;
fCommentAttri: TSynHighlighterAttributes;
fIdentifierAttri: TSynHighlighterAttributes;
fKeyAttri: TSynHighlighterAttributes;
fNumberAttri: TSynHighlighterAttributes;
fPreprocessorAttri: TSynHighlighterAttributes;
fSpaceAttri: TSynHighlighterAttributes;
fStringAttri: TSynHighlighterAttributes;
fSymbolAttri: TSynHighlighterAttributes;
fKeyWords: TStrings;
fComments: TCommentStyles;
fStringDelimCh: char;
fIdentChars: TSynIdentChars;
fDetectPreprocessor: boolean;
CommentBlock: boolean;
procedure DBProcedure;
procedure AsciiCharProc;
procedure BraceOpenProc;
procedure PointCommaProc;
procedure CRProc;
procedure IdentProc;
procedure IntegerProc;
procedure LFProc;
procedure NullProc;
procedure NumberProc;
procedure RoundOpenProc;
procedure SlashProc;
procedure SpaceProc;
procedure StringProc;
procedure UnknownProc;
procedure MakeMethodTables;
procedure AnsiProc;
procedure PasStyleProc;
procedure CStyleProc;
procedure DBCommentProc;
procedure SetKeyWords(const Value: TStrings);
procedure SetComments(Value: TCommentStyles);
function GetStringDelim: TStringDelim;
procedure SetStringDelim(const Value: TStringDelim);
function GetIdentifierChars: string;
procedure SetIdentifierChars(const Value: string);
procedure SetDetectPreprocessor(Value: boolean);
protected
function GetIdentChars: TSynIdentChars; override;
public
fRange: TRangeState;
arEntryPoints: array[1..26] of integer;
//arFunctionNames: array of TFunctionList;
//arFunctionLines: array of integer;
class function GetLanguageName: string; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function GetDefaultAttribute(Index: integer): TSynHighlighterAttributes;
override;
function GetEol: Boolean; override;
function GetRange: Pointer; override;
function GetTokenID: TtkTokenKind;
function GetToken: String; override;
function GetTokenAttribute: TSynHighlighterAttributes; override;
function GetTokenKind: integer; override;
function GetTokenPos: Integer; override;
function IsKeyword(const AKeyword: string): boolean; override;
function PossibleKeyword(text: string): boolean;
procedure UpdateKeywords;
procedure Next; override;
procedure ResetRange; override;
procedure SetRange(Value: Pointer); override;
procedure SetLine(NewValue: String; LineNumber: Integer); override;
procedure UpdateCodeExplorer(Line: string; LineNumber: integer);
{$IFNDEF SYN_CLX}
function SaveToRegistry(RootKey: HKEY; Key: string): boolean; override;
function LoadFromRegistry(RootKey: HKEY; Key: string): boolean; override;
{$ENDIF}
published
property CommentAttri: TSynHighlighterAttributes read fCommentAttri
write fCommentAttri;
property Comments: TCommentStyles read fComments write SetComments;
property DetectPreprocessor: boolean read fDetectPreprocessor
write SetDetectPreprocessor;
property IdentifierAttri: TSynHighlighterAttributes read fIdentifierAttri
write fIdentifierAttri;
property IdentifierChars: string read GetIdentifierChars
write SetIdentifierChars;
property KeyAttri: TSynHighlighterAttributes read fKeyAttri write fKeyAttri;
property KeyWords: TStrings read fKeyWords write SetKeyWords;
property NumberAttri: TSynHighlighterAttributes read fNumberAttri
write fNumberAttri;
property PreprocessorAttri: TSynHighlighterAttributes
read fPreprocessorAttri write fPreprocessorAttri;
property SpaceAttri: TSynHighlighterAttributes read fSpaceAttri
write fSpaceAttri;
property StringAttri: TSynHighlighterAttributes read fStringAttri
write fStringAttri;
property SymbolAttri: TSynHighlighterAttributes read fSymbolAttri
write fSymbolAttri;
property StringDelim: TStringDelim read GetStringDelim write SetStringDelim
default sdSingleQuote;
end;
implementation
uses
{$IFDEF SYN_CLX}
QSynEditStrConst;
{$ELSE}
SynEditStrConst;
{$ENDIF}
var
Identifiers: array[#0..#255] of ByteBool;
mHashTable: array[#0..#255] of Integer;
procedure MakeIdentTable;
var
I, J: Char;
begin
for I := #0 to #255 do
begin
Case I of
'_', 'a'..'z', 'A'..'Z', '0'..'9', '#', '$': Identifiers[I] := True;
else Identifiers[I] := False;
end;
J := UpCase(I);
Case I in ['_', 'a'..'z', 'A'..'Z', '0'..'9', '#'] of
True: mHashTable[I] := Ord(J) - 64
else mHashTable[I] := 0;
end;
end;
end;
function TSynGeneralSyn.IsKeyword(const AKeyword: string): boolean;
var
First, Last, Compare: Integer;
Token: String;
Letter: Char;
flip: boolean;
EntryIndex: Integer;
x, y, index: Integer;
Middle: Integer;
found: boolean;
begin
Result := False;
Token := UpperCase(AKeyword);
Token := trim(Token);
flip := true;
if length(Token) > 0 then begin
Letter := Token[1];
EntryIndex := (ord(Letter)) - 64;
if EntryIndex < 1 then EntryIndex := 1;
First := arEntryPoints[EntryIndex];
if EntryIndex < 26 then
Last := arEntryPoints[EntryIndex + 1] - 1
else
Last := fKeywords.Count - 1;
if Last = -1 then begin
for x := (EntryIndex + 1) to 26 do begin
Last := arEntryPoints[x] - 1;
if Last > 0 then break;
end;
end;
If Last = -1 then last := fKeyWords.Count - 1;
Middle := Round(((First + Last) /2) + 1);
x := 0;
y := 0;
found := false;
while not found do begin
if flip then begin
index := First + x;
flip := false;
inc(x);
end else begin
index := Last - y;
flip := true;
inc(y);
end;
if (x + first > middle) or (y + first > middle) then break;
if length(fKeywords[index]) >= Length(Token) then begin
//CompareToken := copy(fKeywords[index], 0, TokenLen);
Compare := CompareStr(fKeywords[index], Token);
if Compare = 0 then begin
found := true;
result := found;
break;
end;
end;
end;
end;
end; { IsKeyWord }
function TSynGeneralSyn.PossibleKeyword(text: string): boolean;
var First, Last, x, y, Compare, TokenLen, Middle: integer;
Index: integer; flip, found: boolean;
CompareToken: string;
Letter: char; EntryIndex: integer;
begin
//Checks to see if it's possible that the text we have might be part of a keyword
Result := false;
TokenLen := length(text);
text := Uppercase(text);
flip := true;
if (length(text) > 0) then begin
Letter := text[1];
EntryIndex := (ord(Letter)) - 64;
end else begin
EntryIndex := 0;
end;
if EntryIndex < 0 then EntryIndex := 0;
First := arEntryPoints[EntryIndex];
if EntryIndex < 26 then
Last := arEntryPoints[EntryIndex + 1] - 1
else
Last := fKeywords.Count - 1;
//in case the next letter doesn't have any keywords starting with it (like q), then we need to go through this next step:
if Last = -1 then begin
for x := (EntryIndex + 1) to 26 do begin
Last := arEntryPoints[x] - 1;
if Last > 0 then break;
end;
end;
If Last = -1 then last := fKeyWords.Count - 1;
Middle := Round(((First + Last) /2) + 1);
// if Middle > fKeyWords.Count -1 then Middle := fKeywords.Count-1;
x := 0;
y := 0;
found := false;
while not found do begin
if flip then begin
index := First + x;
flip := false;
inc(x);
end else begin
index := Last - y;
flip := true;
inc(y);
end;
if (x + first > middle) or (y + first > middle) then break;
if length(fKeywords[index]) >= TokenLen then begin
CompareToken := copy(fKeywords[index], 0, TokenLen);
Compare := CompareStr(text, CompareToken);
if Compare = 0 then begin
found := true;
result := found;
break;
end;
end;
//if compare < 0 then First := x + 1 else Last := x -1;
end;
//if Compare = 0 then Result := true else Result := false;
end;
procedure TSynGeneralSyn.MakeMethodTables;
var
I: Char;
begin
for I := #0 to #255 do
case I of
//'#': fProcTable[I] := AsciiCharProc;
'{': fProcTable[I] := BraceOpenProc;
';': fProcTable[I] := PointCommaProc;
#13: fProcTable[I] := CRProc;
'A'..'Z', 'a'..'z', '_', '#': fProcTable[I] := IdentProc;
#10: fProcTable[I] := LFProc;
#0: fProcTable[I] := NullProc;
'0'..'9': fProcTable[I] := NumberProc;
'(': fProcTable[I] := RoundOpenProc;
'`': fProcTable[I] := DBProcedure;
'/': fProcTable[I] := SlashProc;
//'R': fProcTable[I] := DBCommentProc;
#1..#9, #11, #12, #14..#32: fProcTable[I] := SpaceProc;
else fProcTable[I] := UnknownProc;
end;
fProcTable[fStringDelimCh] := StringProc;
end;
constructor TSynGeneralSyn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fKeyWords := TStringList.Create;
TStringList(fKeyWords).Sorted := True;
TStringList(fKeyWords).Duplicates := dupIgnore;
fCommentAttri := TSynHighlighterAttributes.Create(SYNS_AttrComment);
fCommentAttri.Style := [fsItalic];
AddAttribute(fCommentAttri);
fIdentifierAttri := TSynHighlighterAttributes.Create(SYNS_AttrIdentifier);
AddAttribute(fIdentifierAttri);
fKeyAttri := TSynHighlighterAttributes.Create(SYNS_AttrReservedWord);
fKeyAttri.Style := [fsBold];
AddAttribute(fKeyAttri);
fNumberAttri := TSynHighlighterAttributes.Create(SYNS_AttrNumber);
AddAttribute(fNumberAttri);
fSpaceAttri := TSynHighlighterAttributes.Create(SYNS_AttrSpace);
AddAttribute(fSpaceAttri);
fStringAttri := TSynHighlighterAttributes.Create(SYNS_AttrString);
AddAttribute(fStringAttri);
fSymbolAttri := TSynHighlighterAttributes.Create(SYNS_AttrSymbol);
AddAttribute(fSymbolAttri);
fPreprocessorAttri := TSynHighlighterAttributes.Create(SYNS_AttrPreprocessor);
AddAttribute(fPreprocessorAttri);
SetAttributesOnChange(DefHighlightChange);
fStringDelimCh := '''';
fIdentChars := inherited GetIdentChars;
MakeMethodTables;
fRange := rsUnknown;
CommentBlock := false;
end; { Create }
destructor TSynGeneralSyn.Destroy;
begin
fKeyWords.Free;
inherited Destroy;
end; { Destroy }
procedure TSynGeneralSyn.SetLine(NewValue: String; LineNumber:Integer);
begin
fLine := PChar(NewValue);
Run := 0;
fLineNumber := LineNumber;
Next;
end; { SetLine }
procedure TSynGeneralSyn.AnsiProc;
begin
case fLine[Run] of
#0: NullProc;
#10: LFProc;
#13: CRProc;
else
fTokenID := tkComment;
repeat
if (fLine[Run] = '*') and (fLine[Run + 1] = ')') then begin
fRange := rsUnKnown;
Inc(Run, 2);
break;
end;
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end;
end;
procedure TSynGeneralSyn.PasStyleProc;
begin
case fLine[Run] of
#0: NullProc;
#10: LFProc;
#13: CRProc;
else
fTokenID := tkComment;
repeat
if fLine[Run] = '}' then begin
fRange := rsUnKnown;
Inc(Run);
break;
end;
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end;
end;
procedure TSynGeneralSyn.CStyleProc;
begin
case fLine[Run] of
#0: NullProc;
#10: LFProc;
#13: CRProc;
else
fTokenID := tkComment;
repeat
if (fLine[Run] = '*') and (fLine[Run + 1] = '/') then begin
fRange := rsUnKnown;
Inc(Run, 2);
break;
end;
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end;
end;
procedure TSynGeneralSyn.AsciiCharProc;
begin
if fDetectPreprocessor then begin
fTokenID := tkPreprocessor;
repeat
inc(Run);
until fLine[Run] in [#0, #10, #13];
end else begin
fTokenID := tkString;
repeat
inc(Run);
until not (fLine[Run] in ['0'..'9']);
end;
end;
procedure TSynGeneralSyn.BraceOpenProc;
begin
if csPasStyle in fComments then
begin
fTokenID := tkComment;
fRange := rsPasStyle;
inc(Run);
while FLine[Run] <> #0 do
case FLine[Run] of
'}':
begin
fRange := rsUnKnown;
inc(Run);
break;
end;
#10: break;
#13: break;
else inc(Run);
end;
end else
begin
inc(Run);
fTokenID := tkSymbol;
end;
end;
procedure TSynGeneralSyn.PointCommaProc;
begin
if (csASmStyle in fComments) or (csBasStyle in fComments) then
begin
fTokenID := tkComment;
fRange := rsUnknown;
inc(Run);
while FLine[Run] <> #0 do
begin
fTokenID := tkComment;
inc(Run);
end;
end else
begin
inc(Run);
fTokenID := tkSymbol;
end;
end;
procedure TSynGeneralSyn.CRProc;
begin
fTokenID := tkSpace;
Inc(Run);
if fLine[Run] = #10 then Inc(Run);
end;
procedure TSynGeneralSyn.IdentProc;
var tempToken: string;
lastkeyword: string;
amt: integer;
ShouldRun: Boolean;
FoundFunction: Boolean;
x,y: Integer;
LineText: string;
FunctionPos: Integer;
FunctionName: string;
FunctionLine: integer;
begin
lastkeyword := '';
fTokenID := tkIdentifier;
while (Identifiers[fLine[Run]]) do begin
inc(Run);
end;
tempToken := getToken;
//Check to see if they typed in 'rem' for the starting of a comment;
if trim(uppercase(tempToken)) = 'REM' then begin
Dec(run);
DBProcedure;
tempToken := '';
end;
if trim(uppercase(tempToken)) = 'REMSTART' then begin
dec(run);
fRange := rsDBStyle;
DBCommentProc;
tempToken := '';
fTokenID := tkComment;
CommentBlock := true;
end;
if IsKeyword(tempToken) then begin
fTokenID := tkKey;
lastkeyword := temptoken;
end;
(*//Ensure that we're not inside a comment block first, and if we're not, then update the function/label list
if (fTokenID <> tkComment) and (CommentBlock = false) then begin
LineText := fLine;
FunctionPos := pos('FUNCTION', uppercase(LineText));
//if FunctionPos > 0 then begin
If uppercase(TempToken) = 'FUNCTION' then begin
//Only add this in if it isn't a duplicate
FunctionName := copy(string(fLine), FunctionPos + 9, StrLen(fline));
FunctionLine := fLineNumber; //This is actually the line INDEX, so the first line is actually 0
FoundFunction := false;
for x := 0 to high(arFunctionNames) do begin
if (arFunctionNames[x].LineNum = FunctionLine) and (arFunctionNames[x].Title = FunctionName) then begin
FoundFunction := true;
break;
end;
{if (arFunctionNames[x] = FunctionName) and (arFunctionLines[x] <> FunctionLine) then begin
//The function has been moved or erased, so we need to update the list
for y := x to high(arFunctionLines) -1 do begin
arFunctionLines[y] := arFunctionLines[y + 1];
arFunctionNames[y] := arFunctionNames[y + 1];
SetLength(arFunctionLines, high(arFunctionLines));
SetLength(arFunctionNames, high(arFunctionNames));
end;
end;
}
end;
if not FoundFunction then begin
//SetLength(arFunctionLines, length(arFunctionLines) + 1);
SetLength(arFunctionNames, length(arFunctionNames) + 1);
arFunctionNames[high(arFunctionNames)].Title := FunctionName;
arFunctionNames[high(arFunctionNames)].LineNum := FunctionLine;
end;
end;
end;
*)
if PossibleKeyword(tempToken) then begin
ShouldRun := true;
amt := run;
while (Identifiers[fline[Run]]) or (fline[Run] = ' ') do begin
if ShouldRun then begin
inc(Run);
tempToken := getToken;
end;
if not ShouldRun then begin
//StartPos := Run + 1;
TempToken := TempToken + fline[amt];
end;
inc(amt);
if IsKeyword(tempToken) then begin
fTokenID := tkKey;
lastkeyword := tempToken;
ShouldRun := false;
run := amt;
//amt := 1;
//end else begin
// fTokenID := tkIdentifier;
end;
if PossibleKeyword(tempToken) = false then begin
break;
end;
end;
end;
end;
procedure TSynGeneralSyn.UpdateCodeExplorer(Line: string; LineNumber: integer);
var
x: integer;
begin
end;
procedure TSynGeneralSyn.IntegerProc;
begin
inc(Run);
fTokenID := tkNumber;
while FLine[Run] in ['0'..'9', 'A'..'F', 'a'..'f'] do inc(Run);
end;
procedure TSynGeneralSyn.LFProc;
begin
fTokenID := tkSpace;
inc(Run);
end;
procedure TSynGeneralSyn.NullProc;
begin
fTokenID := tkNull;
end;
procedure TSynGeneralSyn.NumberProc;
begin
inc(Run);
fTokenID := tkNumber;
while FLine[Run] in ['0'..'9', '.', 'e', 'E', 'x'] do
begin
case FLine[Run] of
'x': begin // handle C style hex numbers
IntegerProc;
break;
end;
'.':
if FLine[Run + 1] = '.' then break;
end;
inc(Run);
end;
end;
procedure TSynGeneralSyn.RoundOpenProc;
begin
inc(Run);
if csAnsiStyle in fComments then
begin
case fLine[Run] of
'*':
begin
fTokenID := tkComment;
fRange := rsAnsi;
inc(Run);
while fLine[Run] <> #0 do
case fLine[Run] of
'*':
if fLine[Run + 1] = ')' then
begin
fRange := rsUnKnown;
inc(Run, 2);
break;
end else inc(Run);
#10: break;
#13: break;
else inc(Run);
end;
end;
'.':
begin
inc(Run);
fTokenID := tkSymbol;
end;
else
begin
FTokenID := tkSymbol;
end;
end;
end else fTokenId := tkSymbol;
end;
procedure TSynGeneralSyn.DBCommentProc;
begin
fTokenID := tkComment;
case fLine[Run] of
#0: NullProc;
#10: LFProc;
#13: CRProc;
else
fTokenID := tkComment;
repeat
if (uppercase(fLine[Run]) = 'R') and (uppercase(fLine[Run + 1]) = 'E') and (uppercase(fLine[Run + 2]) = 'M') and
(uppercase(fline[Run + 3]) = 'E') and (uppercase(fline[Run + 4]) = 'N') and (uppercase(fline[Run + 5]) = 'D') then begin
fRange := rsUnKnown;
Inc(Run, 6);
CommentBlock := false;
break;
end;
Inc(Run);
until fLine[Run] in [#0];
end;
end;
procedure TSynGeneralSyn.DBProcedure;
begin
fTokenID := tkComment;
repeat
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end;
procedure TSynGeneralSyn.SlashProc;
begin
Inc(Run);
case FLine[Run] of
'/':
begin
if csCPPStyle in fComments then
begin
fTokenID := tkComment;
Inc(Run);
while FLine[Run] <> #0 do
begin
case FLine[Run] of
#10, #13: break;
end;
inc(Run);
end;
end
else
fTokenId := tkSymbol;
end;
'*':
begin
if csCStyle in fComments then
begin
fTokenID := tkComment;
fRange := rsCStyle;
Inc(Run);
while fLine[Run] <> #0 do
case fLine[Run] of
'*':
if fLine[Run + 1] = '/' then
begin
fRange := rsUnKnown;
inc(Run, 2);
break;
end else inc(Run);
#10, #13:
break;
else
Inc(Run);
end;
end
else
fTokenId := tkSymbol;
end;
else
fTokenID := tkSymbol;
end;
end;
procedure TSynGeneralSyn.SpaceProc;
begin
inc(Run);
fTokenID := tkSpace;
while FLine[Run] in [#1..#9, #11, #12, #14..#32] do begin
inc(run);
end;
end;
procedure TSynGeneralSyn.StringProc;
begin
fTokenID := tkString;
if (fLine[Run + 1] = fStringDelimCh) and (fLine[Run + 2] = fStringDelimCh) then
Inc(Run, 2);
repeat
case FLine[Run] of
#0, #10, #13: break;
end;
inc(Run);
until FLine[Run] = fStringDelimCh;
if FLine[Run] <> #0 then inc(Run);
end;
procedure TSynGeneralSyn.UnknownProc;
begin
{$IFDEF SYN_MBCSSUPPORT}
if FLine[Run] in LeadBytes then
Inc(Run, 2)
else
{$ENDIF}
inc(Run);
fTokenID := tkUnknown;
end;
procedure TSynGeneralSyn.Next;
begin
fTokenPos := Run;
case fRange of
rsAnsi: AnsiProc;
rsPasStyle: PasStyleProc;
rsDBStyle: DBCommentProc;
rsCStyle: CStyleProc;
rsMultiWord: IdentProc;
else
fProcTable[fLine[Run]];
end;
end;
function TSynGeneralSyn.GetDefaultAttribute(Index: integer): TSynHighlighterAttributes;
begin
case Index of
SYN_ATTR_COMMENT: Result := fCommentAttri;
SYN_ATTR_IDENTIFIER: Result := fIdentifierAttri;
SYN_ATTR_KEYWORD: Result := fKeyAttri;
SYN_ATTR_STRING: Result := fStringAttri;
SYN_ATTR_WHITESPACE: Result := fSpaceAttri;
SYN_ATTR_SYMBOL: Result := fSymbolAttri;
else
Result := nil;
end;
end;
function TSynGeneralSyn.GetEol: Boolean;
begin
Result := fTokenId = tkNull;
end;
function TSynGeneralSyn.GetRange: Pointer;
begin
Result := Pointer(fRange);
end;
function TSynGeneralSyn.GetToken: String;
var
Len: LongInt;
begin
Len := Run - fTokenPos;
SetString(Result, (FLine + fTokenPos), Len);
end;
function TSynGeneralSyn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
end;
function TSynGeneralSyn.GetTokenAttribute: TSynHighlighterAttributes;
begin
case fTokenID of
tkComment: Result := fCommentAttri;
tkIdentifier: Result := fIdentifierAttri;
tkKey: Result := fKeyAttri;
tkNumber: Result := fNumberAttri;
tkPreprocessor: Result := fPreprocessorAttri;
tkSpace: Result := fSpaceAttri;
tkString: Result := fStringAttri;
tkSymbol: Result := fSymbolAttri;
tkUnknown: Result := fSymbolAttri;
else
Result := nil;
end;
end;
function TSynGeneralSyn.GetTokenKind: integer;
begin
Result := Ord(fTokenId);
end;
function TSynGeneralSyn.GetTokenPos: Integer;
begin
Result := fTokenPos;
end;
procedure TSynGeneralSyn.ResetRange;
begin
fRange := rsUnknown;
end;
procedure TSynGeneralSyn.SetRange(Value: Pointer);
begin
fRange := TRangeState(Value);
end;
procedure TSynGeneralSyn.SetKeyWords(const Value: TStrings);
var
i: integer;
begin
if Value <> nil then
begin
Value.BeginUpdate;
for i := 0 to Value.Count - 1 do
Value[i] := UpperCase(Value[i]);
Value.EndUpdate;
end;
fKeyWords.Assign(Value);
DefHighLightChange(nil);
end;
procedure TSynGeneralSyn.UpdateKeywords;
var
x, y: Integer;
CurrentWord: string;
CurrentLetter: char;
begin
//This is a wild idea of mine to see if it speeds up the process of searching for possible keywords to highlight them.
//What it does is create 26 entry points for the program to jump into the keyword list (one for each letter)
//YES!!! YES!!! IT WORKS!! AND FAST TOO!! Ok, enough happiness ;) But I'm really, really pleased seeing the exceptional speed
//I can't notice any slowdown unless I paste over about 5000 lines of code at once, but once it's loaded in, it's exceptionally fast :)
TStringList(fKeywords).Sorted := false;
for x := 0 to fKeyWords.Count - 1 do begin
fKeywords[x] := UpperCase(fKeywords[x]);
end;
TStringList(fKeywords).Sort;
TStringList(fKeywords).Sorted := true;
arEntryPoints[1] := 0;
for x := 2 to 26 do begin
CurrentLetter := Chr(x + 64);
for y := 0 to fKeyWords.Count - 1 do begin
CurrentWord := fKeyWords.Strings[y];
if CurrentWord[1] = CurrentLetter then begin
arEntryPoints[x] := y;
break;
end;
end;
end;
end;
procedure TSynGeneralSyn.SetComments(Value: TCommentStyles);
begin
if fComments <> Value then
begin
fComments := Value;
DefHighLightChange(Self);
end;
end;
class function TSynGeneralSyn.GetLanguageName: string;
begin
Result := SYNS_LangGeneral;
end;
{$IFNDEF SYN_CLX}
function TSynGeneralSyn.LoadFromRegistry(RootKey: HKEY; Key: string): boolean;
var
r: TBetterRegistry;
begin
r:= TBetterRegistry.Create;
try
r.RootKey := RootKey;
if r.OpenKeyReadOnly(Key) then begin
if r.ValueExists('KeyWords') then KeyWords.Text:= r.ReadString('KeyWords');
Result := inherited LoadFromRegistry(RootKey, Key);
end
else Result := false;
finally r.Free; end;
end;
function TSynGeneralSyn.SaveToRegistry(RootKey: HKEY; Key: string): boolean;
var
r: TBetterRegistry;
begin
r:= TBetterRegistry.Create;
try
r.RootKey := RootKey;
if r.OpenKey(Key,true) then begin
Result := true;
r.WriteString('KeyWords', KeyWords.Text);
Result := inherited SaveToRegistry(RootKey, Key);
end
else Result := false;
finally r.Free; end;
end;
{$ENDIF}
function TSynGeneralSyn.GetStringDelim: TStringDelim;
begin
if fStringDelimCh = '''' then
Result := sdSingleQuote
else
Result := sdDoubleQuote;
end;
procedure TSynGeneralSyn.SetStringDelim(const Value: TStringDelim);
var
newCh: char;
begin
case Value of
sdSingleQuote: newCh := '''';
else newCh := '"';
end; //case
if newCh <> fStringDelimCh then begin
fStringDelimCh := newCh;
MakeMethodTables;
end;
end;
function TSynGeneralSyn.GetIdentifierChars: string;
var
ch: char;
s: shortstring;
begin
s := '';
for ch := #0 to #255 do
if ch in fIdentChars then s := s + ch;
Result := s;
end;
procedure TSynGeneralSyn.SetIdentifierChars(const Value: string);
var
i: integer;
begin
fIdentChars := [];
for i := 1 to Length(Value) do begin
fIdentChars := fIdentChars + [Value[i]];
end; //for
WordBreakChars := WordBreakChars - fIdentChars;
end;
function TSynGeneralSyn.GetIdentChars: TSynIdentChars;
begin
Result := fIdentChars;
end;
procedure TSynGeneralSyn.SetDetectPreprocessor(Value: boolean);
begin
if Value <> fDetectPreprocessor then begin
fDetectPreprocessor := Value;
DefHighlightChange(Self);
end;
end;
initialization
MakeIdentTable;
{$IFNDEF SYN_CPPB_1}
RegisterPlaceableHighlighter(TSynGeneralSyn);
{$ENDIF}
end.
It looks like the problem with "as" not always highlighting is if your variable is also part of a keyword. Try these examples:
abc as integer (yes)
x as integer (no)
make as integer (no)
limb as integer (no)
foo as string (yes)
Of course, the thing to do now is figure out how to fix it.
Before I ramble on any longer, here is the update. Try it and let me know if I broke anything. Hopefully, the next update won't be such a long wait.
Good performance is better than a good excuse.
CodeSurge -- DBP Editor for serious programmers.