stfc / fparser

This project maintains and develops a Fortran parser called fparser2 written purely in Python which supports Fortran 2003 and some Fortran 2008. A legacy parser fparser1 is also available but is not supported. The parsers were originally part of the f2py project by Pearu Peterson.
https://fparser.readthedocs.io
Other
64 stars 29 forks source link

namelist false match error #165

Closed rupertford closed 1 year ago

rupertford commented 5 years ago

The f2003 namelist match rule r552 produces an assertion error when a variable starting with the name `namelist' is initialised ...

program test
  NamelistFile = "dummy file"
end program
bblay commented 2 years ago

Just tried to make a PR to fix this, based on the issue 4 fix and the above snippet, but the error does not occur. (What I think is) the bug is still there, if string[:8].upper() != 'NAMELIST':, but it seems it's no longer being triggered, perhaps because things are being called in a different order now.

MatthewHambley commented 1 year ago

There still seems to be a problem around this issue. Here is my test case:

program test

  type(foo_type), pointer :: namelist_ptr

  namelist_ptr => null()

end program test

Parsing this using fparser2 <filename> gives

  File "/net/home/h06/mhambley/Woomera/PointerAssignment/venv/lib/python3.7/site-packages/fparser/two/Fortran2003.py", line 4677, in match
    assert not fst, repr((fst, parts))
AssertionError: ('_ptr => null()', [])

It looks like the "namelist" at the start of the variable name is being interpreted as a "namelist" keyword.

rupertford commented 1 year ago

I still get an error for both examples on master. I'll take it on as I have a fix, but it will take a little while to tidy up the class and add the required tests.

rupertford commented 1 year ago

Created branch 165_namelist_error