MG: directive attribute for pascal highlighter

git-svn-id: trunk@658 -
This commit is contained in:
lazarus 2002-02-03 17:02:50 +00:00
parent 7b585c30cd
commit 38c4c4b2d6
2 changed files with 96 additions and 13 deletions

View File

@ -63,10 +63,12 @@ uses
type type
TtkTokenKind = (tkAsm, tkComment, tkIdentifier, tkKey, tkNull, tkNumber, TtkTokenKind = (tkAsm, tkComment, tkIdentifier, tkKey, tkNull, tkNumber,
tkSpace, tkString, tkSymbol, tkUnknown); tkSpace, tkString, tkSymbol, {$IFDEF SYN_LAZARUS}tkDirective, {$ENDIF}
tkUnknown);
TRangeState = (rsANil, rsAnsi, rsAnsiAsm, rsAsm, rsBor, rsBorAsm, rsProperty, TRangeState = (rsANil, rsAnsi, rsAnsiAsm, rsAsm, rsBor, rsBorAsm,
rsUnKnown); {$IFDEF SYN_LAZARUS}rsDirective, rsDirectiveAsm,{$ENDIF}
rsProperty, rsUnKnown);
TProcTableProc = procedure of object; TProcTableProc = procedure of object;
@ -103,6 +105,9 @@ type
fCommentAttri: TSynHighlighterAttributes; fCommentAttri: TSynHighlighterAttributes;
fIdentifierAttri: TSynHighlighterAttributes; fIdentifierAttri: TSynHighlighterAttributes;
fSpaceAttri: TSynHighlighterAttributes; fSpaceAttri: TSynHighlighterAttributes;
{$IFDEF SYN_LAZARUS}
fDirectiveAttri: TSynHighlighterAttributes;
{$ENDIF}
fD4syntax: boolean; fD4syntax: boolean;
{$IFDEF SYN_LAZARUS} {$IFDEF SYN_LAZARUS}
function KeyHash: Integer; function KeyHash: Integer;
@ -199,6 +204,9 @@ type
procedure BraceOpenProc; procedure BraceOpenProc;
procedure ColonOrGreaterProc; procedure ColonOrGreaterProc;
procedure CRProc; procedure CRProc;
{$IFDEF SYN_LAZARUS}
procedure DirectiveProc;
{$ENDIF}
procedure IdentProc; procedure IdentProc;
procedure IntegerProc; procedure IntegerProc;
procedure LFProc; procedure LFProc;
@ -259,6 +267,8 @@ type
write fStringAttri; write fStringAttri;
property SymbolAttri: TSynHighlighterAttributes read fSymbolAttri property SymbolAttri: TSynHighlighterAttributes read fSymbolAttri
write fSymbolAttri; write fSymbolAttri;
property DirectiveAttri: TSynHighlighterAttributes read fDirectiveAttri
write fDirectiveAttri;
property D4syntax: boolean read FD4syntax write SetD4syntax default true; property D4syntax: boolean read FD4syntax write SetD4syntax default true;
end; end;
@ -1068,6 +1078,10 @@ begin
AddAttribute(fStringAttri); AddAttribute(fStringAttri);
fSymbolAttri := TSynHighlighterAttributes.Create(SYNS_AttrSymbol); fSymbolAttri := TSynHighlighterAttributes.Create(SYNS_AttrSymbol);
AddAttribute(fSymbolAttri); AddAttribute(fSymbolAttri);
{$IFDEF SYN_LAZARUS}
fDirectiveAttri := TSynHighlighterAttributes.Create(SYNS_AttrDirective);
AddAttribute(fDirectiveAttri);
{$ENDIF}
SetAttributesOnChange({$IFDEF FPC}@{$ENDIF}DefHighlightChange); SetAttributesOnChange({$IFDEF FPC}@{$ENDIF}DefHighlightChange);
InitIdent; InitIdent;
@ -1140,13 +1154,51 @@ begin
end; end;
end; end;
{$IFDEF SYN_LAZARUS}
procedure TSynPasSyn.DirectiveProc;
begin
case fLine[Run] of
#0: NullProc;
#10: LFProc;
#13: CRProc;
else begin
fTokenID := tkDirective;
repeat
if fLine[Run] = '}' then begin
Inc(Run);
if fRange = rsDirectiveAsm then
fRange := rsAsm
else
fRange := rsUnKnown;
break;
end;
Inc(Run);
until (Run>fLineLen) or (fLine[Run] in [#0, #10, #13]);
end;
end;
end;
{$ENDIF}
procedure TSynPasSyn.BraceOpenProc; procedure TSynPasSyn.BraceOpenProc;
begin begin
if fRange = rsAsm then {$IFDEF SYN_LAZARUS}
fRange := rsBorAsm if (Run=fLineLen) or (fLine[Run+1]<>'$') then begin
else {$ENDIF}
fRange := rsBor; if fRange = rsAsm then
BorProc; fRange := rsBorAsm
else
fRange := rsBor;
BorProc;
{$IFDEF SYN_LAZARUS}
end else begin
inc(Run);
if fRange = rsAsm then
fRange := rsDirectiveAsm
else
fRange := rsDirective;
DirectiveProc;
end;
{$ENDIF}
end; end;
procedure TSynPasSyn.ColonOrGreaterProc; procedure TSynPasSyn.ColonOrGreaterProc;
@ -1405,6 +1457,10 @@ begin
AnsiProc; AnsiProc;
rsBor, rsBorAsm: rsBor, rsBorAsm:
BorProc; BorProc;
{$IFDEF SYN_LAZARUS}
rsDirective, rsDirectiveAsm:
DirectiveProc;
{$ENDIF}
else else
fProcTable[fLine[Run]]; fProcTable[fLine[Run]];
end; end;
@ -1471,6 +1527,9 @@ begin
tkSpace: Result := fSpaceAttri; tkSpace: Result := fSpaceAttri;
tkString: Result := fStringAttri; tkString: Result := fStringAttri;
tkSymbol: Result := fSymbolAttri; tkSymbol: Result := fSymbolAttri;
{$IFDEF SYN_LAZARUS}
tkDirective: Result := fDirectiveAttri;
{$ENDIF}
tkUnknown: Result := fSymbolAttri; tkUnknown: Result := fSymbolAttri;
else else
Result := nil; Result := nil;
@ -1573,6 +1632,9 @@ function TSynPasSyn.UseUserSettings(settingIndex: integer): boolean;
tmpSymbolAttri : TSynHighlighterAttributes; tmpSymbolAttri : TSynHighlighterAttributes;
tmpAsmAttri : TSynHighlighterAttributes; tmpAsmAttri : TSynHighlighterAttributes;
tmpCommentAttri : TSynHighlighterAttributes; tmpCommentAttri : TSynHighlighterAttributes;
{$IFDEF SYN_LAZARUS}
tmpDirectiveAttri : TSynHighlighterAttributes;
{$ENDIF}
tmpIdentifierAttri: TSynHighlighterAttributes; tmpIdentifierAttri: TSynHighlighterAttributes;
tmpSpaceAttri : TSynHighlighterAttributes; tmpSpaceAttri : TSynHighlighterAttributes;
s : TStringList; s : TStringList;
@ -1589,6 +1651,9 @@ function TSynPasSyn.UseUserSettings(settingIndex: integer): boolean;
tmpSymbolAttri := TSynHighlighterAttributes.Create(''); tmpSymbolAttri := TSynHighlighterAttributes.Create('');
tmpAsmAttri := TSynHighlighterAttributes.Create(''); tmpAsmAttri := TSynHighlighterAttributes.Create('');
tmpCommentAttri := TSynHighlighterAttributes.Create(''); tmpCommentAttri := TSynHighlighterAttributes.Create('');
{$IFDEF SYN_LAZARUS}
tmpDirectiveAttri := TSynHighlighterAttributes.Create('');
{$ENDIF}
tmpIdentifierAttri:= TSynHighlighterAttributes.Create(''); tmpIdentifierAttri:= TSynHighlighterAttributes.Create('');
tmpSpaceAttri := TSynHighlighterAttributes.Create(''); tmpSpaceAttri := TSynHighlighterAttributes.Create('');
tmpStringAttri .Assign(fStringAttri); tmpStringAttri .Assign(fStringAttri);
@ -1597,10 +1662,16 @@ function TSynPasSyn.UseUserSettings(settingIndex: integer): boolean;
tmpSymbolAttri .Assign(fSymbolAttri); tmpSymbolAttri .Assign(fSymbolAttri);
tmpAsmAttri .Assign(fAsmAttri); tmpAsmAttri .Assign(fAsmAttri);
tmpCommentAttri .Assign(fCommentAttri); tmpCommentAttri .Assign(fCommentAttri);
{$IFDEF SYN_LAZARUS}
tmpDirectiveAttri .Assign(fDirectiveAttri);
{$ENDIF}
tmpIdentifierAttri.Assign(fIdentifierAttri); tmpIdentifierAttri.Assign(fIdentifierAttri);
tmpSpaceAttri .Assign(fSpaceAttri); tmpSpaceAttri .Assign(fSpaceAttri);
Result := ReadDelphiSetting(s[settingIndex],fAsmAttri,'Assembler') Result := ReadDelphiSetting(s[settingIndex],fAsmAttri,'Assembler')
and ReadDelphiSetting(s[settingIndex],fCommentAttri,'Comment') and ReadDelphiSetting(s[settingIndex],fCommentAttri,'Comment')
{$IFDEF SYN_LAZARUS}
and ReadDelphiSetting(s[settingIndex],fDirectiveAttri,'Directive')
{$ENDIF}
and ReadDelphiSetting(s[settingIndex],fIdentifierAttri,'Identifier') and ReadDelphiSetting(s[settingIndex],fIdentifierAttri,'Identifier')
and ReadDelphiSetting(s[settingIndex],fKeyAttri,'Reserved word') and ReadDelphiSetting(s[settingIndex],fKeyAttri,'Reserved word')
and ReadDelphiSetting(s[settingIndex],fNumberAttri,'Number') and ReadDelphiSetting(s[settingIndex],fNumberAttri,'Number')
@ -1614,6 +1685,9 @@ function TSynPasSyn.UseUserSettings(settingIndex: integer): boolean;
fSymbolAttri .Assign(tmpSymbolAttri); fSymbolAttri .Assign(tmpSymbolAttri);
fAsmAttri .Assign(tmpAsmAttri); fAsmAttri .Assign(tmpAsmAttri);
fCommentAttri .Assign(tmpCommentAttri); fCommentAttri .Assign(tmpCommentAttri);
{$IFDEF SYN_LAZARUS}
fDirectiveAttri .Assign(tmpDirectiveAttri);
{$ENDIF}
fIdentifierAttri.Assign(tmpIdentifierAttri); fIdentifierAttri.Assign(tmpIdentifierAttri);
fSpaceAttri .Assign(tmpSpaceAttri); fSpaceAttri .Assign(tmpSpaceAttri);
end; end;
@ -1623,6 +1697,9 @@ function TSynPasSyn.UseUserSettings(settingIndex: integer): boolean;
tmpSymbolAttri .Free; tmpSymbolAttri .Free;
tmpAsmAttri .Free; tmpAsmAttri .Free;
tmpCommentAttri .Free; tmpCommentAttri .Free;
{$IFDEF SYN_LAZARUS}
tmpDirectiveAttri .Free;
{$ENDIF}
tmpIdentifierAttri.Free; tmpIdentifierAttri.Free;
tmpSpaceAttri .Free; tmpSpaceAttri .Free;
end; end;

View File

@ -707,6 +707,7 @@ begin
FileExtensions:='pp;pas;inc;lpr;lrs;dpr;dpk'; FileExtensions:='pp;pas;inc;lpr;lrs;dpr;dpk';
SampleSource:= SampleSource:=
'{ Comment }'#13+ '{ Comment }'#13+
'{$R- compiler directive}'#13+
'procedure TForm1.Button1Click(Sender: TObject);'#13+ 'procedure TForm1.Button1Click(Sender: TObject);'#13+
'var'#13+ 'var'#13+
' Number, I, X: Integer;'#13+ ' Number, I, X: Integer;'#13+
@ -728,11 +729,11 @@ begin
' end;'#13+ ' end;'#13+
'end;'#13+ 'end;'#13+
#13; #13;
AddAttrSampleLines[ahaDisabledBreakpoint]:=17; AddAttrSampleLines[ahaDisabledBreakpoint]:=18;
AddAttrSampleLines[ahaEnabledBreakpoint]:=16; AddAttrSampleLines[ahaEnabledBreakpoint]:=17;
AddAttrSampleLines[ahaErrorLine]:=18; AddAttrSampleLines[ahaErrorLine]:=19;
AddAttrSampleLines[ahaExecutionPoint]:=14; AddAttrSampleLines[ahaExecutionPoint]:=15;
AddAttrSampleLines[ahaTextBlock]:=13; AddAttrSampleLines[ahaTextBlock]:=14;
end; end;
Add(NewInfo); Add(NewInfo);
@ -1304,6 +1305,8 @@ begin
DefFGCol:=clLime; DefFGCol:=clLime;
end else if AttriName='Comment' then begin end else if AttriName='Comment' then begin
DefFGCol:=clGray; DefFGCol:=clGray;
end else if AttriName='Directive' then begin
DefFGCol:=clRed;
end else if AttriName='Reserved word' then begin end else if AttriName='Reserved word' then begin
DefFGCol:=clAqua; DefFGCol:=clAqua;
DefFontStyles:=[fsBold]; DefFontStyles:=[fsBold];
@ -1339,6 +1342,9 @@ begin
end else if AttriName='Comment' then begin end else if AttriName='Comment' then begin
DefFGCol:=clBlue; DefFGCol:=clBlue;
DefFontStyles:=[fsBold]; DefFontStyles:=[fsBold];
end else if AttriName='Directive' then begin
DefFGCol:=clRed;
DefFontStyles:=[fsBold];
end else if AttriName='Reserved word' then begin end else if AttriName='Reserved word' then begin
DefFontStyles:=[fsBold]; DefFontStyles:=[fsBold];
end else if AttriName='Number' then begin end else if AttriName='Number' then begin