SynEdit: Pas-HL, optional highlight PasDoc tokens in comments. Issue #19711

This commit is contained in:
Martin 2023-06-13 15:14:41 +02:00
parent 06bb1297c7
commit ea5c133400
21 changed files with 338 additions and 4 deletions

View File

@ -289,6 +289,14 @@ msgstr ""
msgid "Diff Original File"
msgstr ""
#: syneditstrconst.syns_attrpasdockey
msgid "PasDoc Keyword"
msgstr ""
#: syneditstrconst.syns_attrpasdocsymbol
msgid "PasDoc Symbol"
msgstr ""
#: syneditstrconst.syns_attrplsql
msgid "Reserved word (PL/SQL)"
msgstr ""

View File

@ -291,6 +291,14 @@ msgstr "Operátor"
msgid "Diff Original File"
msgstr "Porovnat původní soubor"
#: syneditstrconst.syns_attrpasdockey
msgid "PasDoc Keyword"
msgstr ""
#: syneditstrconst.syns_attrpasdocsymbol
msgid "PasDoc Symbol"
msgstr ""
#: syneditstrconst.syns_attrplsql
msgid "Reserved word (PL/SQL)"
msgstr "Vyhrazené slovo (PL/SQL)"

View File

@ -293,6 +293,14 @@ msgstr "Operator"
msgid "Diff Original File"
msgstr "Ursprüngliches Diff-Datei"
#: syneditstrconst.syns_attrpasdockey
msgid "PasDoc Keyword"
msgstr ""
#: syneditstrconst.syns_attrpasdocsymbol
msgid "PasDoc Symbol"
msgstr ""
#: syneditstrconst.syns_attrplsql
msgid "Reserved word (PL/SQL)"
msgstr "Reserviertes Wort (PL/SQL)"

View File

@ -291,6 +291,14 @@ msgstr "Operador"
msgid "Diff Original File"
msgstr "Diferencia archivo Original"
#: syneditstrconst.syns_attrpasdockey
msgid "PasDoc Keyword"
msgstr ""
#: syneditstrconst.syns_attrpasdocsymbol
msgid "PasDoc Symbol"
msgstr ""
#: syneditstrconst.syns_attrplsql
msgid "Reserved word (PL/SQL)"
msgstr "Palabra reservada (PL/SQL)"

View File

@ -284,6 +284,14 @@ msgstr "Operaattori"
msgid "Diff Original File"
msgstr ""
#: syneditstrconst.syns_attrpasdockey
msgid "PasDoc Keyword"
msgstr ""
#: syneditstrconst.syns_attrpasdocsymbol
msgid "PasDoc Symbol"
msgstr ""
#: syneditstrconst.syns_attrplsql
msgid "Reserved word (PL/SQL)"
msgstr "Varattu sana (PL/SQL)"

View File

@ -291,6 +291,14 @@ msgstr "Opérateur"
msgid "Diff Original File"
msgstr "Fichier d'origine (Diff)"
#: syneditstrconst.syns_attrpasdockey
msgid "PasDoc Keyword"
msgstr ""
#: syneditstrconst.syns_attrpasdocsymbol
msgid "PasDoc Symbol"
msgstr ""
#: syneditstrconst.syns_attrplsql
msgid "Reserved word (PL/SQL)"
msgstr "Mot réservé (PL/SQL)"

View File

@ -289,6 +289,14 @@ msgstr "אופרטור"
msgid "Diff Original File"
msgstr "השווה קובץ מקורי"
#: syneditstrconst.syns_attrpasdockey
msgid "PasDoc Keyword"
msgstr ""
#: syneditstrconst.syns_attrpasdocsymbol
msgid "PasDoc Symbol"
msgstr ""
#: syneditstrconst.syns_attrplsql
msgid "Reserved word (PL/SQL)"
msgstr "מלה שמורה (PL/SQL)"

View File

@ -291,6 +291,14 @@ msgstr "Operátor"
msgid "Diff Original File"
msgstr "Diff - eredeti fájl"
#: syneditstrconst.syns_attrpasdockey
msgid "PasDoc Keyword"
msgstr ""
#: syneditstrconst.syns_attrpasdocsymbol
msgid "PasDoc Symbol"
msgstr ""
#: syneditstrconst.syns_attrplsql
msgid "Reserved word (PL/SQL)"
msgstr "Védett szó (PL/SQL)"

View File

@ -292,6 +292,14 @@ msgstr ""
msgid "Diff Original File"
msgstr ""
#: syneditstrconst.syns_attrpasdockey
msgid "PasDoc Keyword"
msgstr ""
#: syneditstrconst.syns_attrpasdocsymbol
msgid "PasDoc Symbol"
msgstr ""
#: syneditstrconst.syns_attrplsql
msgid "Reserved word (PL/SQL)"
msgstr ""

View File

@ -292,6 +292,14 @@ msgstr "Operatore"
msgid "Diff Original File"
msgstr "File originale Diff"
#: syneditstrconst.syns_attrpasdockey
msgid "PasDoc Keyword"
msgstr ""
#: syneditstrconst.syns_attrpasdocsymbol
msgid "PasDoc Symbol"
msgstr ""
#: syneditstrconst.syns_attrplsql
msgid "Reserved word (PL/SQL)"
msgstr "Parola riservata (PL/SQL)"

View File

@ -292,6 +292,14 @@ msgstr "Operatorius"
msgid "Diff Original File"
msgstr "Skirtumų originalo failas"
#: syneditstrconst.syns_attrpasdockey
msgid "PasDoc Keyword"
msgstr ""
#: syneditstrconst.syns_attrpasdocsymbol
msgid "PasDoc Symbol"
msgstr ""
#: syneditstrconst.syns_attrplsql
msgid "Reserved word (PL/SQL)"
msgstr "Rezervuotas žodis (PL/SQL)"

View File

@ -289,6 +289,14 @@ msgstr ""
msgid "Diff Original File"
msgstr ""
#: syneditstrconst.syns_attrpasdockey
msgid "PasDoc Keyword"
msgstr ""
#: syneditstrconst.syns_attrpasdocsymbol
msgid "PasDoc Symbol"
msgstr ""
#: syneditstrconst.syns_attrplsql
msgid "Reserved word (PL/SQL)"
msgstr ""

View File

@ -292,6 +292,14 @@ msgstr ""
msgid "Diff Original File"
msgstr ""
#: syneditstrconst.syns_attrpasdockey
msgid "PasDoc Keyword"
msgstr ""
#: syneditstrconst.syns_attrpasdocsymbol
msgid "PasDoc Symbol"
msgstr ""
#: syneditstrconst.syns_attrplsql
msgid "Reserved word (PL/SQL)"
msgstr ""

View File

@ -281,6 +281,14 @@ msgstr ""
msgid "Diff Original File"
msgstr ""
#: syneditstrconst.syns_attrpasdockey
msgid "PasDoc Keyword"
msgstr ""
#: syneditstrconst.syns_attrpasdocsymbol
msgid "PasDoc Symbol"
msgstr ""
#: syneditstrconst.syns_attrplsql
msgid "Reserved word (PL/SQL)"
msgstr ""

View File

@ -291,6 +291,14 @@ msgstr "Operador"
msgid "Diff Original File"
msgstr "Arquivo Original \"Diff\""
#: syneditstrconst.syns_attrpasdockey
msgid "PasDoc Keyword"
msgstr ""
#: syneditstrconst.syns_attrpasdocsymbol
msgid "PasDoc Symbol"
msgstr ""
#: syneditstrconst.syns_attrplsql
msgid "Reserved word (PL/SQL)"
msgstr "Palavra reservada (PL/SQL)"

View File

@ -291,6 +291,14 @@ msgstr "Оператор"
msgid "Diff Original File"
msgstr "Исходный файл Diff"
#: syneditstrconst.syns_attrpasdockey
msgid "PasDoc Keyword"
msgstr ""
#: syneditstrconst.syns_attrpasdocsymbol
msgid "PasDoc Symbol"
msgstr ""
#: syneditstrconst.syns_attrplsql
msgid "Reserved word (PL/SQL)"
msgstr "Зарезервированное слово (PL/SQL)"

View File

@ -292,6 +292,14 @@ msgstr ""
msgid "Diff Original File"
msgstr ""
#: syneditstrconst.syns_attrpasdockey
msgid "PasDoc Keyword"
msgstr ""
#: syneditstrconst.syns_attrpasdocsymbol
msgid "PasDoc Symbol"
msgstr ""
#: syneditstrconst.syns_attrplsql
msgid "Reserved word (PL/SQL)"
msgstr ""

View File

@ -294,6 +294,14 @@ msgstr "Оператор"
msgid "Diff Original File"
msgstr "Порівняти оригінальний файл"
#: syneditstrconst.syns_attrpasdockey
msgid "PasDoc Keyword"
msgstr ""
#: syneditstrconst.syns_attrpasdocsymbol
msgid "PasDoc Symbol"
msgstr ""
#: syneditstrconst.syns_attrplsql
msgid "Reserved word (PL/SQL)"
msgstr "Зарезервоване слово (PL/SQL)"

