📄 synhighlighterawk.pas
字号:
if (fLine[i] = ' ') then begin
while (fLine[i] = ' ') do begin
Inc(i);
end;
if (fLine[i + 0] = 'f') and
(fLine[i + 1] = 'i') and
(fLine[i + 2] = 'l') and
(fLine[i + 3] = 'e') and
(fLine[i + 4] in [#0..#32, ';']) then begin
Run := (i + 4);
end;
end;
end;
end
else begin
fTokenID := tkIdentifier;
end;
end;
procedure TSynAWKSyn.Next;
begin
fTokenPos := Run;
fProcTable[fLine[Run]];
end;
procedure TSynAWKSyn.StringProc;
begin
repeat
Inc(Run);
if (fLine[Run] = '"') and (fLine[Run - 1] <> '\') then begin
fTokenID := tkString;
Inc(Run);
Exit;
end;
until (fLine[Run] in [#0..#31]);
fTokenID := tkIdentifier;
end;
procedure TSynAWKSyn.CommentProc;
begin
fTokenID := tkComment;
while not (fLine[Run] in [#0, #10, #13]) do begin
Inc(Run);
end;
end;
procedure TSynAWKSyn.FieldRefProc;
begin
Inc(Run);
if (fLine[Run] in ['0'..'9']) and
not (fLine[Run + 1] in ['0'..'9', 'a'..'z', 'A'..'Z']) then begin
fTokenID := tkSymbol;
Inc(Run);
end
else begin
fTokenID := tkIdentifier;
end;
end;
procedure TSynAWKSyn.SymbolProc;
begin
fTokenID := tkSymbol;
Inc(Run);
end;
procedure TSynAWKSyn.PlusProc;
begin
fTokenID := tkSymbol;
Inc(Run);
if (fLine[Run] in ['+', '=']) then begin
Inc(Run);
end;
end;
procedure TSynAWKSyn.MinusProc;
begin
fTokenID := tkSymbol;
Inc(Run);
if (fLine[Run] in ['-', '=']) then begin
Inc(Run);
end;
end;
procedure TSynAWKSyn.OpInputProc;
begin
fTokenID := tkSymbol;
Inc(Run);
if (fLine[Run] = '=') then begin
Inc(Run);
end;
end;
procedure TSynAWKSyn.ExclamProc;
begin
fTokenID := tkSymbol;
Inc(Run);
if (fLine[Run] in ['=', '~']) then begin
Inc(Run);
end;
end;
procedure TSynAWKSyn.QuestionProc;
begin
Inc(Run);
if (fLine[Run] = ':') then begin
fTokenID := tkSymbol;
Inc(Run);
end
else begin
fTokenID := tkIdentifier;
end;
end;
procedure TSynAWKSyn.OrProc;
begin
Inc(Run);
if (fLine[Run] = '|') then begin
fTokenID := tkSymbol;
Inc(Run);
end
else begin
fTokenID := tkIdentifier;
end;
end;
procedure TSynAWKSyn.AndProc;
begin
Inc(Run);
if (fLine[Run] = '&') then begin
fTokenID := tkSymbol;
Inc(Run);
end
else begin
fTokenID := tkIdentifier;
end;
end;
constructor TSynAWKSyn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fCommentAttri := TSynHighlighterAttributes.Create(SYNS_AttrComment);
fCommentAttri.Foreground := clBlue;
AddAttribute(fCommentAttri);
fIdentifierAttri := TSynHighlighterAttributes.Create(SYNS_AttrIdentifier);
AddAttribute(fIdentifierAttri);
fInterFuncAttri := TSynHighlighterAttributes.Create(SYNS_AttrInternalFunction);
fInterFuncAttri.Foreground := $00408080;
fInterFuncAttri.Style := [fsBold];
AddAttribute(fInterFuncAttri);
fKeyAttri := TSynHighlighterAttributes.Create(SYNS_AttrReservedWord);
fKeyAttri.Foreground := $00FF0080;
fKeyAttri.Style := [fsBold];
AddAttribute(fKeyAttri);
fNumberAttri := TSynHighlighterAttributes.Create(SYNS_AttrNumber);
AddAttribute(fNumberAttri);
fSpaceAttri := TSynHighlighterAttributes.Create(SYNS_AttrSpace);
AddAttribute(fSpaceAttri);
fStringAttri := TSynHighlighterAttributes.Create(SYNS_AttrString);
fStringAttri.Foreground := clTeal;
AddAttribute(fStringAttri);
fSymbolAttri := TSynHighlighterAttributes.Create(SYNS_AttrSymbol);
fSymbolAttri.Style := [fsBold];
AddAttribute(fSymbolAttri);
fSysVarAttri := TSynHighlighterAttributes.Create(SYNS_AttrSystemValue);
fSysVarAttri.Foreground := $000080FF;
fSysVarAttri.Style := [fsBold];
AddAttribute(fSysVarAttri);
SetAttributesOnChange(DefHighlightChange);
AWKSyntaxList := TStringList.Create;
MakeSyntaxList;
MakeMethodTables;
fDefaultFilter := SYNS_FilterAWK;
end;
destructor TSynAWKSyn.Destroy;
begin
AWKSyntaxList.Free;
inherited Destroy;
end;
procedure TSynAWKSyn.SetLine(NewValue: string; LineNumber: Integer);
begin
fLine := PChar(NewValue);
Run := 0;
fLineNumber := LineNumber;
Next;
end;
procedure TSynAWKSyn.CRProc;
begin
fTokenID := tkSpace;
Inc(Run);
if fLine[Run] = #10 then Inc(Run);
end;
procedure TSynAWKSyn.LFProc;
begin
fTokenID := tkSpace;
Inc(Run);
end;
procedure TSynAWKSyn.NullProc;
begin
fTokenID := tkNull;
end;
procedure TSynAWKSyn.SpaceProc;
begin
Inc(Run);
fTokenID := tkSpace;
while (fLine[Run] in [#1..#9, #11, #12, #14..#32]) do begin
Inc(Run);
end;
end;
function TSynAWKSyn.GetDefaultAttribute(Index: integer): TSynHighlighterAttributes;
begin
case Index of
SYN_ATTR_COMMENT: Result := fCommentAttri;
SYN_ATTR_KEYWORD: Result := fKeyAttri;
SYN_ATTR_WHITESPACE: Result := fSpaceAttri;
SYN_ATTR_SYMBOL: Result := fSymbolAttri;
else
Result := nil;
end;
end;
function TSynAWKSyn.GetEol: Boolean;
begin
Result := fTokenID = tkNull;
end;
function TSynAWKSyn.GetToken: string;
var
len: Longint;
begin
len := (Run - fTokenPos);
SetString(Result, (fLine + fTokenPos), len);
end;
function TSynAWKSyn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
end;
function TSynAWKSyn.GetTokenAttribute: TSynHighlighterAttributes;
begin
case fTokenID of
tkComment: Result := fCommentAttri;
tkIdentifier: Result := fIdentifierAttri;
tkInterFunc: Result := fInterFuncAttri;
tkKey: Result := fKeyAttri;
tkNumber: Result := fNumberAttri;
tkSpace: Result := fSpaceAttri;
tkString: Result := fStringAttri;
tkSymbol: Result := fSymbolAttri;
tkSysVar: Result := fSysVarAttri;
else
Result := nil;
end;
end;
function TSynAWKSyn.GetTokenKind: integer;
begin
Result := Ord(fTokenId);
end;
function TSynAWKSyn.GetTokenPos: Integer;
begin
Result := fTokenPos;
end;
function TSynAWKSyn.GetIdentChars: TSynIdentChars;
begin
Result := ['0'..'9', 'a'..'z', 'A'..'Z'] + TSynSpecialChars;
end;
function TSynAWKSyn.IsFilterStored: Boolean;
begin
Result := fDefaultFilter <> SYNS_FilterAWK;
end;
class function TSynAWKSyn.GetLanguageName: string;
begin
Result := SYNS_LangAWK;
end;
{$IFNDEF SYN_CPPB_1}
initialization
RegisterPlaceableHighlighter(TSynAWKSyn);
{$ENDIF}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -