📄 synhighlighteravrc.pas
字号:
{-------------------------------------------------------------------------------
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: SynHighlighterCpp.pas, released 2000-04-10.
The Original Code is based on the dcjCppSyn.pas file from the
mwEdit component suite by Martin Waldenburg and other developers, the Initial
Author of this file is Michael Trier.
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: SynHighlighterCpp.pas,v 1.15 2002/01/10 15:23:13 drbrno Exp $
You may retrieve the latest version of this file at the SynEdit home page,
located at http://SynEdit.SourceForge.net
Known Issues:
-------------------------------------------------------------------------------}
{
@abstract(Provides a C++ syntax highlighter for SynEdit)
@author(Michael Trier)
@created(1998)
@lastmod(2001-11-21)
The SynHighlighterCpp unit provides SynEdit with a C++ syntax highlighter.
Thanks to Martin Waldenburg.
}
{
30.12.2004 Changed to meet the needs of WinAVRIDE (Philipp Schober)
}
unit SynHighlighterAVRC;
{$I SynEdit.inc}
interface
uses
SysUtils,
Classes,
{$IFDEF SYN_CLX}
QControls,
QGraphics,
{$ELSE}
Windows,
Controls,
Graphics,
{$ENDIF}
SynEditTypes,
SynEditHighlighter;
type
TtkTokenKind = (tkAsm, tkComment, tkDirective, tkIdentifier, tkKey, tkNull,
tkNumber, tkSpace, tkString, tkSymbol, tkUnknown,
tkChar, tkFloat, tkHex, tkOctal); // dj
TxtkTokenKind = (
xtkAdd, xtkAddAssign, xtkAnd, xtkAndAssign, xtkArrow, xtkAssign,
xtkBitComplement, xtkBraceClose, xtkBraceOpen, xtkColon, xtkComma,
xtkDecrement, xtkDivide, xtkDivideAssign, xtkEllipse, xtkGreaterThan,
xtkGreaterThanEqual, xtkIncOr, xtkIncOrAssign, xtkIncrement, xtkLessThan,
xtkLessThanEqual, xtkLogAnd, xtkLogComplement, xtkLogEqual, xtkLogOr,
xtkMod, xtkModAssign, xtkMultiplyAssign, xtkNotEqual, xtkPoint, xtkQuestion,
xtkRoundClose, xtkRoundOpen, xtkScopeResolution, xtkSemiColon, xtkShiftLeft,
xtkShiftLeftAssign, xtkShiftRight, xtkShiftRightAssign, xtkSquareClose,
xtkSquareOpen, xtkStar, xtkSubtract, xtkSubtractAssign, xtkXor,
xtkXorAssign);
TRangeState = (rsUnknown, rsAnsiC, rsAnsiCAsm, rsAnsiCAsmBlock, rsAsm,
rsAsmBlock, rsDirective, rsDirectiveComment, rsString34, rsString39,
rsMultiLineString, rsMultiLineDirective); //dj
TProcTableProc = procedure of object;
PIdentFuncTableFunc = ^TIdentFuncTableFunc;
TIdentFuncTableFunc = function: TtkTokenKind of object;
TSynAVRCSyn = class(TSynCustomHighlighter)
private
fAsmStart: Boolean;
fRange: TRangeState;
fLine: PChar;
fProcTable: array[#0..#255] of TProcTableProc;
Run: LongInt;
fStringLen: Integer;
fToIdent: PChar;
fTokenPos: Integer;
FTokenID: TtkTokenKind;
FExtTokenID: TxtkTokenKind;
fLineNumber: Integer;
fIdentFuncTable: array[0..206] of TIdentFuncTableFunc;
fAsmAttri: TSynHighlighterAttributes;
fCommentAttri: TSynHighlighterAttributes;
fDirecAttri: TSynHighlighterAttributes;
fIdentifierAttri: TSynHighlighterAttributes;
fInvalidAttri: TSynHighlighterAttributes;
fKeyAttri: TSynHighlighterAttributes;
fNumberAttri: TSynHighlighterAttributes;
fFloatAttri: TSynHighlighterAttributes;
fHexAttri: TSynHighlighterAttributes;
fOctalAttri: TSynHighlighterAttributes;
fSpaceAttri: TSynHighlighterAttributes;
fStringAttri: TSynHighlighterAttributes;
fCharAttri: TSynHighlighterAttributes;
fSymbolAttri: TSynHighlighterAttributes;
function KeyHash(ToHash: PChar): Integer;
function KeyComp(const aKey: String): Boolean;
function Func17: TtkTokenKind;
function Func21: TtkTokenKind;
function Func32: TtkTokenKind;
function Func34: TtkTokenKind;
function Func36: TtkTokenKind;
function Func42: TtkTokenKind;
function Func45: TtkTokenKind;
function Func46: TtkTokenKind;
function Func48: TtkTokenKind;
function Func52: TtkTokenKind;
function Func54: TtkTokenKind;
function Func57: TtkTokenKind;
function Func59: TtkTokenKind;
function Func61: TtkTokenKind;
function Func62: TtkTokenKind;
function Func64: TtkTokenKind;
function Func65: TtkTokenKind;
function Func68: TtkTokenKind;
function Func69: TtkTokenKind;
function Func76: TtkTokenKind;
function Func78: TtkTokenKind;
function Func85: TtkTokenKind;
function Func86: TtkTokenKind;
function Func88: TtkTokenKind;
function Func92: TtkTokenKind;
function Func101: TtkTokenKind;
function Func102: TtkTokenKind;
function Func104: TtkTokenKind;
function Func107: TtkTokenKind;
function Func109: TtkTokenKind;
function Func125: TtkTokenKind;
function Func134: TtkTokenKind;
procedure AnsiCProc;
procedure AndSymbolProc;
procedure AsciiCharProc;
procedure AtSymbolProc;
procedure BraceCloseProc;
procedure BraceOpenProc;
procedure CRProc;
procedure ColonProc;
procedure CommaProc;
procedure DirectiveProc;
procedure DirectiveEndProc; //dj
procedure EqualProc;
procedure GreaterProc;
procedure IdentProc;
procedure LFProc;
procedure LowerProc;
procedure MinusProc;
procedure ModSymbolProc;
procedure NotSymbolProc;
procedure NullProc;
procedure NumberProc;
procedure OrSymbolProc;
procedure PlusProc;
procedure PointProc;
procedure QuestionProc;
procedure RoundCloseProc;
procedure RoundOpenProc;
procedure SemiColonProc;
procedure SlashProc;
procedure SpaceProc;
procedure SquareCloseProc;
procedure SquareOpenProc;
procedure StarProc;
procedure StringProc;
procedure TildeProc;
procedure XOrSymbolProc;
procedure UnknownProc;
function AltFunc: TtkTokenKind;
procedure InitIdent;
function IdentKind(MayBe: PChar): TtkTokenKind;
procedure MakeMethodTables;
procedure StringEndProc;
protected
function GetIdentChars: TSynIdentChars; override;
function GetExtTokenID: TxtkTokenKind;
function GetSampleSource: string; override;
public
{$IFNDEF SYN_CPPB_1} class {$ENDIF} //mh 2000-07-14
function GetCapabilities: TSynHighlighterCapabilities; override;
{$IFNDEF SYN_CPPB_1} class {$ENDIF} //mh 2000-07-14
function GetLanguageName: string; override;
public
constructor Create(AOwner: TComponent); override;
function GetDefaultAttribute(Index: integer): TSynHighlighterAttributes;
override;
function GetEol: Boolean; override;
function GetRange: Pointer; override;
function GetTokenID: TtkTokenKind;
procedure SetLine(NewValue: String; LineNumber:Integer); override;
function GetToken: String; override;
function GetTokenAttribute: TSynHighlighterAttributes; override;
function GetTokenKind: integer; override;
function GetTokenPos: Integer; override;
procedure Next; override;
procedure SetRange(Value: Pointer); override;
procedure ResetRange; override;
function UseUserSettings(settingIndex: integer): boolean; override;
procedure EnumUserSettings(settings: TStrings); override;
property ExtTokenID: TxtkTokenKind read GetExtTokenID;
published
property AsmAttri: TSynHighlighterAttributes read fAsmAttri write fAsmAttri;
property CommentAttri: TSynHighlighterAttributes read fCommentAttri
write fCommentAttri;
property DirecAttri: TSynHighlighterAttributes read fDirecAttri
write fDirecAttri;
property IdentifierAttri: TSynHighlighterAttributes read fIdentifierAttri
write fIdentifierAttri;
property InvalidAttri: TSynHighlighterAttributes read fInvalidAttri
write fInvalidAttri;
property KeyAttri: TSynHighlighterAttributes read fKeyAttri write fKeyAttri;
property NumberAttri: TSynHighlighterAttributes read fNumberAttri
write fNumberAttri;
property FloatAttri: TSynHighlighterAttributes read fFloatAttri
write fFloatAttri;
property HexAttri: TSynHighlighterAttributes read fHexAttri
write fHexAttri;
property OctalAttri: TSynHighlighterAttributes read fOctalAttri
write fOctalAttri;
property SpaceAttri: TSynHighlighterAttributes read fSpaceAttri
write fSpaceAttri;
property StringAttri: TSynHighlighterAttributes read fStringAttri
write fStringAttri;
property CharAttri: TSynHighlighterAttributes read fCharAttri
write fCharAttri;
property SymbolAttri: TSynHighlighterAttributes read fSymbolAttri
write fSymbolAttri;
end;
implementation
uses
SynEditStrConst;
var
Identifiers: array[#0..#255] of ByteBool;
mHashTable: array[#0..#255] of Integer;
procedure MakeIdentTable;
var
I: Char;
begin
for I := #0 to #255 do
begin
Case I of
'_', '0'..'9', 'a'..'z', 'A'..'Z': Identifiers[I] := True;
else Identifiers[I] := False;
end;
Case I in['_', 'a'..'z', 'A'..'Z'] of
True:
begin
if (I > #64) and (I < #91) then mHashTable[I] := Ord(I) - 64 else
if (I > #96) then mHashTable[I] := Ord(I) - 95;
end;
else mHashTable[I] := 0;
end;
end;
end;
procedure TSynAVRCSyn.InitIdent;
var
I: Integer;
pF: PIdentFuncTableFunc;
begin
pF := PIdentFuncTableFunc(@fIdentFuncTable);
for I := Low(fIdentFuncTable) to High(fIdentFuncTable) do begin
pF^ := AltFunc;
Inc(pF);
end;
fIdentFuncTable[17] := Func17;
fIdentFuncTable[21] := Func21;
fIdentFuncTable[32] := Func32;
fIdentFuncTable[34] := Func34;
fIdentFuncTable[36] := Func36;
fIdentFuncTable[42] := Func42;
fIdentFuncTable[45] := Func45;
fIdentFuncTable[46] := Func46;
fIdentFuncTable[48] := Func48;
fIdentFuncTable[52] := Func52;
fIdentFuncTable[54] := Func54;
fIdentFuncTable[57] := Func57;
fIdentFuncTable[59] := Func59;
fIdentFuncTable[61] := Func61;
fIdentFuncTable[62] := Func62;
fIdentFuncTable[64] := Func64;
fIdentFuncTable[65] := Func65;
fIdentFuncTable[68] := Func68;
fIdentFuncTable[69] := Func69;
fIdentFuncTable[76] := Func76;
fIdentFuncTable[78] := Func78;
fIdentFuncTable[85] := Func85;
fIdentFuncTable[86] := Func86;
fIdentFuncTable[88] := Func88;
fIdentFuncTable[92] := Func92;
fIdentFuncTable[101] := Func101;
fIdentFuncTable[102] := Func102;
fIdentFuncTable[104] := Func104;
fIdentFuncTable[107] := Func107;
fIdentFuncTable[109] := Func109;
fIdentFuncTable[125] := Func125;
fIdentFuncTable[134] := Func134;
end;
function TSynAVRCSyn.KeyHash(ToHash: PChar): Integer;
begin
Result := 0;
while ToHash^ in ['_', '0'..'9', 'a'..'z', 'A'..'Z'] do
begin
inc(Result, mHashTable[ToHash^]);
inc(ToHash);
end;
fStringLen := ToHash - fToIdent;
end; { KeyHash }
function TSynAVRCSyn.KeyComp(const aKey: String): Boolean;
var
I: Integer;
Temp: PChar;
begin
Temp := fToIdent;
if Length(aKey) = fStringLen then
begin
Result := True;
for i := 1 to fStringLen do
begin
if Temp^ <> aKey[i] then
begin
Result := False;
break;
end;
inc(Temp);
end;
end else Result := False;
end; { KeyComp }
function TSynAVRCSyn.Func17: TtkTokenKind;
begin
if KeyComp('if') then Result := tkKey else Result := tkIdentifier;
end;
function TSynAVRCSyn.Func21: TtkTokenKind;
begin
if KeyComp('do') then Result := tkKey else Result := tkIdentifier;
end;
function TSynAVRCSyn.Func32: TtkTokenKind;
begin
if KeyComp('case') then Result := tkKey
else Result := tkIdentifier;
end;
function TSynAVRCSyn.Func34: TtkTokenKind;
begin
if KeyComp('char') then Result := tkKey else Result := tkIdentifier;
end;
function TSynAVRCSyn.Func36: TtkTokenKind;
begin
if KeyComp('asm') or KeyComp('__asm__') then
begin
Result := tkKey;
fRange := rsAsm;
fAsmStart := True;
end else
Result := tkIdentifier;
end;
function TSynAVRCSyn.Func42: TtkTokenKind;
begin
if KeyComp('for') then Result := tkKey else
if KeyComp('break') then Result := tkKey else Result := tkIdentifier;
end;
function TSynAVRCSyn.Func45: TtkTokenKind;
begin
if KeyComp('else') then Result := tkKey
else Result := tkIdentifier;
end;
function TSynAVRCSyn.Func46: TtkTokenKind;
begin
if KeyComp('int') then Result := tkKey else Result := tkIdentifier;
end;
function TSynAVRCSyn.Func48: TtkTokenKind;
begin
if KeyComp('false') then Result := tkKey
else Result := tkIdentifier;
end;
function TSynAVRCSyn.Func52: TtkTokenKind;
begin
if KeyComp('long') then Result := tkKey else Result := tkIdentifier;
end;
function TSynAVRCSyn.Func54: TtkTokenKind;
begin
if KeyComp('void') then Result := tkKey else Result := tkIdentifier;
end;
function TSynAVRCSyn.Func57: TtkTokenKind;
begin
if KeyComp('enum') then Result := tkKey else Result := tkIdentifier;
end;
function TSynAVRCSyn.Func59: TtkTokenKind;
begin
if KeyComp('float') then Result := tkKey
else Result := tkIdentifier;
end;
function TSynAVRCSyn.Func61: TtkTokenKind;
begin
if KeyComp('goto') then Result := tkKey else
if KeyComp('auto') then Result := tkKey else Result := tkIdentifier;
end;
function TSynAVRCSyn.Func62: TtkTokenKind;
begin
if KeyComp('while') then Result := tkKey
else Result := tkIdentifier;
end;
function TSynAVRCSyn.Func64: TtkTokenKind;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -