fortran-lang / fprettify

auto-formatter for modern fortran source code
https://pypi.python.org/pypi/fprettify
Other
368 stars 73 forks source link

Lower case variables? #166

Open AlexanderRichert-NOAA opened 6 months ago

AlexanderRichert-NOAA commented 6 months ago

Is there a way to lower case all variable and non-intrinsic function names with fprettify, and if not, could there be? I'm trying to automate our reformatting of Fortran code and this looks very promising-- We have a lot of code with mixed cases and want to automatically change everything to one or the other case without touching comments, quoted strings, etc. If it sounds like the sort of thing that would be acceptable to include, I'd be happy to take a crack at contributing the modification.

stigh commented 6 months ago

@AlexanderRichert-NOAA. Yes, this works well in fprettify. Use the argument --case 1 1 1 1.

https://github.com/pseewald/fprettify/issues/163 might interest you.

AlexanderRichert-NOAA commented 6 months ago

I am unable to achieve the desired behavior both with the latest pip release (0.3.7) and with the head of master.

Uncleaned test code:

SUBROUTINE mycode(MYVAR, MYOTHERVAR)
  IMPLICIT NONE
  REAL :: MYVAR
  INTEGER :: MYOTHERVAR
END SUBROUTINE MYCODE

Desired output:

$ fprettify --case 1 1 1 1 test.F90
subroutine mycode(myvar, myothervar)
   implicit none
   real :: myvar
   integer :: myothervar
end subroutine mycode

Actual output (0.3.7 and master):

$ fprettify --case 1 1 1 1 test.F90
subroutine mycode(MYVAR, MYOTHERVAR)
   implicit none
   real :: MYVAR
   integer :: MYOTHERVAR
end subroutine MYCODE

For what it's worth, I was able to achieve the desired effect by adding a catch-all condition to the if/elif block under replace_keywords_single_fline, where I added a fifth --case option to let me lower- or upper-case all of the text that's not comments, strings, keywords, procedures, operators, or constants. Needless to say let me know if I'm missing something.

stigh commented 6 months ago

Oh, then I completely misunderstood, sorry. Though you meant the intrinsics.

In my opinion it's better to use the IDE for this, and then I would suggest to use camelCase or snake_case. VSCode has a feature for renaming variables.

AlexanderRichert-NOAA commented 6 months ago

Okay thanks. I'll probably create a separate script or fork fprettify so I can do it CI. Feel free to close this issue if this is not likely to be accepted in fprettify.