D highlighter, also highlight first level of UDA when the @() form is used

This commit is contained in:
Basile Burg 2020-05-25 13:40:46 +02:00
parent 293e89f4e5
commit a4b604a60b
2 changed files with 50 additions and 14 deletions

View File

@ -1,9 +1,13 @@
# v3.9.4-dev # v3.9.4-dev
## Enhancements
- D highlighter: highlight `@()` just like `@Identifier` ans skipping the enclosed content. Nested `@()` are still not handled.
## Bugs fixed ## Bugs fixed
- Messages: force auto scrolling to bottom once and if the messages context is modified. - Messages: force auto scrolling to bottom once and if the messages context is modified.
- Terminal: after launcging dexed, the current directory was not constrained even when the settings to follow the current project or document path were activated. (#5) - Terminal: after launching dexed, the current directory was not constrained even when the settings to follow the current project or document path were activated. (#5)
# v3.9.3 # v3.9.3

View File

@ -15,7 +15,7 @@ type
tkDDocs, tkSpecK, tkError, tkAsmbl, tkAttri, tkLost, tkTypes); tkDDocs, tkSpecK, tkError, tkAsmbl, tkAttri, tkLost, tkTypes);
TRangeKind = (rkString1, rkString2, rkBlockCom1, rkBlockCom2, TRangeKind = (rkString1, rkString2, rkBlockCom1, rkBlockCom2,
rkBlockDoc1, rkBlockDoc2, rkAsm, rkBlockDoc1, rkBlockDoc2, rkAsm, rkAttrib,
rkStringQParen, rkStringQSquare, rkStringQGe, rStringQCurly); rkStringQParen, rkStringQSquare, rkStringQGe, rStringQCurly);
TRangeKinds = set of TRangeKind; TRangeKinds = set of TRangeKind;
@ -33,6 +33,7 @@ type
nestedQSquareStrings: Integer; nestedQSquareStrings: Integer;
nestedQGeStrings : Integer; nestedQGeStrings : Integer;
nestedQCurlyStrings : Integer; nestedQCurlyStrings : Integer;
attribParenCount : Integer;
rangeKinds : TRangeKinds; rangeKinds : TRangeKinds;
// double quoted multi-line string prefixed with 'r': // double quoted multi-line string prefixed with 'r':
// => don't skip '"' following '\' // => don't skip '"' following '\'
@ -43,6 +44,7 @@ type
procedure Clear; override; procedure Clear; override;
// //
procedure copyFrom(source: TSynD2SynRange); procedure copyFrom(source: TSynD2SynRange);
function notInExclusiveRange(): boolean;
end; end;
TSynD2Syn = class (TSynCustomFoldHighlighter) TSynD2Syn = class (TSynCustomFoldHighlighter)
@ -186,6 +188,11 @@ begin
end; end;
end; end;
function TSynD2SynRange.notInExclusiveRange(): boolean;
begin
result := rangeKinds - [rkAttrib, rkAsm] = [];
end;
constructor TSynD2Syn.create(aOwner: TComponent); constructor TSynD2Syn.create(aOwner: TComponent);
begin begin
inherited create(aOwner); inherited create(aOwner);
@ -461,7 +468,7 @@ begin
fCurrRange := TSynD2SynRange.Create(nil); fCurrRange := TSynD2SynRange.Create(nil);
// line comments / region beg-end // line comments / region beg-end
if (fCurrRange.rangeKinds = []) or (fCurrRange.rangeKinds = [rkAsm]) then if fCurrRange.notInExclusiveRange() then
if readDelim(reader, fTokStop, '//') then if readDelim(reader, fTokStop, '//') then
begin begin
fTokKind := tkCommt; fTokKind := tkCommt;
@ -493,7 +500,7 @@ begin
end else readerReset; end else readerReset;
// block comments 1 // block comments 1
if (fCurrRange.rangeKinds = []) or (fCurrRange.rangeKinds = [rkAsm]) then if fCurrRange.notInExclusiveRange() then
if readDelim(reader, fTokStop, '/*') then if readDelim(reader, fTokStop, '/*') then
begin begin
fTokKind := tkCommt; fTokKind := tkCommt;
@ -535,7 +542,7 @@ begin
end; end;
// block comments 2 // block comments 2
if (fCurrRange.rangeKinds = []) or (fCurrRange.rangeKinds = [rkAsm]) then if fCurrRange.notInExclusiveRange() then
if readDelim(reader, fTokStop, '/+') then if readDelim(reader, fTokStop, '/+') then
begin begin
fTokKind := tkCommt; fTokKind := tkCommt;
@ -618,7 +625,7 @@ begin
end; end;
// double quoted strings | raw double quoted strings // double quoted strings | raw double quoted strings
if (fCurrRange.rangeKinds = []) and readDelim(reader, fTokStop, stringPrefixes) then if (fCurrRange.notInExclusiveRange()) and readDelim(reader, fTokStop, stringPrefixes) then
begin begin
if readerPrev^ in ['r','x'] then if readerPrev^ in ['r','x'] then
begin begin
@ -691,7 +698,7 @@ begin
end; end;
// backticks strings // backticks strings
if (fCurrRange.rangeKinds = []) and readDelim(reader, fTokStop, '`') then if fCurrRange.notInExclusiveRange() and readDelim(reader, fTokStop, '`') then
begin begin
fTokKind := tkStrng; fTokKind := tkStrng;
if readUntil(reader, fTokStop, '`') then if readUntil(reader, fTokStop, '`') then
@ -727,7 +734,7 @@ begin
end else readerReset; end else readerReset;
// q"( )" strings // q"( )" strings
if (fCurrRange.rangeKinds = []) and readDelim(reader, fTokStop, 'q"(') then if fCurrRange.notInExclusiveRange() and readDelim(reader, fTokStop, 'q"(') then
begin begin
fTokKind := tkStrng; fTokKind := tkStrng;
fCurrRange.nestedQParensStrings += 1; fCurrRange.nestedQParensStrings += 1;
@ -762,7 +769,7 @@ begin
end; end;
// q"[ ]" strings // q"[ ]" strings
if (fCurrRange.rangeKinds = []) and readDelim(reader, fTokStop, 'q"[') then if fCurrRange.notInExclusiveRange() and readDelim(reader, fTokStop, 'q"[') then
begin begin
fTokKind := tkStrng; fTokKind := tkStrng;
fCurrRange.nestedQSquareStrings += 1; fCurrRange.nestedQSquareStrings += 1;
@ -797,7 +804,7 @@ begin
end; end;
// q"< >" strings // q"< >" strings
if (fCurrRange.rangeKinds = []) and readDelim(reader, fTokStop, 'q"<') then if fCurrRange.notInExclusiveRange() and readDelim(reader, fTokStop, 'q"<') then
begin begin
fTokKind := tkStrng; fTokKind := tkStrng;
fCurrRange.nestedQGeStrings += 1; fCurrRange.nestedQGeStrings += 1;
@ -832,7 +839,7 @@ begin
end; end;
// q"{ }" strings // q"{ }" strings
if (fCurrRange.rangeKinds = []) and readDelim(reader, fTokStop, 'q"{') then if fCurrRange.notInExclusiveRange() and readDelim(reader, fTokStop, 'q"{') then
begin begin
fTokKind := tkStrng; fTokKind := tkStrng;
fCurrRange.nestedQCurlyStrings += 1; fCurrRange.nestedQCurlyStrings += 1;
@ -867,7 +874,7 @@ begin
end; end;
// char literals // char literals
if (fCurrRange.rangeKinds = []) and readDelim(reader, fTokStop, #39) then if fCurrRange.notInExclusiveRange() and readDelim(reader, fTokStop, #39) then
begin begin
fTokKind := tkStrng; fTokKind := tkStrng;
while true do while true do
@ -1006,6 +1013,23 @@ begin
if ((reader+1)^ in stringPostfixes) and not isIdentifier((reader+2)^) then if ((reader+1)^ in stringPostfixes) and not isIdentifier((reader+2)^) then
readerNext; readerNext;
end; end;
'(':
begin
if rkAttrib in fCurrRange.rangeKinds then
fCurrRange.attribParenCount += 1;
end;
')':
begin
if rkAttrib in fCurrRange.rangeKinds then
begin
fCurrRange.attribParenCount -= 1;
if fCurrRange.attribParenCount = 0 then
begin
fCurrRange.rangeKinds -= [rkAttrib];
fTokKind := tkAttri;
end;
end;
end;
end; end;
readerNext; readerNext;
exit; exit;
@ -1086,8 +1110,16 @@ begin
readerNext; readerNext;
end; end;
exit; exit;
end else end
readerPrev; else if (reader^ = '(') and (not (rkAttrib in fCurrRange.rangeKinds)) then
begin
fCurrRange.rangeKinds += [rkAttrib];
fTokKind:=tkAttri;
fCurrRange.attribParenCount := 1;
readerNext;
exit;
end
else readerPrev();
end; end;
// Keywords & identifiers // Keywords & identifiers