Skip to main content

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

Hi,

Is this refactoring supposed to be for free-form or fixed-form fortran
code?  I was assuming free-form, but Bob's e-mail seems to be talking
about fixed-form.

Matt

On Mon, Nov 8, 2010 at 3:27 AM, Daniel Harenberg
<dan.harenberg@xxxxxxxxx> wrote:
> Bob,
>
> I don't understand much of what you were writing. I am just a user and have
> no development knowledge, but maybe my feedback is useful, although I am
> probably wrong on several points.
>
> First, but not so importantly, to me, the starred bullet-points in your
> citation don't seem to be excluding each other, so I don't get them, but
> never mind. More importantly, tabs often don't appear at the beginning of a
> line, but in the middle of the code within a line, e.g. to align the '=' (or
> any other sign) among several lines, or to quickly move an end-of-line
> comment a bit to the right and have it also aligned with other comments.
>
> I thought that tabs are somehow clearly defined in a source (or text) file,
> because independent of which editor I use, it always recognizes them,
> although for some reason, the lines are often not aligned anymore (maybe
> it's editor-specific how to interpret them, like the 5 or 6 spaces you
> mentioned). I imagined the refactoring pretty simple (and still quite
> effective): replace every tab with 'x' spaces. That should work for the
> cases I outlined, and should work independent of the editor (and it's
> interpretation). Again, I am only a user and might be very wrong.
>
> Thanks for your efforts.
>
> Daniel
>
> On 11/08/2010 05:01 AM, Bob Apthorpe wrote:
>>
>> 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
>> _______________________________________________
>> photran mailing list
>> photran@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/photran
>
> _______________________________________________
> photran mailing list
> photran@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/photran
>


Back to the top