fprettify icon indicating copy to clipboard operation
fprettify copied to clipboard

cpp and continuation lines

Open hattom opened this issue 5 years ago • 1 comments
trafficstars

I ran two tests in files with cpp style preprocessor statements. In the first (which has been run through fprettify):

program test
   implicit none

   integer ::  a, b, c, e, f, g, h, i

   print *, a, b, c, d, &
#ifdef TEST
      e, f, g, h, i
#else
   e, f, g, h, i
#endif
end program test

you can see, the indentation of the e, f, ...s does not line up.

If the e, f, ... line also has a prepended ampersand, then this gives a parsing error:

$ cat test.F90
program test
   implicit none

   integer ::  a, b, c, e, f, g, h, i

   print *, a, b, c, d, &
#ifdef TEST
      & e, f, g, h, i
#else
   & e, f, g, h, i
#endif
end program test
$ fprettify test.F90 
ERROR: File test.F90, line 8
    Fatal error occured
Traceback (most recent call last):
  File "/home/me/.local/lib/python2.7/site-packages/fprettify/__init__.py", line 1584, in run
    strip_comments=args.strip_comments)
  File "/home/me/.local/lib/python2.7/site-packages/fprettify/__init__.py", line 991, in reformat_inplace
    orig_filename=filename, **kwargs)
  File "/home/me/.local/lib/python2.7/site-packages/fprettify/__init__.py", line 1093, in reformat_ffile
    lines, is_special, orig_filename, stream.line_nr)
  File "/home/me/.local/lib/python2.7/site-packages/fprettify/__init__.py", line 1337, in remove_pre_ampersands
    "Bad continuation line format", filename, line_nr)
FprettifyParseException: Bad continuation line format

I think the latter should be a valid program, although I agree that it's a slightly strange formulation.

hattom avatar Jul 08 '20 13:07 hattom

fprettify will never be fully compatible with preprocessors and may produce strange formatting - for simplicity it does not parse macros or invoke preprocessors but treats them as comments. But fprettify should always produce a correct output (correct = valid syntax) and should never fail with errors so I consider this a bug.

pseewald avatar Jul 09 '20 08:07 pseewald