View File

@ -292,6 +292,14 @@ msgstr "操作符"
msgid "Diff Original File"
msgstr "比较原始文件"
#: syneditstrconst.syns_attrpasdockey
msgid "PasDoc Keyword"
msgstr ""
#: syneditstrconst.syns_attrpasdocsymbol
msgid "PasDoc Symbol"
msgstr ""
#: syneditstrconst.syns_attrplsql
msgid "Reserved word (PL/SQL)"
msgstr "保留字(PL/SQL)"

View File

@ -128,6 +128,8 @@ resourcestring
SYNS_AttrSymbol = 'Symbol';
SYNS_AttrProcedureHeaderName = 'Procedure header name';
SYNS_AttrCaseLabel = 'Case label';
SYNS_AttrPasDocKey = 'PasDoc Keyword';
SYNS_AttrPasDocSymbol = 'PasDoc Symbol';
SYNS_AttrSyntaxError = 'SyntaxError';
SYNS_AttrSystem = 'System functions and variables';
SYNS_AttrSystemValue = 'System value';
@ -246,6 +248,8 @@ const
SYNS_XML_AttrSymbol = 'Symbol';
SYNS_XML_AttrProcedureHeaderName = 'Procedure header name';
SYNS_XML_AttrCaseLabel = 'Case label';
SYNS_XML_AttrPasDocKey = 'PasDoc-Keyword';
SYNS_XML_AttrPasDocSymbol = 'PasDoc-Symbol';
SYNS_XML_AttrSyntaxError = 'SyntaxError';
SYNS_XML_AttrSystem = 'System functions and variables';
SYNS_XML_AttrSystemValue = 'System value';

View File

