fparser icon indicating copy to clipboard operation
fparser copied to clipboard

No error on invalid Fortran file

Open hiker opened this issue 4 years ago • 0 comments

While I was trying to use the dependency creation tool of fparser (in examples), I realised that if there should be an error in a Fortan file, the whole program just aborts. My program (at this stage) was just a stub with a typo in the end module statement (name not matching the module name):

module compute_born_mod

    private
    public compute_born

contains

    subroutine compute_born(grid, born, current)
        implicit none
    end subroutine compute_born

end module compute_born

The dependency creator loops over all files, and dies when parsing. E.g. (shortened):

    for filename in all_files:
        # Parse the current source file:
        try:
            reader = FortranFileReader(filename)
        except IOError:
            print("Could not open file '{0}'.".format(filename),
                  file=sys.stderr)
            sys.exit(-1)
        parser = ParserFactory().create(std="f2003")
        parse_tree = parser(reader)
        ....

The program just exists in the parse(reader) statement - no error message, no other loop iterations (for filename in all_files) are executed anymore. It should ideally raise an exception, or if it really has to abort, at least print an error message with the file name.

hiker avatar Feb 16 '21 23:02 hiker