[Lazarus] Code explorer implementation

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] Code explorer implementation

Free Pascal - Lazarus mailing list
I want to make a tool that can analyze source files for functions/classes etc... that can be used for auto complete in 3rd party editors. I see Lazarus already has such a “Code Explorer” feature and I wonder how it gets this information and if I could scavenge it from the project. Does anyone have any ideas on this, where to look in the Lazarus sources, etc...? I think it may be possible to use .ppu files also but I’m not sure if the information is as complete as what Lazarus has.

Regards,
        Ryan Joseph

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Code explorer implementation

Free Pascal - Lazarus mailing list


On Fri, 13 Sep 2019, Ryan Joseph via lazarus wrote:

> I want to make a tool that can analyze source files for functions/classes
> etc...  that can be used for auto complete in 3rd party editors.  I see
> Lazarus already has such a “Code Explorer” feature and I wonder how it
> gets this information and if I could scavenge it from the project.  Does
> anyone have any ideas on this, where to look in the Lazarus sources,
> etc...?  I think it may be possible to use .ppu files also but I’m not
> sure if the information is as complete as what Lazarus has.

No the ppu will not be as complete.

You can also try the fcl-passrc sources. It is standalone by design,
and can give you all info that lazarus gives you.

It's used for the pas2js compiler, so you can be sure the info is very complete.

Michael.
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Code explorer implementation

Free Pascal - Lazarus mailing list


> On Sep 13, 2019, at 12:19 PM, Michael Van Canneyt via lazarus <[hidden email]> wrote:
>
> You can also try the fcl-passrc sources. It is standalone by design, and can give you all info that lazarus gives you.

Thanks Michael this looks like exactly what I want. How well do they keep up with new syntax etc…? I was thinking of making my own parser before but I didn’t want to keep up with changing syntax and things breaking.

Regards,
        Ryan Joseph

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Code explorer implementation

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
A follow up. I built the parsepp.pp program and used it to parse a file. Everything seems to work except it tries to follow include macros (that would be nice to turn off since it requires compiler flags to work properly) and += operators are causing errors. Why doesn’t it know c style operators?



EParserError: Identifier expected at token "=" in file /Users/ryanjoseph/Desktop/parser_test.pas at line 5 column 6


program test;

begin
  i += 1;
end.

Regards,
        Ryan Joseph

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Code explorer implementation

Free Pascal - Lazarus mailing list


On Sat, 14 Sep 2019, Ryan Joseph via lazarus wrote:

> A follow up.  I built the parsepp.pp program and used it to parse a file.
> Everything seems to work except it tries to follow include macros (that
> would be nice to turn off since it requires compiler flags to work
> properly) and += operators are causing errors.  Why doesn’t it know c
> style operators?

It mimics FPC in behaviour.

By default, FPC also does not allow C style operators.

You need to provide the -Sc command-line flag to the parser or set the appropriate flag
manually on the parser object.

Normally this should do it:

parsepp -Sc yourfile.

the parser understands all directives and compiler flags that FPC itself
understands. So you can just do
parsepp -Sc yourfile. -Fi../your/include/dir


Michael.
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Code explorer implementation

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list


On Sat, 14 Sep 2019, Ryan Joseph via lazarus wrote:

>
>
>> On Sep 13, 2019, at 12:19 PM, Michael Van Canneyt via lazarus <[hidden email]> wrote:
>>
>> You can also try the fcl-passrc sources. It is standalone by design, and can give you all info that lazarus gives you.
>
> Thanks Michael this looks like exactly what I want. How well do they keep up with new syntax etc…?

It is fully equivalent to FPC, it currently allows even more: anonymous
functions are supported.

Michael.
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Code explorer implementation

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list


> On Sep 14, 2019, at 2:07 PM, Michael Van Canneyt via lazarus <[hidden email]> wrote:
>
> By default, FPC also does not allow C style operators.
>
> You need to provide the -Sc command-line flag to the parser or set the appropriate flag manually on the parser object.

I tried using -Mobjfpc because I know c style operators are a mode switch but that didn’t work. I guess modes are not supported in the parser and we need to use all the various -S flags?

Regards,
        Ryan Joseph

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Code explorer implementation

Free Pascal - Lazarus mailing list


On Sat, 14 Sep 2019, Ryan Joseph via lazarus wrote:

>
>
>> On Sep 14, 2019, at 2:07 PM, Michael Van Canneyt via lazarus <[hidden email]> wrote:
>>
>> By default, FPC also does not allow C style operators.
>>
>> You need to provide the -Sc command-line flag to the parser or set the appropriate flag manually on the parser object.
>
> I tried using -Mobjfpc because I know c style operators are a mode switch but that didn’t work.
> I guess modes are not supported in the parser and we need to use all the various -S flags?
Modes & modeswitches are supported, but -Mobjfpc does not switch on C style operators.

You need -Sc, just as in FPC, the -M command-line switch is not supported by
the ParseSource() routine, it has only a limited set of options implemented.

if you need/want more control, you can just create the scanner and parser, and
set any flag you want: the ParseSource is a simple routine that will set up
the parser/scanner with some very basic options.

Michael.
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Code explorer implementation

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
Ryan Joseph via lazarus <[hidden email]> schrieb am Sa., 14. Sep. 2019, 20:18:


> On Sep 14, 2019, at 2:07 PM, Michael Van Canneyt via lazarus <[hidden email]> wrote:
>
> By default, FPC also does not allow C style operators.
>
> You need to provide the -Sc command-line flag to the parser or set the appropriate flag manually on the parser object.

I tried using -Mobjfpc because I know c style operators are a mode switch but that didn’t work. I guess modes are not supported in the parser and we need to use all the various -S flags?

As I already wrote some time ago C-style operators are *not* enabled by default in any of the modes. Also they aren't a modeswitch either. They are simply switched on inside the default fpc.cfg using the -Sc option. Thus, as Michael wrote, you need to pass that parameter as well or explicitly set the corresponding flag of the parser object. 

Regards, 
Sven 

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus