[Lazarus] Using FPC parser/tokenizer for code formatting

Doug Chamberlin dougchamberlin at earthlink.net
Mon May 31 04:36:13 CEST 2010


Adem-

I have great interest in a parser-based code formatting tool. However, I 
have doubt that using the compiler's parser is the best solution. So, 
I'd like to discuss some of the issues surrounding this decision.

I'd like to get your ideas on the following problem. There are basically 
two philosophies of code reformatting. These I'll call "reorganization" 
and "rebuild".

Using the reorganization approach, the source file is largely retained 
intact with some lines modified to enforce some formatting rules. The 
idea is to keep everything as it is except those things that have 
specifically been requested to be examined and modified. Minimal change 
is called for. Parts of the source file that the parser does not 
understand are left intact.

Using the rebuild approach, the source file is examined by the 
reformatter, digested for content, and completely rewritten by the 
reformatter according to its rules. Everything is re-written according 
to the formatting rules so nothing can be included that the reformatter 
does not understand. For example, any manually formatted details are 
lost. The reformatter must know about and understand how to retain all 
valuable content. The developer cannot add anything important that the 
reformatter does not know how to handle.

Which approach do you think should be used?

I prefer the reorganization approach because I view source code as 
carefully sculpted art. Others treat source code as essentially a 
machine-generated intermediate representation of some abstract concepts 
that can be transformed over and over again as needed. These people 
would be more comfortable with the rebuild approach.

I'm just curious how you look at the problem because it has a big impact 
on what parser is used. Of course, I'm also interested in everyone 
else's viewpoint as well.

-- 

Doug C.
-----
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?





More information about the Lazarus mailing list