Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [photran] refactoring suggestion

Hi,

On 11/7/2010 5:11 PM, Michel DEVEL wrote:
> Le 07/11/2010 16:48, Daniel Harenberg a écrit :
>> Hi,
>>
>> some time ago somebody on this list asked for refactoring suggestions
>> so that he could give it as an assignment to students. I couldn't find
>> that email in the Photran mailing list archives, so maybe somebody can
>> pick this up or forward.
>>
>> The following refactoring idea seems useful and easy to implement
>> (please let me know if it already exists):
>>
>> Replace all tabs with ('x') spaces in current file / project (and
>> maybe also other way around). The integer x is optional.
>>
>> The reason is that - as far as I know - tab formatting is a
>> non-standard extension in Fortran 95 (I think it has been included in
>> Fortran 2003). Also, tab formatting can look different (and even
>> messy) when you open the same file in different editors. Nonetheless,
>> much legacy code does have a lot of tabs.
> 
> Dear photran developers,
> 
> I also vote for this one because I have quite a lot of Compaq Visual
> Fortran legacy code that include tabs that I would like to convert to
> spaces.
> Thanks Daniel for requesting it.

A far-too-brief Google search turned up the following interpretation of
tabs in source code:

From
http://www.nd.edu/~hpcc/solaris_opt/SUNWspro.forte6u1/WS6U1/lib/locale/C/html/manuals/fortran/user_guide/C_f95.html

"If a tab is the first nonblank character, then:

* If the character after the tab is anything other than a nonzero digit,
then the text following the tab is an initial line.

* If there is a nonzero digit after the first tab, the line is a
continuation line. The text following the nonzero digit is the next part
of the statement."

The upshot is that leading tabs are either 5 or 6 spaces, depending on
if a continuation character is detected. Heuristically, that's probably
either a digit or an '&'. Someone with a lot more varied source code
than I have available may want to scan it because this may take some
investigation to set sane defaults. If anything, it needs to be
configurable.

As an aside, I've written some naive refactoring code in perl to address
this sort of problem, primarily using regular expressions and a little
logic code. I've delved into Photran's refactoring code and still have
some trouble rectifying my line-by-line text processing approach with
the much-more-flexible-for-most-refactorings AST approach. Is there a
place for the regex-based approach for refactorings? The tabs-to-spaces
refactoring seems to fall in the cracks between something suited to AST
modification vs a regex. The AST approach is definitely preferable for
really interesting automatic code changes but IMO the learning curve is
a lot steeper.

-- Bob


Back to the top