diff --git a/src/fparser/two/Fortran2003.py b/src/fparser/two/Fortran2003.py index 20acfe27..d342a3f8 100644 --- a/src/fparser/two/Fortran2003.py +++ b/src/fparser/two/Fortran2003.py @@ -9329,7 +9329,9 @@ class Io_Implied_Do(Base): # R917 @staticmethod def match(string): - if len(string) <= 9 or string[0] != "(" or string[-1] != ")": + # The shortest possible io-implied-do, e.g. "(i,i=1,2)", is 9 + # characters long. + if len(string) < 9 or string[0] != "(" or string[-1] != ")": return line, repmap = string_replace_map(string[1:-1].strip()) i = line.rfind("=") diff --git a/src/fparser/two/tests/test_fortran2003.py b/src/fparser/two/tests/test_fortran2003.py index 43f8f129..dc55b641 100644 --- a/src/fparser/two/tests/test_fortran2003.py +++ b/src/fparser/two/tests/test_fortran2003.py @@ -2228,6 +2228,11 @@ def test_io_implied_do(): # R917 assert isinstance(obj, tcls), repr(obj) assert str(obj) == "(a, i = 1, 2)" + # Minimal-length (9-character) io-implied-do. + obj = tcls("(i,i=1,2)") + assert isinstance(obj, tcls), repr(obj) + assert str(obj) == "(i, i = 1, 2)" + obj = tcls("((i+j,j=3,4,1), i=1,2)") assert isinstance(obj, tcls), repr(obj) assert str(obj) == "((i + j, j = 3, 4, 1), i = 1, 2)"