[Lazarus] Using FPC parser/tokenizer for code formatting

Sven Barth pascaldragon at googlemail.com
Fri May 28 16:46:54 CEST 2010


Am 28.05.2010 16:38, schrieb Adem:
>
>>> But, I am hoping to modify the FPC parser/tokenizer so that instead
>>> of it deciding whether to stop, it should do a callback and let the
>>> caller decide whether it should stop.
>>>
>>> Is this likely to be unworthy of the effort?
>> No, but it is hard to do in a meaningful way.
> Could you (or someone else) point me to the source files of FPC
> parser/tokenizer please.
>

Most units that are related to parsing are inside "compiler" directory 
and prefixed with a "p", e.g. pdecl.pas and pdecsub.pas (but you still 
need to find the relations between those units yourself - I myself only 
find these "on demand" ^^)

> I can guess that it won't be easy; but if it can be done, I think it
> should be.
>
> It is the only way the code formatter can keep up with new features of FPC.
>

I don't think that it will be that easy. You might need to do so many 
changes that you can't simply copy new features from the compiler to 
your formatter.

You might be better of playing around and modifying the parser in 
fcl-passrc - at least that one was developed for simply parsing Pascal 
code. You might be able to extend it with better error recovery and 
fragment parsing. (Before you start yet another Pascal parser, because a 
"forked" FPC parser might become to different to be recognized as FPC's 
parser any more)

Regards,
Sven




More information about the Lazarus mailing list