Closed TeranIvy closed 5 years ago
This can be fixed by checking for an empty file within the new method of Program. Add the following code at line 209 on master of file Fortran2003.py
if string.linecount == 0:
raise FortranSyntaxError("Empty file")
Obviously some tidying of the SyntaxError would need to be done. There have been improvements to the output of errors in PR @121 (e.g. it modifies the script so it does not raise an exception if there is no code in the buffer - which is what happens in this case) so I'll wait until that is on master before adding this code.
I don't think the above solution is correct as it is returning 0 even if the number of lines in the file is not 0. We might need to actually read a line, check it, then put it back if it is not empty, or perhaps modify the reader to give us the information we want.
For anything other than a completely empty file we get a sensible syntax error. So we just need to handle this particular case.
It's pretty simple to raise a SyntaxError when there is an empty file but I don't think that it what @TeranIvy wants. She has asked for there to be no error if the input is empty. I think I can do this by using sys.exit("message").
Created branch empty_input
raising SystemExit works but it kills the interpreter when running interactively (unless it is trapped) so I'm not happy with this as a solution.
Now I'm just returning if there is no content, rather than raising an exception when there are no matches and this seems to work.
pr #134 has been merged to master. Closing this issue.
When parsing an empty file fparser2 returns an unhelpful error
Apparently, just compiling an empty file is tolerated by Fortran compilers (e.g. Intel 17.0.1 and Gnu 6.1.0) so fparser2 should not fail because of this. However, a warning to report parsing an empty file would be very useful.