Skip to content

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

@dbroemmel

Description

@dbroemmel

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions