[Lazarus] Using FPC parser/tokenizer for code formatting

Mattias Gaertner nc-gaertnma at netcologne.de
Fri May 28 15:57:09 CEST 2010


On Fri, 28 May 2010 15:26:30 +0200
Sven Barth <pascaldragon at googlemail.com> wrote:

> Hi!
> 
> Am 28.05.2010 14:12, schrieb Adem:
> > Given that I have some time to spare now, I would like to tackle using
> > FPC's own parser/tokenizer engine for a code formatter.
> >
> > Trouble is, I am not familiar enough with the internals of FPC source
> > tree; meaning I don't even know where to begin looking for the relevant
> > files in the FPC tree.
> >
> > Could someone point me in the right direction please.
> >
> > I'd also like to hear opinions whether I should spend time on this, or
> > even whether it is a good idea to use FPC's parser/tokenizer engine for
> > code formatter.
> >
> 
> I don't think that it would be a wise idea to use the compiler's 
> parser/tokenizer for this. It is too much trimed for its main purpose: 
> compiling.
> But you might try the parser in packages/fcl-passrc which is used inside 
> the fpdoc tool. It also has it's own (small) wiki page here: 
> http://wiki.freepascal.org/fcl-passrc
> As far as I understood it, it was extended to also parse implementation 
> sections (for documentation only interface sections are needed). It 
> still has some bugs (see BugTracker), but it seems to work rather well.

Yes, it can already parse all fcl sources.

Adem,
What I miss in all code formatters is formatting fragments. For example
when the codetools adds missing procedures or when a code template is
inserted or when some fragment is pasted from clipboard the IDE should
format this fragment with the user settings. For performance reasons
the formatter should not rescan the whole unit every time a fragment
is inserted.


Mattias




More information about the Lazarus mailing list