@ -329,6 +329,10 @@ type
fAsmStart: Boolean;
FExtendedKeywordsMode: Boolean;
FNestedComments: boolean;
FUsePasDoc, FIsPasDocKey, FIsPasDocSym, FIsInSlash: Boolean;
FPasDocWordList: TStringList;
fPasDocKeyWordAttri: TSynHighlighterAttributesModifier;
fPasDocSymbolAttri: TSynHighlighterAttributesModifier;
FProcedureHeaderNameAttr: TSynHighlighterAttributesModifier;
FCurProcedureHeaderNameAttr: TSynSelectedColorMergeResult;
FStartCodeFoldBlockLevel: integer; // TODO: rename FStartNestedFoldBlockLevel
@ -365,6 +369,7 @@ type
fSpaceAttri: TSynHighlighterAttributes;
FCaseLabelAttri: TSynHighlighterAttributesModifier;
FCurCaseLabelAttri: TSynSelectedColorMergeResult;
FCurPasDocAttri: TSynSelectedColorMergeResult;
fDirectiveAttri: TSynHighlighterAttributes;
FCompilerMode: TPascalCompilerMode;
fD4syntax: boolean;
@ -372,6 +377,7 @@ type
FDividerDrawConfig: Array [TSynPasDividerDrawLocation] of TSynDividerDrawConfig;
function GetPasCodeFoldRange: TSynPasSynRange;
procedure PasDocAttrChanged(Sender: TObject);
procedure SetCompilerMode(const AValue: TPascalCompilerMode);
procedure SetExtendedKeywordsMode(const AValue: Boolean);
procedure SetNestedComments(const ANestedComments: boolean);
@ -478,6 +484,7 @@ type
procedure MakeMethodTables;
procedure AddressOpProc;
procedure AsciiCharProc;
function CheckPasDoc(APeekOnly: Boolean = False): boolean;
procedure AnsiProc;
procedure BorProc;
procedure BraceOpenProc;
@ -647,6 +654,9 @@ type
read FStringKeywordMode write SetStringKeywordMode default spsmDefault;
property StringMultilineMode: TSynPasMultilineStringModes
read FStringMultilineMode write SetStringMultilineMode;
property PasDocKeyWord: TSynHighlighterAttributesModifier read fPasDocKeyWordAttri write fPasDocKeyWordAttri;
property PasDocSymbol: TSynHighlighterAttributesModifier read fPasDocSymbolAttri write fPasDocSymbolAttri;
end;
{ TSynFreePascalSyn }
@ -698,6 +708,60 @@ const
'try'
);
RESERVED_PASDOC: array [1..51] of String = ( // all lowercase
'abstract',
'anchor',
'author',
'bold',
'br',
'cell',
'classname',
'code',
'created',
'cvs',
'definitionlist',
'deprecated',
'exclude',
'false',
'html',
'image',
'include',
'includecode',
'inherited',
'inheritedclass',
'italic',
'item',
'itemlabel',
'itemsetnumber',
'itemspacing',
'lastmod',
'latex',
'link',
'longcode',
'member',
'name',
'nil',
'noautolink',
'noautolinkhere',
'orderedlist',
'param',
'preformatted',
'raises',
'return',
'returns',
'row',
'rowhead',
'section',
'seealso',
'shorttitle',
'table',
'tableofcontents',
'title',
'true',
'unorderedlist',
'value'
);
RESERVED_WORDS_FPC: array [1..5] of String = (
'dispose', 'exit', 'false', 'new', 'true'
);
@ -846,6 +910,11 @@ begin
fIdentFuncTable[181] := @Func181;
fIdentFuncTable[191] := @Func191;
fIdentFuncTable[220] := @Func220;
FPasDocWordList.Clear;
for i := low(RESERVED_PASDOC) to high(RESERVED_PASDOC) do
FPasDocWordList.Add(RESERVED_PASDOC[i]);
FPasDocWordList.Sorted := True;
end;
function TSynPasSyn.KeyHash: Integer;
@ -963,6 +1032,13 @@ begin
Result := TSynPasSynRange(CodeFoldRange);
end;
procedure TSynPasSyn.PasDocAttrChanged(Sender: TObject);
begin
FUsePasDoc := fPasDocKeyWordAttri.IsEnabled or
fPasDocSymbolAttri.IsEnabled;
DefHighlightChange(Sender);
end;
function TSynPasSyn.Func15: TtkTokenKind;
begin
if KeyComp('If') then begin
@ -2898,8 +2974,20 @@ begin
fDirectiveAttri := TSynHighlighterAttributes.Create(@SYNS_AttrDirective, SYNS_XML_AttrDirective);
fDirectiveAttri.Style:= [fsItalic];
AddAttribute(fDirectiveAttri);
fPasDocKeyWordAttri := TSynHighlighterAttributesModifier.Create(@SYNS_AttrPasDocKey, SYNS_XML_AttrPasDocKey);
fPasDocKeyWordAttri.Clear;
AddAttribute(fPasDocKeyWordAttri);
fPasDocSymbolAttri := TSynHighlighterAttributesModifier.Create(@SYNS_AttrPasDocSymbol, SYNS_XML_AttrPasDocSymbol);
fPasDocSymbolAttri.Clear;
AddAttribute(fPasDocSymbolAttri);
FCurPasDocAttri := TSynSelectedColorMergeResult.Create(@SYNS_AttrCaseLabel, SYNS_XML_AttrCaseLabel);
FPasDocWordList := TStringList.Create;
CompilerMode:=pcmDelphi;
SetAttributesOnChange(@DefHighlightChange);
fPasDocKeyWordAttri.OnChange := @PasDocAttrChanged;
fPasDocSymbolAttri.OnChange := @PasDocAttrChanged;
InitIdent;
MakeMethodTables;
@ -2914,6 +3002,8 @@ begin
FreeAndNil(FCurCaseLabelAttri);
FreeAndNil(FCurIDEDirectiveAttri);
FreeAndNil(FCurProcedureHeaderNameAttr);
FreeAndNil(FCurPasDocAttri);
FreeAndNil(FPasDocWordList);
inherited Destroy;
end;
@ -2937,6 +3027,7 @@ begin
fLineLen:=length(fLineStr);
fLine:=PChar(Pointer(fLineStr));
Run := 0;
FIsInSlash := False;
Inherited SetLine(NewValue,LineNumber);
PasCodeFoldRange.LastLineCodeFoldLevelFix := 0;
PasCodeFoldRange.PasFoldFixLevel := 0;
@ -2999,6 +3090,41 @@ begin
end;
end;
function TSynPasSyn.CheckPasDoc(APeekOnly: Boolean): boolean;
var
p, r: LongInt;
s: string;
begin
Result := False;
r := Run;
inc(Run); // the @
if fLine[Run] in ['(', ')', '-'] then begin
inc(Run);
FIsPasDocSym := not APeekOnly;
Result := True;
if APeekOnly then
Run := r;
exit;
end;
p := Run;
while fLine[Run] in ['A'..'Z', 'a'..'z'] do
inc(Run);
if p = Run then begin
if APeekOnly then
Run := r;
exit;
end;
SetLength(s, Run - p);
move(fLine[p], s[1], Run - p);
Result := FPasDocWordList.IndexOf(LowerCase(s)) >= 0;
FIsPasDocKey := Result and not APeekOnly;
if APeekOnly then
Run := r;
end;
procedure TSynPasSyn.BorProc;
var
p: LongInt;
@ -3007,6 +3133,12 @@ begin
fTokenID := tkComment;
if rsIDEDirective in fRange then
fTokenID := tkIDEDirective;
if FUsePasDoc and not(rsIDEDirective in fRange) and (fLine[Run] = '@') then begin
if CheckPasDoc then
exit;
end;
repeat
case fLine[p] of
#0,#10,#13: break;
@ -3030,6 +3162,13 @@ begin
StartPascalCodeFoldBlock(cfbtNestedComment);
p:=Run;
end;
'@': begin
if FUsePasDoc and not(rsIDEDirective in fRange) then begin
Run := p;
if CheckPasDoc(True) then
exit;
end;
end;
end;
Inc(p);
until (p>=fLineLen);
@ -3248,6 +3387,8 @@ begin
StartPascalCodeFoldBlock(cfbtBorCommand);
inc(Run);
end;
if FUsePasDoc and (fLine[Run] = '@') and CheckPasDoc(True) then
exit;
BorProc;
end;
end;
@ -3433,6 +3574,11 @@ end;
procedure TSynPasSyn.AnsiProc;
begin
fTokenID := tkComment;
if FUsePasDoc and (fLine[Run] = '@') then begin
if CheckPasDoc then
exit;
end;
repeat
if fLine[Run]=#0 then
break
@ -3455,6 +3601,9 @@ begin
StartPascalCodeFoldBlock(cfbtNestedComment);
Inc(Run,2);
end else
if FUsePasDoc and (fLine[Run] = '@') and CheckPasDoc(True) then
exit
else
Inc(Run);
until (Run>=fLineLen) or (fLine[Run] in [#0, #10, #13]);
end;
@ -3478,6 +3627,8 @@ begin
StartPascalCodeFoldBlock(cfbtAnsiComment);
Inc(Run, 2);
if not (fLine[Run] in [#0, #10, #13]) then begin
if FUsePasDoc and (fLine[Run] = '@') and CheckPasDoc(True) then
exit;
AnsiProc;
end;
end;
@ -3600,8 +3751,12 @@ begin
StartPascalCodeFoldBlock(cfbtSlashComment);
end;
inc(Run, 2);
FIsInSlash := True;
while not(fLine[Run] in [#0, #10, #13]) do
Inc(Run);
if FUsePasDoc and (fLine[Run] = '@') and CheckPasDoc(True) then
exit
else
Inc(Run);
end else begin
Inc(Run);
fTokenID := tkSymbol;
@ -3612,11 +3767,20 @@ end;
procedure TSynPasSyn.SlashContinueProc;
begin
if (fLine[Run] = '/') and (fLine[Run + 1] = '/') then begin
if FIsInSlash and (fLine[Run] = '@') then begin
if CheckPasDoc then
exit;
end;
if FIsInSlash or ((fLine[Run] = '/') and (fLine[Run + 1] = '/')) then begin
FIsInSlash := True;
// Continue fold block
fTokenID := tkComment;
while not(fLine[Run] in [#0, #10, #13]) do
Inc(Run);
if FUsePasDoc and (fLine[Run] = '@') and CheckPasDoc(True) then
exit
else
Inc(Run);
exit;
end;
@ -3723,8 +3887,10 @@ var
IsAtCaseLabel: Boolean;
begin
fAsmStart := False;
FIsPasDocKey := False;
FIsPasDocSym := False;
FTokenIsCaseLabel := False;
fTokenPos := Run;
FTokenIsCaseLabel := False;
if Run>=fLineLen then begin
NullProc;
exit;
@ -3888,6 +4054,18 @@ begin
Result := FCurCaseLabelAttri;
end;
if FIsPasDocKey then begin
FCurPasDocAttri.Assign(Result);
FCurPasDocAttri.Merge(fPasDocKeyWordAttri);
Result := FCurPasDocAttri;
end
else
if FIsPasDocSym then begin
FCurPasDocAttri.Assign(Result);
FCurPasDocAttri.Merge(fPasDocSymbolAttri);
Result := FCurPasDocAttri;
end;
if (tid in [tkIdentifier, tkSymbol]) and
(fRange * [rsInProcHeader, rsAfterEqualOrColon, rsAfterEqual] = [rsInProcHeader]) and
(tfProcName in FTokenFlags) and