📄 synhighlighteravrc.pas
字号:
inc(Run);
FExtTokenID := xtkStar;
end;
end;
end;
procedure TSynAVRCSyn.StringProc;
begin
if (fRange = rsAsmBlock) then
begin
inc(Run);
fTokenID := tkAsm;
end
else
begin
fTokenID := tkString;
repeat
if fLine[Run] = '\' then begin
case fLine[Run + 1] of
#34, '\':
Inc(Run);
#00:
begin
Inc(Run);
fRange := rsMultilineString;
Exit;
end;
end;
end;
inc(Run);
until fLine[Run] in [#0, #10, #13, #34];
if FLine[Run] = #34 then
inc(Run);
end;
end;
procedure TSynAVRCSyn.StringEndProc;
begin
fTokenID := tkString;
case FLine[Run] of
#0:
begin
NullProc;
Exit;
end;
#10:
begin
LFProc;
Exit;
end;
#13:
begin
CRProc;
Exit;
end;
end;
fRange := rsUnknown;
repeat
case FLine[Run] of
#0, #10, #13: Break;
'\':
begin
case fLine[Run + 1] of
#34, '\':
Inc(Run);
#00:
begin
Inc(Run);
fRange := rsMultilineString;
Exit;
end;
end;
end;
#34: Break;
end;
inc(Run);
until fLine[Run] in [#0, #10, #13, #34];
if FLine[Run] = #34 then
inc(Run);
end;
procedure TSynAVRCSyn.TildeProc;
begin
inc(Run); {bitwise complement}
fTokenId := tkSymbol;
FExtTokenID := xtkBitComplement;
end;
procedure TSynAVRCSyn.XOrSymbolProc;
begin
fTokenID := tkSymbol;
Case FLine[Run + 1] of
'=': {xor assign}
begin
inc(Run, 2);
FExtTokenID := xtkXorAssign;
end;
else {xor}
begin
inc(Run);
FExtTokenID := xtkXor;
end;
end;
end;
procedure TSynAVRCSyn.UnknownProc;
begin
{$IFDEF SYN_MBCSSUPPORT}
if FLine[Run] in LeadBytes then // if FLine[Run] is the leadbyte of MBCS char,then jump 2 chars.
Inc(Run,2)
else
{$ENDIF}
Inc(Run);
fTokenID := tkUnknown;
end;
procedure TSynAVRCSyn.Next;
begin
fAsmStart := False;
fTokenPos := Run;
case fRange of
rsAnsiC, rsAnsiCAsm,
rsAnsiCAsmBlock, rsDirectiveComment: AnsiCProc;
rsMultiLineDirective: DirectiveEndProc; // dj
rsMultilineString: StringEndProc; //ek 2001-08-02
else
begin
if not (fRange = rsAsm) and not (fRange = rsAsmBlock) then fRange := rsUnknown;
fProcTable[fLine[Run]];
end;
end;
end;
function TSynAVRCSyn.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 TSynAVRCSyn.GetEol: Boolean;
begin
Result := fTokenID = tkNull;
end;
function TSynAVRCSyn.GetRange: Pointer;
begin
Result := Pointer(fRange);
end;
function TSynAVRCSyn.GetToken: String;
var
Len: LongInt;
begin
Len := Run - fTokenPos;
SetString(Result, (FLine + fTokenPos), Len);
end;
function TSynAVRCSyn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
if ({(fRange = rsAsm) or }(fRange = rsAsmBlock)) and not fAsmStart
and not (fTokenId in [tkComment, tkSpace, tkNull])
then
Result := tkAsm;
end;
function TSynAVRCSyn.GetExtTokenID: TxtkTokenKind;
begin
Result := FExtTokenID;
end;
function TSynAVRCSyn.GetTokenAttribute: TSynHighlighterAttributes;
begin
case GetTokenID of
tkAsm: Result := fAsmAttri;
tkComment: Result := fCommentAttri;
tkDirective: Result := fDirecAttri;
tkIdentifier: Result := fIdentifierAttri;
tkKey: Result := fKeyAttri;
tkNumber: Result := fNumberAttri;
tkFloat: Result := fFloatAttri;
tkHex: Result := fHexAttri;
tkOctal: Result := fOctalAttri;
tkSpace: Result := fSpaceAttri;
tkString: Result := fStringAttri;
tkChar: Result := fCharAttri;
tkSymbol: Result := fSymbolAttri;
tkUnknown: Result := fInvalidAttri;
else Result := nil;
end;
end;
function TSynAVRCSyn.GetTokenKind: integer;
begin
Result := Ord(GetTokenID);
end;
function TSynAVRCSyn.GetTokenPos: Integer;
begin
Result := fTokenPos;
end;
procedure TSynAVRCSyn.ReSetRange;
begin
fRange:= rsUnknown;
end;
procedure TSynAVRCSyn.SetRange(Value: Pointer);
begin
fRange := TRangeState(Value);
end;
procedure TSynAVRCSyn.EnumUserSettings(settings: TStrings);
begin
{ returns the user settings that exist in the registry }
{$IFNDEF SYN_CLX}
with TBetterRegistry.Create do
begin
try
RootKey := HKEY_LOCAL_MACHINE;
if OpenKeyReadOnly('\SOFTWARE\Borland\C++Builder') then
begin
try
GetKeyNames(settings);
finally
CloseKey;
end;
end;
finally
Free;
end;
end;
{$ENDIF}
end;
function TSynAVRCSyn.UseUserSettings(settingIndex: integer): boolean;
// Possible parameter values:
// index into TStrings returned by EnumUserSettings
// Possible return values:
// true : settings were read and used
// false: problem reading settings or invalid version specified - old settings
// were preserved
{$IFNDEF SYN_CLX}
function ReadCPPBSettings(settingIndex: integer): boolean;
function ReadCPPBSetting(settingTag: string; attri: TSynHighlighterAttributes; key: string): boolean;
function ReadCPPB1(settingTag: string; attri: TSynHighlighterAttributes; name: string): boolean;
var
i: integer;
begin
for i := 1 to Length(name) do
if name[i] = ' ' then name[i] := '_';
Result := attri.LoadFromBorlandRegistry(HKEY_CURRENT_USER,
'\SOFTWARE\Borland\C++Builder\'+settingTag+'\Highlight',name,true);
end; { ReadCPPB1 }
function ReadCPPB3OrMore(settingTag: string; attri: TSynHighlighterAttributes; key: string): boolean;
begin
Result := attri.LoadFromBorlandRegistry(HKEY_CURRENT_USER,
'\Software\Borland\C++Builder\'+settingTag+'\Editor\Highlight',
key,false);
end; { ReadCPPB3OrMore }
begin { ReadCPPBSetting }
try
if (settingTag[1] = '1')
then Result := ReadCPPB1(settingTag,attri,key)
else Result := ReadCPPB3OrMore(settingTag,attri,key);
except Result := false; end;
end; { ReadCPPBSetting }
var
tmpStringAttri : TSynHighlighterAttributes;
tmpCharAttri : TSynHighlighterAttributes;
tmpNumberAttri : TSynHighlighterAttributes;
tmpFloatAttri : TSynHighlighterAttributes;
tmpHexAttri : TSynHighlighterAttributes;
tmpOctalAttri : TSynHighlighterAttributes;
tmpKeyAttri : TSynHighlighterAttributes;
tmpSymbolAttri : TSynHighlighterAttributes;
tmpAsmAttri : TSynHighlighterAttributes;
tmpCommentAttri : TSynHighlighterAttributes;
tmpIdentifierAttri: TSynHighlighterAttributes;
tmpInvalidAttri : TSynHighlighterAttributes;
tmpSpaceAttri : TSynHighlighterAttributes;
tmpDirecAttri : TSynHighlighterAttributes;
s : TStringList;
begin { ReadCPPBSettings }
s := TStringList.Create;
try
EnumUserSettings(s);
if settingIndex >= s.Count then Result := false
else begin
tmpStringAttri := TSynHighlighterAttributes.Create('');
tmpCharAttri := TSynHighlighterAttributes.Create('');
tmpNumberAttri := TSynHighlighterAttributes.Create('');
tmpFloatAttri := TSynHighlighterAttributes.Create('');
tmpHexAttri := TSynHighlighterAttributes.Create('');
tmpOctalAttri := TSynHighlighterAttributes.Create('');
tmpKeyAttri := TSynHighlighterAttributes.Create('');
tmpSymbolAttri := TSynHighlighterAttributes.Create('');
tmpAsmAttri := TSynHighlighterAttributes.Create('');
tmpCommentAttri := TSynHighlighterAttributes.Create('');
tmpIdentifierAttri:= TSynHighlighterAttributes.Create('');
tmpInvalidAttri := TSynHighlighterAttributes.Create('');
tmpSpaceAttri := TSynHighlighterAttributes.Create('');
tmpDirecAttri := TSynHighlighterAttributes.Create('');
tmpStringAttri .Assign(fStringAttri);
tmpCharAttri .Assign(fCharAttri);
tmpNumberAttri .Assign(fNumberAttri);
tmpFloatAttri .Assign(fFloatAttri);
tmpHexAttri .Assign(fHexAttri);
tmpOctalAttri .Assign(fOctalAttri);
tmpKeyAttri .Assign(fKeyAttri);
tmpSymbolAttri .Assign(fSymbolAttri);
tmpAsmAttri .Assign(fAsmAttri);
tmpCommentAttri .Assign(fCommentAttri);
tmpIdentifierAttri.Assign(fIdentifierAttri);
tmpInvalidAttri .Assign(fInvalidAttri);
tmpSpaceAttri .Assign(fSpaceAttri);
tmpDirecAttri .Assign(fDirecAttri);
if s[settingIndex][1] = '1'
then Result := ReadCPPBSetting(s[settingIndex],fAsmAttri,'Plain text')
else Result := ReadCPPBSetting(s[settingIndex],fAsmAttri,'Assembler');
Result := Result and
ReadCPPBSetting(s[settingIndex],fCommentAttri,'Comment') and
ReadCPPBSetting(s[settingIndex],fIdentifierAttri,'Identifier') and
ReadCPPBSetting(s[settingIndex],fInvalidAttri,'Illegal Char') and
ReadCPPBSetting(s[settingIndex],fKeyAttri,'Reserved word') and
ReadCPPBSetting(s[settingIndex],fNumberAttri,'Integer') and
ReadCPPBSetting(s[settingIndex],fFloatAttri,'Float') and
ReadCPPBSetting(s[settingIndex],fHexAttri,'Hex') and
ReadCPPBSetting(s[settingIndex],fOctalAttri,'Octal') and
ReadCPPBSetting(s[settingIndex],fSpaceAttri,'Whitespace') and
ReadCPPBSetting(s[settingIndex],fStringAttri,'String') and
ReadCPPBSetting(s[settingIndex],fCharAttri,'Character') and
ReadCPPBSetting(s[settingIndex],fSymbolAttri,'Symbol') and
ReadCPPBSetting(s[settingIndex],fDirecAttri,'Preprocessor');
if not Result then begin
fStringAttri .Assign(tmpStringAttri);
fCharAttri .Assign(tmpCharAttri);
fNumberAttri .Assign(tmpNumberAttri);
fFloatAttri .Assign(tmpFloatAttri);
fHexAttri .Assign(tmpHexAttri);
fOctalAttri .Assign(tmpOctalAttri);
fKeyAttri .Assign(tmpKeyAttri);
fSymbolAttri .Assign(tmpSymbolAttri);
fAsmAttri .Assign(tmpAsmAttri);
fCommentAttri .Assign(tmpCommentAttri);
fIdentifierAttri.Assign(tmpIdentifierAttri);
fInvalidAttri .Assign(tmpInvalidAttri);
fSpaceAttri .Assign(tmpSpaceAttri);
fDirecAttri .Assign(tmpDirecAttri);
end;
tmpStringAttri .Free;
tmpCharAttri .Free;
tmpNumberAttri .Free;
tmpFloatAttri .Free;
tmpHexAttri .Free;
tmpOctalAttri .Free;
tmpKeyAttri .Free;
tmpSymbolAttri .Free;
tmpAsmAttri .Free;
tmpCommentAttri .Free;
tmpIdentifierAttri.Free;
tmpInvalidAttri .Free;
tmpSpaceAttri .Free;
tmpDirecAttri .Free;
end;
finally s.Free; end;
end; { ReadCPPBSettings }
{$ENDIF}
begin
{$IFNDEF SYN_CLX}
Result := ReadCPPBSettings(settingIndex);
{$ELSE}
Result := False;
{$ENDIF}
end; { TSynAVRCSyn.UseUserSettings }
function TSynAVRCSyn.GetIdentChars: TSynIdentChars;
begin
Result := TSynValidStringChars;
end;
{$IFNDEF SYN_CPPB_1} class {$ENDIF} //mh 2000-07-14
function TSynAVRCSyn.GetLanguageName: string;
begin
Result := SYNS_LangCPP;
end;
{$IFNDEF SYN_CPPB_1} class {$ENDIF} //mh 2000-07-14
function TSynAVRCSyn.GetCapabilities: TSynHighlighterCapabilities;
begin
Result := inherited GetCapabilities + [hcUserSettings];
end;
function TSynAVRCSyn.GetSampleSource: string;
begin
Result := '// Syntax Highlighting'#13#10+
'void __fastcall TForm1::Button1Click(TObject *Sender)'#13#10+
'{'#13#10+
' int number = 123456;'#13#10+
' char c = ''a'';'#13#10+
' Caption = "The number is " + IntToStr(i);'#13#10+
' for (int i = 0; i <= number; i++)'#13#10+
' {'#13#10+
' x -= 0xff;'#13#10+
' x -= 023;'#13#10+
' x += 1.0;'#13#10+
' x += @; /* illegal character */'#13#10+
' }'#13#10+
' #ifdef USE_ASM'#13#10+
' asm'#13#10+
' {'#13#10+
' ASM MOV AX, 0x1234'#13#10+
' ASM MOV i, AX'#13#10+
' }'#13#10+
' #endif'#13#10+
'}';
end;
initialization
MakeIdentTable;
{$IFNDEF SYN_CPPB_1} //mh 2000-07-14
RegisterPlaceableHighlighter(TSynAVRCSyn);
{$ENDIF}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -