📄 synhighlightercs.pas
字号:
procedure TSynCSSyn.SpaceProc;
begin
inc(Run);
fTokenID := tkSpace;
while FLine[Run] in [#1..#9, #11, #12, #14..#32] do inc(Run);
end;
procedure TSynCSSyn.SquareCloseProc;
begin
inc(Run);
fTokenID := tkSymbol;
FExtTokenID := xtkSquareClose;
end;
procedure TSynCSSyn.SquareOpenProc;
begin
inc(Run);
fTokenID := tkSymbol;
FExtTokenID := xtkSquareOpen;
end;
procedure TSynCSSyn.StarProc;
begin
fTokenID := tkSymbol;
case FLine[Run + 1] of
'=': {multiply assign}
begin
inc(Run, 2);
FExtTokenID := xtkMultiplyAssign;
end;
else {star}
begin
inc(Run);
FExtTokenID := xtkStar;
end;
end;
end;
procedure TSynCSSyn.StringProc;
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;
procedure TSynCSSyn.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 TSynCSSyn.TildeProc;
begin
inc(Run); {bitwise complement}
fTokenId := tkSymbol;
FExtTokenID := xtkBitComplement;
end;
procedure TSynCSSyn.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 TSynCSSyn.UnknownProc;
begin
{$IFDEF SYN_MBCSSUPPORT}
if FLine[Run] in LeadBytes then
Inc(Run, 2)
else
{$ENDIF}
inc(Run);
fTokenID := tkUnknown;
end;
procedure TSynCSSyn.Next;
begin
fAsmStart := False;
fTokenPos := Run;
case fRange of
rsAnsiC, rsAnsiCAsm,
rsAnsiCAsmBlock, rsDirectiveComment: AnsiCProc;
rsDirective: DirectiveProc;
rsMultilineString: StringEndProc;
else
begin
fRange := rsUnknown;
fProcTable[fLine[Run]];
end;
end;
end;
function TSynCSSyn.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;
else Result := nil;
end;
end;
function TSynCSSyn.GetEol: Boolean;
begin
Result := fTokenID = tkNull;
end;
function TSynCSSyn.GetRange: Pointer;
begin
Result := Pointer(fRange);
end;
function TSynCSSyn.GetToken: String;
var
Len: LongInt;
begin
Len := Run - fTokenPos;
SetString(Result, (FLine + fTokenPos), Len);
end;
function TSynCSSyn.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 TSynCSSyn.GetExtTokenID: TxtkTokenKind;
begin
Result := FExtTokenID;
end;
function TSynCSSyn.GetTokenAttribute: TSynHighlighterAttributes;
begin
case fTokenID of
tkAsm: Result := fAsmAttri;
tkComment: Result := fCommentAttri;
tkDirective: Result := fDirecAttri;
tkIdentifier: Result := fIdentifierAttri;
tkKey: Result := fKeyAttri;
tkNumber: Result := fNumberAttri;
tkSpace: Result := fSpaceAttri;
tkString: Result := fStringAttri;
tkSymbol: Result := fSymbolAttri;
tkUnknown: Result := fInvalidAttri;
else Result := nil;
end;
end;
function TSynCSSyn.GetTokenKind: integer;
begin
Result := Ord(GetTokenID);
end;
function TSynCSSyn.GetTokenPos: Integer;
begin
Result := fTokenPos;
end;
procedure TSynCSSyn.ResetRange;
begin
fRange:= rsUnknown;
end;
procedure TSynCSSyn.SetRange(Value: Pointer);
begin
fRange := TRangeState(Value);
end;
procedure TSynCSSyn.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 TSynCSSyn.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;
tmpNumberAttri : 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('');
tmpNumberAttri := 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);
tmpNumberAttri .Assign(fNumberAttri);
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],fSpaceAttri,'Whitespace') and
ReadCPPBSetting(s[settingIndex],fStringAttri,'String') and
ReadCPPBSetting(s[settingIndex],fSymbolAttri,'Symbol') and
ReadCPPBSetting(s[settingIndex],fDirecAttri,'Preprocessor');
if not Result then begin
fStringAttri .Assign(tmpStringAttri);
fNumberAttri .Assign(tmpNumberAttri);
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;
tmpNumberAttri .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; { TSynCSSyn.UseUserSettings }
function TSynCSSyn.GetIdentChars: TSynIdentChars;
begin
Result := ['_', '0'..'9', 'a'..'z', 'A'..'Z'];
end;
function TSynCSSyn.GetSampleSource: string;
begin
Result := '/* Syntax Highlighting */'#13#10 +
'int num = 12345;'#13#10 +
'string str = "Hello World";'#13#10;
end; { GetSampleSource }
class function TSynCSSyn.GetLanguageName: string;
begin
Result := SYNS_LangCS;
end;
function TSynCSSyn.IsFilterStored: boolean;
begin
Result := fDefaultFilter <> SYNS_FilterCS;
end;
class function TSynCSSyn.GetCapabilities: TSynHighlighterCapabilities;
begin
Result := inherited GetCapabilities + [hcUserSettings];
end;
initialization
MakeIdentTable;
{$IFNDEF SYN_CPPB_1}
RegisterPlaceableHighlighter(TSynCSSyn);
{$ENDIF}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -