[Lazarus] Regex and Syntax Highlighting

Graeme Geldenhuys graemeg.lists at gmail.com
Wed May 26 12:59:39 CEST 2010


On 26 May 2010 11:13, Marco van de Voort wrote:
> Just that
>
> codeblock 1
>
> {  xxx
> { yyy }
>  zzz }
>
> codeblock 2
>
> is coloured properly  And xxx yyy and zzz can contain (commented)code too of
> course

....and that will produce a nice compiler warning (and for good
reason, and why I, and none of my team will ever use that format).
It's basic Pascal 101! :-)

    frm_learnerlist.pas(653,3) Warning: Comment level 2 found


Here is the example I used to produce the above compiler warning:

{
procedure TLearnerListForm.PerformTabQuery;
const
 eof = ^Z;
var
  lData: TViewFilter;
begin
  { load data based on view }
  lData := TViewFilter.Create(sgb.View);
  try
    lData.TabLetters := pcName1.ActivePage.Text;
    gTIOPFManager.VisitorManager.Execute('LoadLearnerViewData', lData);
    sgb.Data := lData.Data;
  finally
    lData.Free;
  end;
end;
}


I tested: jEdit, gEdit, MSEide, Lazarus IDE and mcedit. Only Lazarus
IDE syntax highlighted the above code as one single block of commented
code.  But considering that that code now gives a compiler waring
doesn't say much.

Changing the above code to the more correct commenting style when
nested comments apply; suddenly *all* editors passed with flying
colors, and the FPC compiler gave no warnings. :-)

(*
procedure TLearnerListForm.PerformTabQuery;
const
 eof = ^Z;
var
  lData: TViewFilter;
begin
  { load data based on view }
  lData := TViewFilter.Create(sgb.View);
  try
    lData.TabLetters := pcName1.ActivePage.Text;
    gTIOPFManager.VisitorManager.Execute('LoadLearnerViewData', lData);
    sgb.Data := lData.Data;
  finally
    lData.Free;
  end;
end;
*)

Removing the outer comment block, again all editors correctly applied
syntax highlighting. The one exception being gEdit which highlighted
the identifier eof incorrectly, but I am pretty sure a minor tweak to
the pascal.lang file will fix that.

NOTE:
I never said all editors using regular expressions are 100% - then
neither is Lazarus IDE's syntax highlighting. Only thing is, normally
the regex way is easier to fix without the need for improving the
parser, highlighting component and recompiling the whole IDE.

Problems in Lazarus IDE:
  * deprecated modifier is incorrectly highlighted, no matter where you use it.
  * A method named 'write(...)' will be incorrectly highlighted.
Lazarus thinks identifier write is
    the same as when it is used for a property setter method.
      property Name: string read FName write FName;
        vs
      procedure Write(...);

... I remember seeing a few more in Lazarus, but can't remember them now.


-- 
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/




More information about the Lazarus mailing list