mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-28 15:01:06 +02:00
SynEdit, Highlighter: added highlight of case-labels
git-svn-id: trunk@25432 -
This commit is contained in:
parent
99c23d89c7
commit
82018af2fb
@ -84,12 +84,16 @@ type
|
|||||||
property NeedsReScanEndIndex: Integer read FNeedsReScanEndIndex;
|
property NeedsReScanEndIndex: Integer read FNeedsReScanEndIndex;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TSynHighlighterAttrFeature = (hafStyleMask);
|
||||||
|
TSynHighlighterAttrFeatures = set of TSynHighlighterAttrFeature;
|
||||||
{ TSynHighlighterAttributes }
|
{ TSynHighlighterAttributes }
|
||||||
|
|
||||||
TSynHighlighterAttributes = class(TPersistent)
|
TSynHighlighterAttributes = class(TPersistent)
|
||||||
private
|
private
|
||||||
fBackground: TColor;
|
fBackground: TColor;
|
||||||
fBackgroundDefault: TColor; //mh 2000-10-08
|
fBackgroundDefault: TColor; //mh 2000-10-08
|
||||||
|
FFeature: TSynHighlighterAttrFeatures;
|
||||||
|
FFeatures: TSynHighlighterAttrFeatures;
|
||||||
fForeground: TColor;
|
fForeground: TColor;
|
||||||
fForegroundDefault: TColor; //mh 2000-10-08
|
fForegroundDefault: TColor; //mh 2000-10-08
|
||||||
FFrameColor: TColor;
|
FFrameColor: TColor;
|
||||||
@ -140,6 +144,7 @@ type
|
|||||||
property Name: string read fName;
|
property Name: string read fName;
|
||||||
property StoredName: string read FStoredName write FStoredName;
|
property StoredName: string read FStoredName write FStoredName;
|
||||||
property OnChange: TNotifyEvent read fOnChange write fOnChange;
|
property OnChange: TNotifyEvent read fOnChange write fOnChange;
|
||||||
|
property Features: TSynHighlighterAttrFeatures read FFeatures write FFeature;
|
||||||
published
|
published
|
||||||
property Background: TColor read fBackground write SetBackground
|
property Background: TColor read fBackground write SetBackground
|
||||||
stored GetBackgroundColorStored; //mh 2000-10-08
|
stored GetBackgroundColorStored; //mh 2000-10-08
|
||||||
|
@ -133,6 +133,7 @@ resourcestring
|
|||||||
SYNS_AttrSQLPlus = 'SQL*Plus command';
|
SYNS_AttrSQLPlus = 'SQL*Plus command';
|
||||||
SYNS_AttrString = 'String';
|
SYNS_AttrString = 'String';
|
||||||
SYNS_AttrSymbol = 'Symbol';
|
SYNS_AttrSymbol = 'Symbol';
|
||||||
|
SYNS_AttrCaseLabel = 'Case label';
|
||||||
SYNS_AttrSyntaxError = 'SyntaxError';
|
SYNS_AttrSyntaxError = 'SyntaxError';
|
||||||
SYNS_AttrSystem = 'System functions and variables';
|
SYNS_AttrSystem = 'System functions and variables';
|
||||||
SYNS_AttrSystemValue = 'System value';
|
SYNS_AttrSystemValue = 'System value';
|
||||||
@ -240,6 +241,7 @@ const
|
|||||||
SYNS_XML_AttrSQLPlus :String = SYNS_AttrSQLPlus; // 'SQL*Plus command';
|
SYNS_XML_AttrSQLPlus :String = SYNS_AttrSQLPlus; // 'SQL*Plus command';
|
||||||
SYNS_XML_AttrString :String = SYNS_AttrString; // 'String';
|
SYNS_XML_AttrString :String = SYNS_AttrString; // 'String';
|
||||||
SYNS_XML_AttrSymbol :String = SYNS_AttrSymbol; // 'Symbol';
|
SYNS_XML_AttrSymbol :String = SYNS_AttrSymbol; // 'Symbol';
|
||||||
|
SYNS_XML_AttrCaseLabel :String = SYNS_AttrCaseLabel; // 'Case label';
|
||||||
SYNS_XML_AttrSyntaxError :String = SYNS_AttrSyntaxError; // 'SyntaxError';
|
SYNS_XML_AttrSyntaxError :String = SYNS_AttrSyntaxError; // 'SyntaxError';
|
||||||
SYNS_XML_AttrSystem :String = SYNS_AttrSystem; // 'System functions and variables';
|
SYNS_XML_AttrSystem :String = SYNS_AttrSystem; // 'System functions and variables';
|
||||||
SYNS_XML_AttrSystemValue :String = SYNS_AttrSystemValue; // 'System value';
|
SYNS_XML_AttrSystemValue :String = SYNS_AttrSystemValue; // 'System value';
|
||||||
|
@ -83,7 +83,8 @@ type
|
|||||||
// Detect if class/object is ended by ";" or "end;"
|
// Detect if class/object is ended by ";" or "end;"
|
||||||
rsAtClass,
|
rsAtClass,
|
||||||
rsAfterClass,
|
rsAfterClass,
|
||||||
rsAtClosingBracket // ')'
|
rsAtClosingBracket, // ')'
|
||||||
|
rsAtCaseLabel
|
||||||
);
|
);
|
||||||
TRangeStates = set of TRangeState;
|
TRangeStates = set of TRangeState;
|
||||||
|
|
||||||
@ -254,6 +255,7 @@ type
|
|||||||
fIdentFuncTable: array[0..191] of TIdentFuncTableFunc;
|
fIdentFuncTable: array[0..191] of TIdentFuncTableFunc;
|
||||||
fTokenPos: Integer;// start of current token in fLine
|
fTokenPos: Integer;// start of current token in fLine
|
||||||
FTokenID: TtkTokenKind;
|
FTokenID: TtkTokenKind;
|
||||||
|
FTokenIsCaseLabel: Boolean;
|
||||||
fStringAttri: TSynHighlighterAttributes;
|
fStringAttri: TSynHighlighterAttributes;
|
||||||
fNumberAttri: TSynHighlighterAttributes;
|
fNumberAttri: TSynHighlighterAttributes;
|
||||||
fKeyAttri: TSynHighlighterAttributes;
|
fKeyAttri: TSynHighlighterAttributes;
|
||||||
@ -262,6 +264,8 @@ type
|
|||||||
fCommentAttri: TSynHighlighterAttributes;
|
fCommentAttri: TSynHighlighterAttributes;
|
||||||
fIdentifierAttri: TSynHighlighterAttributes;
|
fIdentifierAttri: TSynHighlighterAttributes;
|
||||||
fSpaceAttri: TSynHighlighterAttributes;
|
fSpaceAttri: TSynHighlighterAttributes;
|
||||||
|
FCaseLabelAttri: TSynHighlighterAttributes;
|
||||||
|
FCurCaseLabelAttri: TSynHighlighterAttributes;
|
||||||
{$IFDEF SYN_LAZARUS}
|
{$IFDEF SYN_LAZARUS}
|
||||||
fDirectiveAttri: TSynHighlighterAttributes;
|
fDirectiveAttri: TSynHighlighterAttributes;
|
||||||
FCompilerMode: TPascalCompilerMode;
|
FCompilerMode: TPascalCompilerMode;
|
||||||
@ -504,6 +508,8 @@ type
|
|||||||
write fStringAttri;
|
write fStringAttri;
|
||||||
property SymbolAttri: TSynHighlighterAttributes read fSymbolAttri
|
property SymbolAttri: TSynHighlighterAttributes read fSymbolAttri
|
||||||
write fSymbolAttri;
|
write fSymbolAttri;
|
||||||
|
property CaseLabelAttri: TSynHighlighterAttributes read FCaseLabelAttri
|
||||||
|
write FCaseLabelAttri;
|
||||||
{$IFDEF SYN_LAZARUS}
|
{$IFDEF SYN_LAZARUS}
|
||||||
property DirectiveAttri: TSynHighlighterAttributes read fDirectiveAttri
|
property DirectiveAttri: TSynHighlighterAttributes read fDirectiveAttri
|
||||||
write fDirectiveAttri;
|
write fDirectiveAttri;
|
||||||
@ -894,12 +900,17 @@ begin
|
|||||||
// Accidental start of block // End at next semicolon (usually same line)
|
// Accidental start of block // End at next semicolon (usually same line)
|
||||||
CodeFoldRange.Pop(false); // avoid minlevel
|
CodeFoldRange.Pop(false); // avoid minlevel
|
||||||
CodeFoldRange.Add(Pointer(PtrInt(cfbtUses)), false);
|
CodeFoldRange.Add(Pointer(PtrInt(cfbtUses)), false);
|
||||||
end;
|
end
|
||||||
|
else
|
||||||
|
if (TopPascalCodeFoldBlockType = cfbtCase) then
|
||||||
|
fRange := fRange + [rsAtCaseLabel];
|
||||||
end
|
end
|
||||||
else Result := tkIdentifier;
|
else Result := tkIdentifier;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TSynPasSyn.Func23: TtkTokenKind;
|
function TSynPasSyn.Func23: TtkTokenKind;
|
||||||
|
var
|
||||||
|
tfb: TPascalCodeFoldBlockType;
|
||||||
begin
|
begin
|
||||||
if KeyComp('End') then begin
|
if KeyComp('End') then begin
|
||||||
if ((fToIdent<2) or (fLine[fToIdent-1]<>'@'))
|
if ((fToIdent<2) or (fLine[fToIdent-1]<>'@'))
|
||||||
@ -909,30 +920,34 @@ begin
|
|||||||
PasCodeFoldRange.BracketNestLevel := 0; // Reset in case of partial code
|
PasCodeFoldRange.BracketNestLevel := 0; // Reset in case of partial code
|
||||||
{$IFDEF SYN_LAZARUS}
|
{$IFDEF SYN_LAZARUS}
|
||||||
// there may be more than on block ending here
|
// there may be more than on block ending here
|
||||||
if TopPascalCodeFoldBlockType = cfbtRecord then begin
|
tfb := TopPascalCodeFoldBlockType;
|
||||||
|
if tfb = cfbtRecord then begin
|
||||||
EndPascalCodeFoldBlock;
|
EndPascalCodeFoldBlock;
|
||||||
end else if TopPascalCodeFoldBlockType = cfbtUnit then begin
|
end else if tfb = cfbtUnit then begin
|
||||||
EndPascalCodeFoldBlock;
|
EndPascalCodeFoldBlock;
|
||||||
end else if TopPascalCodeFoldBlockType = cfbtExcept then begin
|
end else if tfb = cfbtExcept then begin
|
||||||
EndPascalCodeFoldBlock;
|
EndPascalCodeFoldBlock;
|
||||||
if TopPascalCodeFoldBlockType = cfbtTry then
|
if TopPascalCodeFoldBlockType = cfbtTry then
|
||||||
EndPascalCodeFoldBlock;
|
EndPascalCodeFoldBlock;
|
||||||
end else if TopPascalCodeFoldBlockType = cfbtTry then begin
|
end else if tfb = cfbtTry then begin
|
||||||
EndPascalCodeFoldBlock;
|
EndPascalCodeFoldBlock;
|
||||||
end else if TopPascalCodeFoldBlockType in [cfbtTopBeginEnd, cfbtAsm] then begin
|
end else if tfb in [cfbtTopBeginEnd, cfbtAsm] then begin
|
||||||
EndPascalCodeFoldBlock;
|
EndPascalCodeFoldBlock;
|
||||||
if TopPascalCodeFoldBlockType in [cfbtProcedure] then
|
if TopPascalCodeFoldBlockType in [cfbtProcedure] then
|
||||||
EndPascalCodeFoldBlock;
|
EndPascalCodeFoldBlock;
|
||||||
if TopPascalCodeFoldBlockType = cfbtProgram then
|
if TopPascalCodeFoldBlockType = cfbtProgram then
|
||||||
EndPascalCodeFoldBlock;
|
EndPascalCodeFoldBlock;
|
||||||
end else if TopPascalCodeFoldBlockType in [cfbtBeginEnd, cfbtCase] then begin
|
end else if tfb in [cfbtCase] then begin
|
||||||
EndPascalCodeFoldBlock;
|
EndPascalCodeFoldBlock;
|
||||||
end else if TopPascalCodeFoldBlockType = cfbtUnitSection then begin
|
fRange := fRange - [rsAtCaseLabel];
|
||||||
|
end else if tfb in [cfbtBeginEnd] then begin
|
||||||
|
EndPascalCodeFoldBlock;
|
||||||
|
end else if tfb = cfbtUnitSection then begin
|
||||||
EndPascalCodeFoldBlockLastLine;
|
EndPascalCodeFoldBlockLastLine;
|
||||||
if TopPascalCodeFoldBlockType = cfbtUnit then // "Unit".."end."
|
if TopPascalCodeFoldBlockType = cfbtUnit then // "Unit".."end."
|
||||||
EndPascalCodeFoldBlock;
|
EndPascalCodeFoldBlock;
|
||||||
end else begin
|
end else begin
|
||||||
if TopPascalCodeFoldBlockType = cfbtClassSection then
|
if tfb = cfbtClassSection then
|
||||||
EndPascalCodeFoldBlockLastLine;
|
EndPascalCodeFoldBlockLastLine;
|
||||||
if TopPascalCodeFoldBlockType = cfbtClass then
|
if TopPascalCodeFoldBlockType = cfbtClass then
|
||||||
EndPascalCodeFoldBlock;
|
EndPascalCodeFoldBlock;
|
||||||
@ -2037,6 +2052,10 @@ begin
|
|||||||
AddAttribute(fStringAttri);
|
AddAttribute(fStringAttri);
|
||||||
fSymbolAttri := TSynHighlighterAttributes.Create(SYNS_AttrSymbol, SYNS_XML_AttrSymbol);
|
fSymbolAttri := TSynHighlighterAttributes.Create(SYNS_AttrSymbol, SYNS_XML_AttrSymbol);
|
||||||
AddAttribute(fSymbolAttri);
|
AddAttribute(fSymbolAttri);
|
||||||
|
FCaseLabelAttri := TSynHighlighterAttributes.Create(SYNS_AttrCaseLabel, SYNS_XML_AttrCaseLabel);
|
||||||
|
AddAttribute(FCaseLabelAttri);
|
||||||
|
FCaseLabelAttri.Features := FCaseLabelAttri.Features + [hafStyleMask];
|
||||||
|
FCurCaseLabelAttri := TSynHighlighterAttributes.Create(SYNS_AttrCaseLabel, SYNS_XML_AttrCaseLabel);
|
||||||
{$IFDEF SYN_LAZARUS}
|
{$IFDEF SYN_LAZARUS}
|
||||||
fDirectiveAttri := TSynHighlighterAttributes.Create(SYNS_AttrDirective, SYNS_XML_AttrDirective);
|
fDirectiveAttri := TSynHighlighterAttributes.Create(SYNS_AttrDirective, SYNS_XML_AttrDirective);
|
||||||
fDirectiveAttri.Style:= [fsItalic];
|
fDirectiveAttri.Style:= [fsItalic];
|
||||||
@ -2056,6 +2075,7 @@ end; { Create }
|
|||||||
destructor TSynPasSyn.Destroy;
|
destructor TSynPasSyn.Destroy;
|
||||||
begin
|
begin
|
||||||
DestroyDividerDrawConfig;
|
DestroyDividerDrawConfig;
|
||||||
|
FreeAndNil(FCurCaseLabelAttri);
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -2307,6 +2327,7 @@ begin
|
|||||||
fTokenID := tkSymbol;
|
fTokenID := tkSymbol;
|
||||||
inc(Run);
|
inc(Run);
|
||||||
if fLine[Run] = '=' then inc(Run);
|
if fLine[Run] = '=' then inc(Run);
|
||||||
|
fRange := fRange - [rsAtCaseLabel];
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSynPasSyn.CRProc;
|
procedure TSynPasSyn.CRProc;
|
||||||
@ -2318,11 +2339,7 @@ end;
|
|||||||
|
|
||||||
procedure TSynPasSyn.IdentProc;
|
procedure TSynPasSyn.IdentProc;
|
||||||
begin
|
begin
|
||||||
{$IFDEF SYN_LAZARUS}
|
|
||||||
fTokenID := IdentKind(Run);
|
fTokenID := IdentKind(Run);
|
||||||
{$ELSE}
|
|
||||||
fTokenID := IdentKind((fLine + Run));
|
|
||||||
{$ENDIF}
|
|
||||||
inc(Run, fStringLen);
|
inc(Run, fStringLen);
|
||||||
while Identifiers[fLine[Run]] do inc(Run);
|
while Identifiers[fLine[Run]] do inc(Run);
|
||||||
end;
|
end;
|
||||||
@ -2521,13 +2538,18 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSynPasSyn.SemicolonProc;
|
procedure TSynPasSyn.SemicolonProc;
|
||||||
|
var
|
||||||
|
tfb: TPascalCodeFoldBlockType;
|
||||||
begin
|
begin
|
||||||
Inc(Run);
|
Inc(Run);
|
||||||
fTokenID := tkSymbol;
|
fTokenID := tkSymbol;
|
||||||
if TopPascalCodeFoldBlockType = cfbtUses then
|
tfb := TopPascalCodeFoldBlockType;
|
||||||
|
if tfb = cfbtUses then
|
||||||
EndPascalCodeFoldBlock;
|
EndPascalCodeFoldBlock;
|
||||||
if (TopPascalCodeFoldBlockType = cfbtClass) and (rsAfterClass in fRange) then
|
if (tfb = cfbtClass) and (rsAfterClass in fRange) then
|
||||||
EndPascalCodeFoldBlock(True);
|
EndPascalCodeFoldBlock(True);
|
||||||
|
if (tfb = cfbtCase) then
|
||||||
|
fRange := fRange + [rsAtCaseLabel];
|
||||||
if (rsProperty in fRange) and (PasCodeFoldRange.BracketNestLevel = 0) then
|
if (rsProperty in fRange) and (PasCodeFoldRange.BracketNestLevel = 0) then
|
||||||
fRange := fRange - [rsProperty];
|
fRange := fRange - [rsProperty];
|
||||||
end;
|
end;
|
||||||
@ -2597,9 +2619,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSynPasSyn.Next;
|
procedure TSynPasSyn.Next;
|
||||||
|
var
|
||||||
|
IsAtCaseLabel: Boolean;
|
||||||
begin
|
begin
|
||||||
fAsmStart := False;
|
fAsmStart := False;
|
||||||
fTokenPos := Run;
|
fTokenPos := Run;
|
||||||
|
FTokenIsCaseLabel := False;
|
||||||
{$IFDEF SYN_LAZARUS}
|
{$IFDEF SYN_LAZARUS}
|
||||||
if Run>=fLineLen then begin
|
if Run>=fLineLen then begin
|
||||||
fTokenID := tkNull;
|
fTokenID := tkNull;
|
||||||
@ -2625,7 +2650,13 @@ begin
|
|||||||
else
|
else
|
||||||
if rsAtClass in fRange then
|
if rsAtClass in fRange then
|
||||||
fRange := fRange + [rsAfterClass] - [rsAtClass];
|
fRange := fRange + [rsAfterClass] - [rsAtClass];
|
||||||
|
IsAtCaseLabel := rsAtCaseLabel in fRange;
|
||||||
fProcTable[fLine[Run]];
|
fProcTable[fLine[Run]];
|
||||||
|
if (IsAtCaseLabel) and (rsAtCaseLabel in fRange) then begin
|
||||||
|
FTokenIsCaseLabel := True;
|
||||||
|
if (FTokenID = tkKey) then
|
||||||
|
fRange := fRange - [rsAtCaseLabel];
|
||||||
|
end;
|
||||||
if not (FTokenID in [tkSpace, tkComment, tkDirective]) then begin
|
if not (FTokenID in [tkSpace, tkComment, tkDirective]) then begin
|
||||||
if (PasCodeFoldRange.BracketNestLevel = 0) and
|
if (PasCodeFoldRange.BracketNestLevel = 0) and
|
||||||
not(rsAtClosingBracket in fRange) then
|
not(rsAtClosingBracket in fRange) then
|
||||||
@ -2700,6 +2731,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TSynPasSyn.GetTokenAttribute: TSynHighlighterAttributes;
|
function TSynPasSyn.GetTokenAttribute: TSynHighlighterAttributes;
|
||||||
|
var
|
||||||
|
sMask: TFontStyles;
|
||||||
begin
|
begin
|
||||||
case GetTokenID of
|
case GetTokenID of
|
||||||
tkAsm: Result := fAsmAttri;
|
tkAsm: Result := fAsmAttri;
|
||||||
@ -2717,6 +2750,18 @@ begin
|
|||||||
else
|
else
|
||||||
Result := nil;
|
Result := nil;
|
||||||
end;
|
end;
|
||||||
|
if FTokenIsCaseLabel and
|
||||||
|
(GetTokenID in [tkIdentifier, tkKey, tkNumber, tkString])
|
||||||
|
then begin
|
||||||
|
FCurCaseLabelAttri.Assign(Result);
|
||||||
|
Result := FCurCaseLabelAttri;
|
||||||
|
if FCaseLabelAttri.Background <> clNone then Result.Background := FCaseLabelAttri.Background;
|
||||||
|
if FCaseLabelAttri.Foreground <> clNone then Result.Foreground := FCaseLabelAttri.Foreground;
|
||||||
|
if FCaseLabelAttri.FrameColor <> clNone then Result.FrameColor := FCaseLabelAttri.FrameColor;
|
||||||
|
sMask := FCaseLabelAttri.StyleMask + (fsNot(FCaseLabelAttri.StyleMask) * FCaseLabelAttri.Style); // Styles to be taken from FCaseLabelAttri
|
||||||
|
Result.Style:= (Result.Style * fsNot(sMask)) + (FCaseLabelAttri.Style * sMask);
|
||||||
|
Result.StyleMask:= (Result.StyleMask * fsNot(sMask)) + (FCaseLabelAttri.StyleMask * sMask);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TSynPasSyn.GetTokenKind: integer;
|
function TSynPasSyn.GetTokenKind: integer;
|
||||||
|
Loading…
Reference in New Issue
Block a user