Recent

Author Topic: SynHighlighterPas: Bug with generics  (Read 5346 times)

Pascal

  • Hero Member
  • *****
  • Posts: 831
SynHighlighterPas: Bug with generics
« on: June 12, 2017, 01:21:49 pm »
SynHighlihterPas has some problems with generics (see screenshot of Generics.Collections).

I had a look at the highlighter and was wondering why beginning a FoldBlock after rsAfterEqualOrColon
instead of rsAfterEqual?

Code: Pascal  [Select]
  1. function TSynPasSyn.Func54: TtkTokenKind;
  2. begin
  3.   if KeyComp('Class') then begin
  4.     Result := tkKey;
  5.     if (rsAfterEqualOrColon in fRange) and (PasCodeFoldRange.BracketNestLevel = 0)
  6.     then begin
  7.       fRange := fRange + [rsAtClass] - [rsVarTypeInSpecification];
  8.       StartPascalCodeFoldBlock(cfbtClass);
  9.     end;
  10.   end
  11.   else
  12.     Result := tkIdentifier;
  13. end;
  14.  

I actualy don't know of a case where to begin a new foldblock for keyword class after a colon.
So maybe we just can change rsAfterEqualOrColon to rsAfterEqual?

Pascal
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5573
    • wiki
Re: SynHighlighterPas: Bug with generics
« Reply #1 on: June 12, 2017, 02:53:35 pm »
I had a look at the highlighter and was wondering why beginning a FoldBlock after rsAfterEqualOrColon
instead of rsAfterEqual?

Probably that code was written before rsAfterEqual was introduced.

But yes it, I think it can be changed.

Please check if the test case still passes. (and add a new test for this ;)  )

Pascal

  • Hero Member
  • *****
  • Posts: 831
Re: SynHighlighterPas: Bug with generics
« Reply #2 on: June 12, 2017, 04:35:02 pm »
Tests are okay so far. New test is in the works  ;)
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Pascal

  • Hero Member
  • *****
  • Posts: 831
Re: SynHighlighterPas: Bug with generics
« Reply #3 on: June 12, 2017, 08:00:16 pm »
Martin,

could you have a look at the patch. Would this be a suitable test?
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5573
    • wiki
Re: SynHighlighterPas: Bug with generics
« Reply #4 on: June 12, 2017, 10:19:43 pm »
looks ok.

Code: Pascal  [Select]
  1.  CheckNode( 3, [], 0,   0,   17, 22,   3, 4,   3, 4,
  2.                                   cfbtClass, cfbtClass,  FOLDGROUP_PASCAL,
  3.                                   [sfaOpen, sfaFold, sfaFoldFold, sfaMultiLine, sfaMarkup, sfaOpenFold]);
  4.  
Because the above checks the x pos, so it checks that the fold is triggered by the correct of the 2 "class" keywords on that line.

Applied the patch.

Pascal

  • Hero Member
  • *****
  • Posts: 831
Re: SynHighlighterPas: Bug with generics
« Reply #5 on: June 14, 2017, 01:16:11 pm »
I've found an other one  :D
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Pascal

  • Hero Member
  • *****
  • Posts: 831
Re: SynHighlighterPas: Bug with generics
« Reply #6 on: June 14, 2017, 01:43:55 pm »
Could this patch be a solution? Tests still run fine.
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5573
    • wiki
Re: SynHighlighterPas: Bug with generics
« Reply #7 on: June 14, 2017, 03:25:48 pm »
Yes seems ok.

Pascal

  • Hero Member
  • *****
  • Posts: 831
Re: SynHighlighterPas: Bug with generics
« Reply #8 on: June 14, 2017, 03:26:55 pm »
Okay, i'll also update the test.
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Pascal

  • Hero Member
  • *****
  • Posts: 831
Re: SynHighlighterPas: Bug with generics
« Reply #9 on: June 14, 2017, 03:44:10 pm »
Okay, here is the patch (with changed test).
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Pascal

  • Hero Member
  • *****
  • Posts: 831
Re: SynHighlighterPas: Bug with generics
« Reply #10 on: June 15, 2017, 06:05:59 am »
... and an other one:

Patch includes last patch!
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5573
    • wiki
Re: SynHighlighterPas: Bug with generics
« Reply #11 on: June 15, 2017, 06:23:40 am »
The 2 latter ones are actually a result of the first patch.

rsAfterEqualOrColon is cleared in function Next.

rsAfterEqual is not cleared.


Same breakage will be for
Code: Pascal  [Select]
  1. foo = object
  2.  class function...

I'll have another look if rsAfterEqual  should be cleared in Next too.

IIRC rsAfterEqual  was introduced to handle the ^ symbol.
Either pointer, or char #3 = ^C

Pascal

  • Hero Member
  • *****
  • Posts: 831
Re: SynHighlighterPas: Bug with generics
« Reply #12 on: June 16, 2017, 06:32:31 am »
I've tested to clear rsAfterEqual in Next and it seems to work (including new tests for the last two issues).

laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5573
    • wiki
Re: SynHighlighterPas: Bug with generics
« Reply #13 on: June 17, 2017, 05:50:08 pm »
I fixed it in class/object/record.

I added more tests, the fix in "next" would have broken
var a:string=^a^b;

Pascal

  • Hero Member
  • *****
  • Posts: 831
Re: SynHighlighterPas: Bug with generics
« Reply #14 on: June 17, 2017, 11:09:25 pm »
Oklay, thanks.
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)