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

--enable-replacements breaks multi-line Fortran statements #153

Open
dbroemmel opened this issue Jul 4, 2023 · 1 comment
Open

--enable-replacements breaks multi-line Fortran statements #153

dbroemmel opened this issue Jul 4, 2023 · 1 comment

Comments

@dbroemmel
Copy link
Contributor

dbroemmel commented Jul 4, 2023

If a Fortran line is continued across multiple lines and contains a relation that is going to be replaced, linebreaks are not correct and the output is wrong (only tested in one direction, don't see why the other should be ok). Take as example:

     if (my_rank==0) write(*,*)  '# particles: ', npartr,'# electrons: ', ner, &
         'Box_x: ',xlr,&
          'Vplas: ',Vplas

and process via fprettify --enable-replacements, then linebreaks will be off by 2 characters. This will produce

     if (my_rank .eq. 0) write (*, *) '# particles: ', npartr, '# electrons: ', ner &
        , 'Box_x: ', xl &
        r, 'Vplas: ', Vplas

instead of

     if (my_rank .eq. 0) write (*, *) '# particles: ', npartr, '# electrons: ', ner, &
        'Box_x: ', xlr, &
        'Vplas: ', Vplas

This can break code.

I believe the error occurs because https://github.com/pseewald/fprettify/blob/c177742851f95c6ce6078027719f0edff5db5ad2/fprettify/__init__.py#L1557

is called on the original lines, while the following https://github.com/pseewald/fprettify/blob/c177742851f95c6ce6078027719f0edff5db5ad2/fprettify/__init__.py#L1561-L1562

adds (or subtracts) characters. So linebreak_pos would need to be updated (or populated later on). But I don't speak enough Python to see how to fix this right now.

@dbroemmel
Copy link
Contributor Author

dbroemmel commented Jul 4, 2023

It does not seem to break in the other direction, i.e. replacing towards c-relations, e.g. '.gt.' to '>'.

dbroemmel added a commit to dbroemmel/fprettify that referenced this issue Jul 4, 2023
This is a sort of brute-force workaround to avoid fortran-lang#153. Likely not up to
the standard of `fprettify` but 'works-for-me'.
Test amended to cover the corner case, I think.
dbroemmel added a commit to dbroemmel/fprettify that referenced this issue Jul 4, 2023
This is a sort of brute-force workaround to avoid fortran-lang#153. Likely not up to
the standard of `fprettify` but 'works-for-me'.
Test amended to cover the corner case, I think.
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

1 participant