Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lower case variables? #166

Open
AlexanderRichert-NOAA opened this issue Feb 28, 2024 · 4 comments
Open

Lower case variables? #166

AlexanderRichert-NOAA opened this issue Feb 28, 2024 · 4 comments

Comments

@AlexanderRichert-NOAA
Copy link

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
Copy link

stigh commented Feb 29, 2024

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

#163 might interest you.

@AlexanderRichert-NOAA
Copy link
Author

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
Copy link

stigh commented Feb 29, 2024

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants