📄 synhighlighterldraw.pas
字号:
if fLine[Run] = #10 then
inc(Run);
end;
procedure TSynLDRSyn.LFProc;
begin
fTokenID := tkUnknown;
inc(Run);
end;
constructor TSynLDRSyn.Create(AOwner: TComponent);
{$IFDEF SYN_KYLIX}
function RGB(r, g, b: Byte): LongWord;
begin
Result := (r or (g shl 8) or (b shl 16));
end;
{$ENDIF}
begin
inherited Create(AOwner);
fColorAttri := TSynHighLighterAttributes.Create(SYNS_AttrColor);
fColorAttri.Foreground := clNavy;
AddAttribute(fColorAttri);
fCommentAttri := TSynHighLighterAttributes.Create(SYNS_AttrComment);
fCommentAttri.Foreground := clBlue;
AddAttribute(fCommentAttri);
fFirstTriAttri := TSynHighLighterAttributes.Create(SYNS_AttrFirstTri);
fFirstTriAttri.Foreground := RGB(206,111,73);
AddAttribute(fFirstTriAttri);
fFourthTriAttri := TSynHighLighterAttributes.Create(SYNS_AttrFourthTri);
fFourthTriAttri.Foreground := RGB(54,99,12);
AddAttribute(fFourthTriAttri);
fIdentifierAttri := TSynHighLighterAttributes.Create(SYNS_AttrIdentifier);
AddAttribute(fIdentifierAttri);
fKeyAttri := TSynHighLighterAttributes.Create(SYNS_AttrReservedWord);
fKeyAttri.Style := [fsBold];
AddAttribute(fKeyAttri);
fLineAttri := TSynHighLighterAttributes.Create(SYNS_AttrLine);
fLineAttri.Foreground := clBlack;
AddAttribute(fLineAttri);
fOpLineAttri := TSynHighLighterAttributes.Create(SYNS_AttrOpLine);
fOpLineAttri.Foreground := clBlack;
AddAttribute(fOpLineAttri);
fQuadAttri := TSynHighLighterAttributes.Create(SYNS_AttrQuad);
fQuadAttri.Foreground := clRed;
AddAttribute(fQuadAttri);
fSecondTriAttri := TSynHighLighterAttributes.Create(SYNS_AttrSecondTri);
fSecondTriAttri.Foreground := RGB(54,99,12);
AddAttribute(fSecondTriAttri);
fThirdTriAttri := TSynHighLighterAttributes.Create(SYNS_AttrThirdTri);
fThirdTriAttri.Foreground := RGB(206,111,73);
AddAttribute(fThirdTriAttri);
fTriangleAttri := TSynHighLighterAttributes.Create(SYNS_AttrTriangle);
fTriangleAttri.Foreground := clBlack;
AddAttribute(fTriangleAttri);
SetAttributesOnChange(DefHighlightChange);
InitIdent;
MakeMethodTables;
fDefaultFilter := SYNS_FilterLDraw;
fRange := rsUnknown;
end;
procedure TSynLDRSyn.SetLine(NewValue: String; LineNumber: Integer);
begin
fLine := PChar(NewValue);
Run := 0;
fLineNumber := LineNumber;
Next;
end;
function TSynLDRSyn.FirstChar(DatLine: PChar): Char;
var
index: Integer;
begin
index := 0;
while DATLine[index] = ' ' do inc(index);
Result := DATLine[index];
end;
procedure TSynLDRSyn.IdentProc;
begin
if FirstChar(fLine) = '0' then
begin
fTokenID := tkComment;
while (fLine[Run] <> #10) and (fLine[Run] <> #13)
and (fLine[Run] <> #0) do inc(Run);
end
else
begin
fTokenID := IdentKind((fLine + Run));
inc(Run, fStringLen);
while Identifiers[fLine[Run]] do
Inc(Run);
end;
end;
procedure TSynLDRSyn.Number1Proc;
function ArgNumber(DatLine: PChar): Byte;
var
index: Integer;
flag: Boolean;
begin
index := 0;
Result := 0;
flag := false;
while index <= Run do
begin
if DatLine[index] = ' ' then
begin
inc(index);
flag := false;
end
else
begin
if flag = false then inc(Result);
flag := true;
inc(index)
end;
end;
end;
begin
case ArgNumber(fLine) of
1: begin
case fLine[Run] of
'0': fTokenID := tkComment;
'1': fTokenID := tkIdentifier;
'2': fTokenID := tkLine;
'3': fTokenID := tkTriangle;
'4': fTokenID := tkQuad;
'5': fTokenID := tkOpLine;
end;
end;
2: if FirstChar(fLine) <> '0' then fTokenID := tkColor
else fTokenID := tkComment;
3..5: if FirstChar(fLine) <> '0' then fTokenID := tkFirstTri
else fTokenID := tkComment;
6..8: if FirstChar(fLine) <> '0' then fTokenID := tkSecondTri
else fTokenID := tkComment;
9..11: if FirstChar(fLine) <> '0' then fTokenID := tkThirdTri
else fTokenID := tkComment;
12..14: if FirstChar(fLine) <> '0' then fTokenID := tkFourthTri
else fTokenID := tkComment;
else
fTokenID := tkIdentifier;
end;
while FLine[Run] in ['0'..'9', '.'] do inc(Run);
end;
procedure TSynLDRSyn.UnknownProc;
begin
{$IFDEF SYN_MBCSSUPPORT}
if FLine[Run] in LeadBytes then
Inc(Run, 2)
else
{$ENDIF}
inc(Run);
fTokenID := tkUnknown;
end;
procedure TSynLDRSyn.Next;
begin
fTokenPos := Run;
fProcTable[fLine[Run]];
end;
function TSynLDRSyn.GetDefaultAttribute(Index: integer): TSynHighLighterAttributes;
begin
case Index of
SYN_ATTR_COMMENT : Result := fCommentAttri;
SYN_ATTR_IDENTIFIER : Result := fIdentifierAttri;
SYN_ATTR_KEYWORD : Result := fKeyAttri;
else
Result := nil;
end;
end;
function TSynLDRSyn.GetEol: Boolean;
begin
Result := fTokenID = tkNull;
end;
function TSynLDRSyn.GetKeyWords: string;
begin
Result :=
'Author';
end;
function TSynLDRSyn.GetToken: String;
var
Len: LongInt;
begin
Len := Run - fTokenPos;
SetString(Result, (FLine + fTokenPos), Len);
end;
function TSynLDRSyn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
end;
function TSynLDRSyn.GetTokenAttribute: TSynHighLighterAttributes;
begin
case GetTokenID of
tkColor: Result := fColorAttri;
tkComment: Result := fCommentAttri;
tkFirstTri: Result := fFirstTriAttri;
tkFourthTri: Result := fFourthTriAttri;
tkIdentifier: Result := fIdentifierAttri;
tkKey: Result := fKeyAttri;
tkLine: Result := fLineAttri;
tkOpLine: Result := fOpLineAttri;
tkQuad: Result := fQuadAttri;
tkSecondTri: Result := fSecondTriAttri;
tkThirdTri: Result := fThirdTriAttri;
tkTriangle: Result := fTriangleAttri;
tkUnknown: Result := fIdentifierAttri;
else
Result := nil;
end;
end;
function TSynLDRSyn.GetTokenKind: integer;
begin
Result := Ord(fTokenId);
end;
function TSynLDRSyn.GetTokenPos: Integer;
begin
Result := fTokenPos;
end;
function TSynLDRSyn.GetIdentChars: TSynIdentChars;
begin
Result := ['_', 'a'..'z', 'A'..'Z', '0'..'9'];
end;
function TSynLDRSyn.GetSampleSource: string;
begin
Result := #13#10 +
'Sample source for: '#13#10 +
'Ldraw Parser/Highlighter'#13#10 +
'0 Comment'#13#10 +
'1 16 0 0 0 1 0 0 0 1 0 0 0 1 stud.dat'#13#10 +
'2 16 0 0 0 1 1 1'#13#10 +
'3 16 0 0 0 1 1 1 2 2 2'#13#10 +
'4 16 0 0 0 1 1 1 2 2 2 3 3 3'#13#10 +
'5 16 0 0 0 1 1 1 2 2 2 3 3 3';
end;
function TSynLDRSyn.IsFilterStored: Boolean;
begin
Result := fDefaultFilter <> SYNS_FilterLDraw;
end;
class function TSynLDRSyn.GetLanguageName: string;
begin
Result := SYNS_LangLDraw;
end;
procedure TSynLDRSyn.ResetRange;
begin
fRange := rsUnknown;
end;
procedure TSynLDRSyn.SetRange(Value: Pointer);
begin
fRange := TRangeState(Value);
end;
function TSynLDRSyn.GetRange: Pointer;
begin
Result := Pointer(fRange);
end;
initialization
MakeIdentTable;
{$IFNDEF SYN_CPPB_1}
RegisterPlaceableHighlighter(TSynLDRSyn);
{$ENDIF}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -