📄 synhighlighterasm.pas
字号:
#39 : fProcTable[I] := SingleQuoteStringProc;
'>' : fProcTable[I] := GreaterProc;
'<' : fProcTable[I] := LowerProc;
'/' : fProcTable[I] := SlashProc;
'A'..'Z', 'a'..'z', '_':
fProcTable[I] := IdentProc;
'0'..'9':
fProcTable[I] := NumberProc;
#1..#9, #11, #12, #14..#32:
fProcTable[I] := SpaceProc;
'#', ';':
fProcTable[I] := CommentProc;
'.', ':', '&', '{', '}', '=', '^', '-', '+', '(', ')', '*':
fProcTable[I] := SymbolProc;
else
fProcTable[I] := UnknownProc;
end;
end;
constructor TSynAsmSyn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fKeywords := TSynHashEntryList.Create;
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);
MakeMethodTables;
EnumerateKeywords(Ord(tkKey), OpCodes, IdentChars, DoAddKeyword);
SetAttributesOnChange(DefHighlightChange);
fDefaultFilter := SYNS_FilterX86Assembly;
end;
destructor TSynAsmSyn.Destroy;
begin
fKeywords.Free;
inherited Destroy;
end;
procedure TSynAsmSyn.SetLine(NewValue: String; LineNumber:Integer);
begin
fLine := PChar(NewValue);
Run := 0;
fLineNumber := LineNumber;
Next;
end;
procedure TSynAsmSyn.CommentProc;
begin
fTokenID := tkComment;
repeat
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end;
procedure TSynAsmSyn.CRProc;
begin
fTokenID := tkSpace;
Inc(Run);
if fLine[Run] = #10 then Inc(Run);
end;
procedure TSynAsmSyn.GreaterProc;
begin
Inc(Run);
fTokenID := tkSymbol;
if fLine[Run] = '=' then Inc(Run);
end;
procedure TSynAsmSyn.IdentProc;
begin
fTokenID := IdentKind((fLine + Run));
inc(Run, fStringLen);
while Identifiers[fLine[Run]] do inc(Run);
end;
procedure TSynAsmSyn.LFProc;
begin
fTokenID := tkSpace;
inc(Run);
end;
procedure TSynAsmSyn.LowerProc;
begin
Inc(Run);
fTokenID := tkSymbol;
if fLine[Run] in ['=', '>'] then Inc(Run);
end;
procedure TSynAsmSyn.NullProc;
begin
fTokenID := tkNull;
end;
procedure TSynAsmSyn.NumberProc;
begin
inc(Run);
fTokenID := tkNumber;
while FLine[Run] in ['0'..'9', '.', 'a'..'f', 'h', 'A'..'F', 'H'] do
Inc(Run);
end;
procedure TSynAsmSyn.SlashProc;
begin
Inc(Run);
if fLine[Run] = '/' then begin
fTokenID := tkComment;
repeat
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end else
fTokenID := tkSymbol;
end;
procedure TSynAsmSyn.SpaceProc;
begin
fTokenID := tkSpace;
repeat
Inc(Run);
until (fLine[Run] > #32) or (fLine[Run] in [#0, #10, #13]);
end;
procedure TSynAsmSyn.StringProc;
begin
fTokenID := tkString;
if (FLine[Run + 1] = #34) and (FLine[Run + 2] = #34) then
inc(Run, 2);
repeat
case FLine[Run] of
#0, #10, #13: break;
end;
inc(Run);
until FLine[Run] = #34;
if FLine[Run] <> #0 then inc(Run);
end;
procedure TSynAsmSyn.SingleQuoteStringProc;
begin
fTokenID := tkString;
if (FLine[Run + 1] = #39) and (FLine[Run + 2] = #39) then
inc(Run, 2);
repeat
case FLine[Run] of
#0, #10, #13: break;
end;
inc(Run);
until FLine[Run] = #39;
if FLine[Run] <> #0 then inc(Run);
end;
procedure TSynAsmSyn.SymbolProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynAsmSyn.UnknownProc;
begin
{$IFDEF SYN_MBCSSUPPORT}
if FLine[Run] in LeadBytes then
Inc(Run, 2)
else
{$ENDIF}
inc(Run);
fTokenID := tkIdentifier;
end;
procedure TSynAsmSyn.Next;
begin
fTokenPos := Run;
fProcTable[fLine[Run]];
end;
function TSynAsmSyn.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 TSynAsmSyn.GetEol: Boolean;
begin
Result := fTokenId = tkNull;
end;
function TSynAsmSyn.GetToken: String;
var
Len: LongInt;
begin
Len := Run - fTokenPos;
SetString(Result, (FLine + fTokenPos), Len);
end;
function TSynAsmSyn.GetTokenAttribute: TSynHighlighterAttributes;
begin
case fTokenID of
tkComment: Result := fCommentAttri;
tkIdentifier: Result := fIdentifierAttri;
tkKey: Result := fKeyAttri;
tkNumber: Result := fNumberAttri;
tkSpace: Result := fSpaceAttri;
tkString: Result := fStringAttri;
tkSymbol: Result := fSymbolAttri;
tkUnknown: Result := fIdentifierAttri;
else Result := nil;
end;
end;
function TSynAsmSyn.GetTokenKind: integer;
begin
Result := Ord(fTokenId);
end;
function TSynAsmSyn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
end;
function TSynAsmSyn.GetTokenPos: Integer;
begin
Result := fTokenPos;
end;
function TSynAsmSyn.GetIdentChars: TSynIdentChars;
begin
Result := TSynValidStringChars;
end;
class function TSynAsmSyn.GetLanguageName: string;
begin
Result := SYNS_LangX86Asm;
end;
function TSynAsmSyn.IsFilterStored: Boolean;
begin
Result := fDefaultFilter <> SYNS_FilterX86Assembly;
end;
function TSynAsmSyn.GetSampleSource: string;
begin
Result := '; x86 assembly sample source'#13#10 +
' CODE SEGMENT BYTE PUBLIC'#13#10 +
' ASSUME CS:CODE'#13#10 +
#13#10 +
' PUSH SS'#13#10 +
' POP DS'#13#10 +
' MOV AX, AABBh'#13#10 +
' MOV BYTE PTR ES:[DI], 255'#13#10 +
' JMP SHORT AsmEnd'#13#10 +
#13#10 +
' welcomeMsg DB ''Hello World'', 0'#13#10 +
#13#10 +
' AsmEnd:'#13#10 +
' MOV AX, 0'#13#10 +
#13#10 +
' CODE ENDS'#13#10 +
'END';
end;
initialization
MakeIdentTable;
{$IFNDEF SYN_CPPB_1}
RegisterPlaceableHighlighter(TSynAsmSyn);
{$ENDIF}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -