diff --git a/CHANGELOG.md b/CHANGELOG.md index 53589708..eb37e020 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,9 @@ Modifications by (in alphabetical order): * P. Vitt, University of Siegen, Germany * A. Voysey, UK Met Office +24/08/2026 PR #523 for #522. Adds an extension to support the (Intel-specific) + 'directory=' and 'dirspec=' arguments to the INQUIRY function. + 16/07/2026 PR #520 for #519. Fix truncation of a character length expression that contains a comma (e.g. the arguments to an intrinsic such as MAX) when the kind appears before the length in a char-selector. diff --git a/src/fparser/two/Fortran2003.py b/src/fparser/two/Fortran2003.py index ecc89765..20acfe27 100644 --- a/src/fparser/two/Fortran2003.py +++ b/src/fparser/two/Fortran2003.py @@ -9758,6 +9758,10 @@ class Inquire_Spec(KeywordValueBase): # R930 | STREAM = | UNFORMATTED = | WRITE = + If the extension `inquiry-directory` is enabled, it will also allow + the intel specific arguments: + | DIRECTORY = + | DIRSPEC = The `items` attribute for this class contains (str, instance). @@ -9789,7 +9793,7 @@ def match(string): # The only argument which need not be named is the unit number return "UNIT", File_Unit_Number(string) # We have a keyword-value pair. Check whether it is valid... - for keyword, value in [ + valid = [ ( [ "ACCESS", @@ -9825,13 +9829,21 @@ def match(string): ("IOMSG", Iomsg_Variable), ("FILE", File_Name_Expr), ("UNIT", File_Unit_Number), - ]: + ] + + if "inquire-directory" in EXTENSIONS(): + # Support the intel-specific extension: + valid.append(("DIRECTORY", File_Name_Expr)) + valid.append(("DIRSPEC", Scalar_Default_Char_Variable)) + + for keyword, value in valid: try: obj = KeywordValueBase.match(keyword, value, string, upper_lhs=True) except NoMatchError: obj = None if obj is not None: return obj + return None diff --git a/src/fparser/two/tests/test_fortran2003.py b/src/fparser/two/tests/test_fortran2003.py index cfcefaa1..43f8f129 100644 --- a/src/fparser/two/tests/test_fortran2003.py +++ b/src/fparser/two/tests/test_fortran2003.py @@ -2346,9 +2346,16 @@ def test_inquire_stmt(): assert str(obj) == "INQUIRE(UNIT = get_unit, OPENED = llopn)" -def test_inquire_spec(): +@pytest.mark.parametrize("standard_only", [True, False]) +def test_inquire_spec(monkeypatch, standard_only): """Tests that we recognise the various possible forms of entries in an inquire list (R930).""" + + if standard_only: + # Disable the inquire-directory extension for this test to verify + # that really only standard expressions are accepted + monkeypatch.setattr(utils, "_EXTENSIONS", []) + tcls = Inquire_Spec obj = tcls("1") assert isinstance(obj, tcls), repr(obj) @@ -2373,6 +2380,31 @@ def test_inquire_spec(): assert isinstance(obj, tcls), repr(obj) assert str(obj) == "DIRECT = a" + if standard_only: + with pytest.raises(NoMatchError) as excinfo: + _ = tcls("directory = a") + assert "Inquire_Spec: 'directory = a" in str(excinfo.value) + with pytest.raises(NoMatchError) as excinfo: + _ = tcls("dirspec = a") + assert "Inquire_Spec: 'dirspec = a" in str(excinfo.value) + else: + obj = tcls("directory = a") + assert isinstance(obj, tcls), repr(obj) + assert str(obj) == "DIRECTORY = a" + + obj = tcls("directory = 'some_dir'") + assert isinstance(obj, tcls), repr(obj) + assert str(obj) == "DIRECTORY = 'some_dir'" + + obj = tcls("dirspec = some_var") + assert isinstance(obj, tcls), repr(obj) + assert str(obj) == "DIRSPEC = some_var" + + # Make sure a character constant is not accepted: + with pytest.raises(NoMatchError) as excinfo: + _ = tcls("dirspec = 'a'") + assert "Inquire_Spec: 'dirspec = 'a'" in str(excinfo.value) + def test_inquire_spec_list(): """Tests that we recognise the various possible forms of diff --git a/src/fparser/two/utils.py b/src/fparser/two/utils.py index b7985a80..0fdefa2a 100644 --- a/src/fparser/two/utils.py +++ b/src/fparser/two/utils.py @@ -118,6 +118,10 @@ # With this extension, these statements will be allowed. _EXTENSIONS += ["extended-stop-args"] +# While non-standard, some compilers (Intel at least) support using inquire +# with a directory, using e.g. INQUIRE (DIRECTORY=".", DIRSPEC=C_DIRSPEC, ...) +_EXTENSIONS += ["inquire-directory"] + def EXTENSIONS(): """