Recent

Author Topic: FCL-PasSrc question  (Read 5870 times)

v.denis

  • Guest
FCL-PasSrc question
« on: May 04, 2013, 01:18:25 pm »
I'm adapting FCL-PasSrc to be used from my Delphi code.

Such code is not parsed, cmdline = "-Sd 1.pas" (i.e. delphi mode)
Code: [Select]
type
  TMyType<T1, T2, T3> = class
    FVal1: T1;
  end;
 
begin
end.

I can see Delphi mode parsing of generics in pparser.TPasParser.ParseDeclarations does not hande this case.

But in Code Explorer window in Lazarus I can see it's parsed.

Does it use some different parser there?

And which parser I'd better to stick with? (i.e. which is more advanced?)
« Last Edit: May 04, 2013, 01:21:30 pm by v.denis »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: FCL-PasSrc question
« Reply #1 on: May 04, 2013, 01:38:43 pm »
Quote
Does it use some different parser there?
No, the compiler has its own, the IDE has its own, FCL-PasSrc is another one (fpdoc uses it though). Indeed, as confirmed with fpdoc as well, FCL-PasSrc is not yet extended to handle the current generics syntax.

v.denis

  • Guest
Re: FCL-PasSrc question
« Reply #2 on: May 04, 2013, 01:55:02 pm »
Thanks.

IDE uses PascalParaserTool unit, I guess?

Anyway FCL-PasSrc seems to me much easier to adapt.
« Last Edit: May 04, 2013, 02:12:39 pm by v.denis »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: FCL-PasSrc question
« Reply #3 on: May 04, 2013, 03:23:05 pm »
Quote
IDE uses PascalParaserTool unit, I guess?
I guess so, more precisely: IDE->CodeTools->PascalParserTool
Quote
Anyway FCL-PasSrc seems to me much easier to adapt.
Indeed, since it's more a general parser. Codetools parser is a bit permissive, allowing some errors to happen (this serves as a foundation for IDE features). The compiler's parser is interleaved with semantic checks and perhaps optimization.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4715
  • I like bugs.
Re: FCL-PasSrc question
« Reply #4 on: May 04, 2013, 03:55:20 pm »
Codetools parser is a bit permissive, allowing some errors to happen (this serves as a foundation for IDE features).

Yes, CodeTools stores to its parse-tree only definitions of types, functions and variables, but not actual source code. In IDE the source is parsed as needed while it is edited. Code browsing and completion works better than its Delphi counterpart.
So, if you are only interested in definitions, you can also use CodeTools. Otherwise I recommend FCL-PasSrc.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

v.denis

  • Guest
Re: FCL-PasSrc question
« Reply #5 on: May 04, 2013, 04:13:53 pm »
I agree, code browsing and completion is much better in Lazarus.

I'll stop on FCL-PasSrc, thanks for saving my time, guys.

One more thing,

there are AnsiString and String usages, like this

Code: [Select]
  TPrimitiveExpr = class(TPasExpr)
    Value     : AnsiString;
    constructor Create(AParent : TPasElement; AKind: TPasExprKind; const AValue : AnsiString); overload;
    function GetDeclaration(full : Boolean) : String; override;
  end;

I suppose AnsiStrings can be replaced with String (or at least aliased to TFPCString/TFPCAnsiString).
« Last Edit: May 04, 2013, 04:24:07 pm by v.denis »

v.denis

  • Guest
Re: FCL-PasSrc question
« Reply #6 on: May 06, 2013, 11:56:51 am »
Attached adapted version for latest Delphi. Maybe it will be useful for someone.

Seems parse fine D7-like sources. I modified scanner to parse &-started identifiers.
« Last Edit: May 06, 2013, 11:59:49 am by v.denis »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: FCL-PasSrc question
« Reply #7 on: May 06, 2013, 04:17:11 pm »
Quote
Attached adapted version for latest Delphi. Maybe it will be useful for someone.

Seems parse fine D7-like sources. I modified scanner to parse &-started identifiers.
Create a patch and contribute through the bugtracker instead (well, if you want the code to be incorporated into fpc)

 

TinyPortal © 2005-2018