handle HEREDOC strings base on common delimiters `()` `<>` `[]`

This commit is contained in:
Basile Burg 2020-04-23 16:08:52 +02:00
parent b5f04aa324
commit d992e7554e
3 changed files with 156 additions and 7 deletions

View File

@ -2,6 +2,7 @@
## Enhancements ## Enhancements
- Dlang highlighter: added suport for HEREDOC strings of type `q"()"` `q"[]"` and `q"<>"`. "free" HEREDOC strings wont be handled as they might be removed as per DIP 1026.
- TODO list: a new option, _disableIfMoreFilesThan_, allows to disable auto refreshing of the list could be slow when the current project is huge. - TODO list: a new option, _disableIfMoreFilesThan_, allows to disable auto refreshing of the list could be slow when the current project is huge.
## Bugs fixed ## Bugs fixed

View File

@ -15,7 +15,8 @@ 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,
rkStringQParen, rkStringQSquare, rkStringQGe, rStringQCurly);
TRangeKinds = set of TRangeKind; TRangeKinds = set of TRangeKind;
@ -26,12 +27,16 @@ type
// internal class used to keep trace of the useful informations of the previous line // internal class used to keep trace of the useful informations of the previous line
TSynD2SynRange = class(TSynCustomHighlighterRange) TSynD2SynRange = class(TSynCustomHighlighterRange)
private private
namedRegionCount: Integer; namedRegionCount : Integer;
nestedCommentsCount: Integer; nestedCommentsCount : Integer;
rangeKinds: TRangeKinds; nestedQParensStrings: Integer;
nestedQSquareStrings: Integer;
nestedQGeStrings : Integer;
nestedQCurlyStrings : Integer;
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 '\'
rString: boolean; rString : boolean;
public public
procedure Assign(source: TSynCustomHighlighterRange); override; procedure Assign(source: TSynCustomHighlighterRange); override;
function Compare(range: TSynCustomHighlighterRange): integer; override; function Compare(range: TSynCustomHighlighterRange): integer; override;
@ -130,6 +135,9 @@ begin
rng := TSynD2SynRange(source); rng := TSynD2SynRange(source);
rangeKinds := rng.rangeKinds; rangeKinds := rng.rangeKinds;
namedRegionCount := rng.namedRegionCount; namedRegionCount := rng.namedRegionCount;
nestedQGeStrings:= rng.nestedQGeStrings;
nestedQParensStrings := rng.nestedQParensStrings;
nestedQSquareStrings := rng.nestedQSquareStrings;
end; end;
end; end;
@ -612,7 +620,7 @@ begin
// 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.rangeKinds = []) and readDelim(reader, fTokStop, stringPrefixes) then
begin begin
if readerPrev^ in ['r','x','q'] then if readerPrev^ in ['r','x'] then
begin begin
fCurrRange.rString := reader^ = 'r'; fCurrRange.rString := reader^ = 'r';
if not (readerNext^ = '"') then if not (readerNext^ = '"') then
@ -718,6 +726,146 @@ begin
exit; exit;
end else readerReset; end else readerReset;
// q"( )" strings
if (fCurrRange.rangeKinds = []) and readDelim(reader, fTokStop, 'q"(') then
begin
fTokKind := tkStrng;
fCurrRange.nestedQParensStrings += 1;
if readUntil(reader, fTokStop, ')"') then
begin
fCurrRange.nestedQParensStrings -= 1;
if fCurrRange.nestedQParensStrings = 0 then
begin
readDelim(reader, fTokStop, stringPostfixes);
exit;
end;
end;
fCurrRange.rangeKinds += [rkStringQParen];
readLine(reader, fTokStop);
exit;
end else readerReset;
if rkStringQParen in fCurrRange.rangeKinds then
begin
fTokKind := tkStrng;
if readUntil(reader, fTokStop, ')"') then
begin
fCurrRange.nestedQParensStrings -= 1;
if fCurrRange.nestedQParensStrings = 0 then
begin
readDelim(reader, fTokStop, stringPostfixes);
fCurrRange.rangeKinds -= [rkStringQParen];
exit;
end;
end;
readLine(reader, fTokStop);
exit;
end;
// q"[ ]" strings
if (fCurrRange.rangeKinds = []) and readDelim(reader, fTokStop, 'q"[') then
begin
fTokKind := tkStrng;
fCurrRange.nestedQSquareStrings += 1;
if readUntil(reader, fTokStop, ']"') then
begin
fCurrRange.nestedQSquareStrings -= 1;
if fCurrRange.nestedQSquareStrings = 0 then
begin
readDelim(reader, fTokStop, stringPostfixes);
exit;
end;
end;
fCurrRange.rangeKinds += [rkStringQSquare];
readLine(reader, fTokStop);
exit;
end else readerReset;
if rkStringQSquare in fCurrRange.rangeKinds then
begin
fTokKind := tkStrng;
if readUntil(reader, fTokStop, ']"') then
begin
fCurrRange.nestedQSquareStrings -= 1;
if fCurrRange.nestedQSquareStrings = 0 then
begin
readDelim(reader, fTokStop, stringPostfixes);
fCurrRange.rangeKinds -= [rkStringQSquare];
exit;
end;
end;
readLine(reader, fTokStop);
exit;
end;
// q"< >" strings
if (fCurrRange.rangeKinds = []) and readDelim(reader, fTokStop, 'q"<') then
begin
fTokKind := tkStrng;
fCurrRange.nestedQGeStrings += 1;
if readUntil(reader, fTokStop, '>"') then
begin
fCurrRange.nestedQGeStrings -= 1;
if fCurrRange.nestedQGeStrings = 0 then
begin
readDelim(reader, fTokStop, stringPostfixes);
exit;
end;
end;
fCurrRange.rangeKinds += [rkStringQGe];
readLine(reader, fTokStop);
exit;
end else readerReset;
if rkStringQGe in fCurrRange.rangeKinds then
begin
fTokKind := tkStrng;
if readUntil(reader, fTokStop, ')"') then
begin
fCurrRange.nestedQGeStrings -= 1;
if fCurrRange.nestedQGeStrings = 0 then
begin
readDelim(reader, fTokStop, stringPostfixes);
fCurrRange.rangeKinds -= [rkStringQGe];
exit;
end;
end;
readLine(reader, fTokStop);
exit;
end;
// q"{ }" strings
if (fCurrRange.rangeKinds = []) and readDelim(reader, fTokStop, 'q"{') then
begin
fTokKind := tkStrng;
fCurrRange.nestedQCurlyStrings += 1;
if readUntil(reader, fTokStop, '}"') then
begin
fCurrRange.nestedQCurlyStrings -= 1;
if fCurrRange.nestedQCurlyStrings = 0 then
begin
readDelim(reader, fTokStop, stringPostfixes);
exit;
end;
end;
fCurrRange.rangeKinds += [rStringQCurly];
readLine(reader, fTokStop);
exit;
end else readerReset;
if rStringQCurly in fCurrRange.rangeKinds then
begin
fTokKind := tkStrng;
if readUntil(reader, fTokStop, '}"') then
begin
fCurrRange.nestedQCurlyStrings -= 1;
if fCurrRange.nestedQCurlyStrings = 0 then
begin
readDelim(reader, fTokStop, stringPostfixes);
fCurrRange.rangeKinds -= [rStringQCurly];
exit;
end;
end;
readLine(reader, fTokStop);
exit;
end;
// char literals // char literals
if (fCurrRange.rangeKinds = []) and readDelim(reader, fTokStop, #39) then if (fCurrRange.rangeKinds = []) and readDelim(reader, fTokStop, #39) then
begin begin

View File

@ -12,7 +12,7 @@ type
const const
stringPostfixes: TCharSet = ['c', 'w', 'd']; stringPostfixes: TCharSet = ['c', 'w', 'd'];
stringPrefixes: TCharSet = ['r', 'x', 'q', '"']; stringPrefixes: TCharSet = ['r', 'x', '"'];
stringStopChecks: TCharSet = ['\', '"']; stringStopChecks: TCharSet = ['\', '"'];
charStopChecks: TCharSet = ['\', #39]; charStopChecks: TCharSet = ['\', #39];
symbChars: TCharSet = [';', '{', '}', '(', ')', '[', ']', ',', '.', ':', '?', '$', '"', #39]; symbChars: TCharSet = [';', '{', '}', '(', ')', '[', ']', ',', '.', ':', '?', '$', '"', #39];