Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > SynUniHighlighter and SynEdit (English Language) > strange error when using UniHighlighter


Автор: Vit 27.10.2006, 21:25
Hi

I wanted to provide some feedback for UniHighlighter but got an error on 
the feedback page.
So I do it now by email.

I did have a strange error when using UniHighlighter. The last token on 
a line would be printed twice.
I tracked the problem down and found that the there was an error in the 
Next function.
When end of line is detected, the current token position is not 
forwarded to the end of the previous token.

I solved this by adding the following line:
    fTokenPos := Run;

At line 331 in SynUniHighlighter.pas, just before the exit upon EOL.

Anyway thanks for this fine component, it did solve the problem I had 
with the regular highlighter which made it impossible
to handle both a // and a /* */ comment (because both start with a /).

Regards

Frans Bouwmans

Автор: DavidCl0nel 30.10.2006, 15:59
>>the problem I had 
with the regular highlighter which made it impossible
to handle both a // and a /* */ comment (because both start with a /).


Yes, a little bit. The SynGen-Output didnt work, but you can tweak it:

Код
  //                        /* Comment */  , // Comment         , #define some   , "text"
  TRangeState = (rsUnKnown, rsCStyleComment, rsCStyleLineComment, rsCPreprocessor, rsString);


....


procedure TSynMySyn.CStyleCommentOpenProc;
begin
  Inc(Run);
  if (fLine[Run] = '*') then
  begin
    fRange := rsCStyleComment;
    CStyleCommentMultiLineProc;
  end
  else if (fLine[Run] = '/') then
  begin
    fRange := rsCStyleLineComment;
    CStyleCommentLineProc;
  end
  else
    fTokenID := tkIdentifier;
end;

procedure TSynMySyn.CStyleCommentLineProc;
begin
  case fLine[Run] of
     #0: NullProc;
    #10: LFProc;
    #13: CRProc;
  else
    begin
      fTokenID := tkComment;
      repeat 
        Inc(Run);
      until fLine[Run] in [#0, #10, #13];
      fRange := rsUnKnown;
    end; //else
  end; //case
end;

procedure TSynMySyn.CStyleCommentMultiLineProc;
var
  iNestedComment: Integer;
begin
  iNestedComment := 0;
  case fLine[Run] of
     #0: NullProc;
    #10: LFProc;
    #13: CRProc;
    else begin
      fTokenID := tkComment;
      repeat
        if (fLine[Run] = '/') and (fLine[Run + 1] = '*') then begin
          Inc(iNestedComment);
          Inc(Run, 2);
        end;
        if (fLine[Run] = '*') and (fLine[Run + 1] = '/') and not (fLine[Run - 1] = '/') {ignore /*/} then begin
          Inc(Run, 2);
          if (iNestedComment = 0) then begin
            fRange := rsUnKnown;
            Exit;
          end else begin
            Dec(iNestedComment);
          end;
        end;
        if not (fLine[Run] in [#0, #10, #13]) then Inc(Run);
      until fLine[Run] in [#0, #10, #13];
    end; //else
  end; //case
end;




It isnt very clean to use the same function twice, but it works - also for nested comments. I use it such way in my highlighter, I don't use the unihighlighter, because I don't need this functionality.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)