mirror of https://gitlab.com/basile.b/dexed.git
fix #142 and simplify slightly the highlighter
This commit is contained in:
parent
23b71d0f11
commit
09fa996fd7
|
@ -14,7 +14,7 @@ type
|
||||||
TTokenKind = (tkCommt, tkIdent, tkKeywd, tkStrng, tkBlank, tkSymbl, tkNumbr,
|
TTokenKind = (tkCommt, tkIdent, tkKeywd, tkStrng, tkBlank, tkSymbl, tkNumbr,
|
||||||
tkDDocs, tkSpecK, tkError, tkAsmbl, tkAttri, tkLost, tkTypes);
|
tkDDocs, tkSpecK, tkError, tkAsmbl, tkAttri, tkLost, tkTypes);
|
||||||
|
|
||||||
TRangeKind = (rkString1, rkString2, rkTokString, rkBlockCom1, rkBlockCom2,
|
TRangeKind = (rkString1, rkString2, rkBlockCom1, rkBlockCom2,
|
||||||
rkBlockDoc1, rkBlockDoc2, rkAsm);
|
rkBlockDoc1, rkBlockDoc2, rkAsm);
|
||||||
|
|
||||||
TRangeKinds = set of TRangeKind;
|
TRangeKinds = set of TRangeKind;
|
||||||
|
@ -28,7 +28,6 @@ type
|
||||||
private
|
private
|
||||||
namedRegionCount: Integer;
|
namedRegionCount: Integer;
|
||||||
nestedCommentsCount: Integer;
|
nestedCommentsCount: Integer;
|
||||||
tokenStringBracketsCount: 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 '\'
|
||||||
|
@ -130,8 +129,6 @@ begin
|
||||||
begin
|
begin
|
||||||
rng := TSynD2SynRange(source);
|
rng := TSynD2SynRange(source);
|
||||||
rangeKinds := rng.rangeKinds;
|
rangeKinds := rng.rangeKinds;
|
||||||
nestedCommentsCount := rng.nestedCommentsCount;
|
|
||||||
tokenStringBracketsCount := rng.tokenStringBracketsCount;
|
|
||||||
namedRegionCount := rng.namedRegionCount;
|
namedRegionCount := rng.namedRegionCount;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
@ -153,8 +150,6 @@ begin
|
||||||
if src_t.rString <> rString then exit(1);
|
if src_t.rString <> rString then exit(1);
|
||||||
if src_t.nestedCommentsCount <> nestedCommentsCount then
|
if src_t.nestedCommentsCount <> nestedCommentsCount then
|
||||||
exit(cmpRes[src_t.nestedCommentsCount > nestedCommentsCount]);
|
exit(cmpRes[src_t.nestedCommentsCount > nestedCommentsCount]);
|
||||||
if src_t.tokenStringBracketsCount <> tokenStringBracketsCount then
|
|
||||||
exit(cmpRes[src_t.tokenStringBracketsCount > tokenStringBracketsCount]);
|
|
||||||
if src_t.namedRegionCount <> namedRegionCount then
|
if src_t.namedRegionCount <> namedRegionCount then
|
||||||
exit(cmpRes[src_t.namedRegionCount > namedRegionCount]);
|
exit(cmpRes[src_t.namedRegionCount > namedRegionCount]);
|
||||||
end;
|
end;
|
||||||
|
@ -165,7 +160,6 @@ begin
|
||||||
inherited;
|
inherited;
|
||||||
nestedCommentsCount := 0;
|
nestedCommentsCount := 0;
|
||||||
namedRegionCount := 0;
|
namedRegionCount := 0;
|
||||||
tokenStringBracketsCount := 0;
|
|
||||||
rangeKinds := [];
|
rangeKinds := [];
|
||||||
rString := false;
|
rString := false;
|
||||||
end;
|
end;
|
||||||
|
@ -174,7 +168,6 @@ procedure TSynD2SynRange.copyFrom(source: TSynD2SynRange);
|
||||||
begin
|
begin
|
||||||
nestedCommentsCount := source.nestedCommentsCount;
|
nestedCommentsCount := source.nestedCommentsCount;
|
||||||
namedRegionCount := source.namedRegionCount;
|
namedRegionCount := source.namedRegionCount;
|
||||||
tokenStringBracketsCount := source.tokenStringBracketsCount;
|
|
||||||
rangeKinds := source.rangeKinds;
|
rangeKinds := source.rangeKinds;
|
||||||
rString := source.rString;
|
rString := source.rString;
|
||||||
end;
|
end;
|
||||||
|
@ -450,8 +443,7 @@ begin
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// line comments / region beg-end
|
// line comments / region beg-end
|
||||||
if (fCurrRange.rangeKinds = []) or (fCurrRange.rangeKinds = [rkTokString]) or
|
if (fCurrRange.rangeKinds = []) or (fCurrRange.rangeKinds = [rkAsm])
|
||||||
(fCurrRange.rangeKinds = [rkAsm])
|
|
||||||
then if readDelim(reader, fTokStop, '//') then
|
then if readDelim(reader, fTokStop, '//') then
|
||||||
begin
|
begin
|
||||||
fTokKind := tkCommt;
|
fTokKind := tkCommt;
|
||||||
|
@ -483,8 +475,8 @@ begin
|
||||||
end else readerReset;
|
end else readerReset;
|
||||||
|
|
||||||
// block comments 1
|
// block comments 1
|
||||||
if (fCurrRange.rangeKinds = []) or (fCurrRange.rangeKinds = [rkTokString]) or
|
if (fCurrRange.rangeKinds = []) or (fCurrRange.rangeKinds = [rkAsm]) then
|
||||||
(fCurrRange.rangeKinds = [rkAsm]) then if readDelim(reader, fTokStop, '/*') then
|
if readDelim(reader, fTokStop, '/*') then
|
||||||
begin
|
begin
|
||||||
fTokKind := tkCommt;
|
fTokKind := tkCommt;
|
||||||
if readDelim(reader, fTokStop, '*') then
|
if readDelim(reader, fTokStop, '*') then
|
||||||
|
@ -521,8 +513,8 @@ begin
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// block comments 2
|
// block comments 2
|
||||||
if (fCurrRange.rangeKinds = []) or (fCurrRange.rangeKinds = [rkTokString]) or
|
if (fCurrRange.rangeKinds = []) or (fCurrRange.rangeKinds = [rkAsm]) then
|
||||||
(fCurrRange.rangeKinds = [rkAsm]) then if readDelim(reader, fTokStop, '/+') then
|
if readDelim(reader, fTokStop, '/+') then
|
||||||
begin
|
begin
|
||||||
fTokKind := tkCommt;
|
fTokKind := tkCommt;
|
||||||
if readDelim(reader, fTokStop, '+') then
|
if readDelim(reader, fTokStop, '+') then
|
||||||
|
@ -602,8 +594,7 @@ begin
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// double quoted strings | raw double quoted strings
|
// double quoted strings | raw double quoted strings
|
||||||
if (fCurrRange.rangeKinds = []) or (fCurrRange.rangeKinds = [rkTokString])
|
if (fCurrRange.rangeKinds = []) and readDelim(reader, fTokStop, stringPrefixes) then
|
||||||
then if readDelim(reader, fTokStop, stringPrefixes) then
|
|
||||||
begin
|
begin
|
||||||
if readerPrev^ in ['r','x','q'] then
|
if readerPrev^ in ['r','x','q'] then
|
||||||
begin
|
begin
|
||||||
|
@ -672,8 +663,7 @@ begin
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// backticks strings
|
// backticks strings
|
||||||
if (fCurrRange.rangeKinds = []) or (fCurrRange.rangeKinds = [rkTokString]) then
|
if (fCurrRange.rangeKinds = []) and readDelim(reader, fTokStop, '`') then
|
||||||
if readDelim(reader, fTokStop, '`') then
|
|
||||||
begin
|
begin
|
||||||
fTokKind := tkStrng;
|
fTokKind := tkStrng;
|
||||||
if readUntil(reader, fTokStop, '`') then
|
if readUntil(reader, fTokStop, '`') then
|
||||||
|
@ -704,15 +694,12 @@ begin
|
||||||
if readDelim(reader, fTokStop, 'q{') then
|
if readDelim(reader, fTokStop, 'q{') then
|
||||||
begin
|
begin
|
||||||
fTokKind := tkSymbl;
|
fTokKind := tkSymbl;
|
||||||
inc(fCurrRange.tokenStringBracketsCount);
|
|
||||||
fCurrRange.rangeKinds += [rkTokString];
|
|
||||||
StartCodeFoldBlock(nil, fkBrackets in fFoldKinds);
|
StartCodeFoldBlock(nil, fkBrackets in fFoldKinds);
|
||||||
exit;
|
exit;
|
||||||
end else readerReset;
|
end else readerReset;
|
||||||
|
|
||||||
// char literals
|
// char literals
|
||||||
if (fCurrRange.rangeKinds = []) or (fCurrRange.rangeKinds = [rkTokString])
|
if (fCurrRange.rangeKinds = []) and readDelim(reader, fTokStop, #39) then
|
||||||
then if readDelim(reader, fTokStop, #39) then
|
|
||||||
begin
|
begin
|
||||||
fTokKind := tkStrng;
|
fTokKind := tkStrng;
|
||||||
while true do
|
while true do
|
||||||
|
@ -847,12 +834,8 @@ begin
|
||||||
EndCodeFoldBlock(fkBrackets in fFoldKinds);
|
EndCodeFoldBlock(fkBrackets in fFoldKinds);
|
||||||
if (reader^ = '}') and (rkAsm in fCurrRange.rangeKinds) then
|
if (reader^ = '}') and (rkAsm in fCurrRange.rangeKinds) then
|
||||||
fCurrRange.rangeKinds -= [rkAsm]; ;
|
fCurrRange.rangeKinds -= [rkAsm]; ;
|
||||||
if (rkTokString in fCurrRange.rangeKinds) then
|
if (reader+1)^ in stringPostfixes then
|
||||||
begin
|
readerNext;
|
||||||
Dec(fCurrRange.tokenStringBracketsCount);
|
|
||||||
if (fCurrRange.tokenStringBracketsCount = 0) then
|
|
||||||
fCurrRange.rangeKinds -= [rkTokString];
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
readerNext;
|
readerNext;
|
||||||
|
|
|
@ -815,6 +815,8 @@ begin
|
||||||
begin
|
begin
|
||||||
reader.saveBeginning;
|
reader.saveBeginning;
|
||||||
identifier += reader.head^;
|
identifier += reader.head^;
|
||||||
|
if (reader.head^ = '}') and ((reader.head + 1)^ in stringPostfixes) then
|
||||||
|
reader.Next;
|
||||||
reader.Next;
|
reader.Next;
|
||||||
addToken(ltkSymbol);
|
addToken(ltkSymbol);
|
||||||
if callBackDoStop then
|
if callBackDoStop then
|
||||||
|
|
Loading…
Reference in New Issue