Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 14 additions & 2 deletions src/fparser/two/Fortran2003.py
Original file line number Diff line number Diff line change
Expand Up @@ -9758,6 +9758,10 @@ class Inquire_Spec(KeywordValueBase): # R930
| STREAM = <scalar-default-char-variable>
| UNFORMATTED = <scalar-default-char-variable>
| WRITE = <scalar-default-char-variable>
If the extension `inquiry-directory` is enabled, it will also allow
the intel specific arguments:
| DIRECTORY = <file-name-expr>
| DIRSPEC = <scalar-default-char-variable>

The `items` attribute for this class contains (str, instance).

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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


Expand Down
34 changes: 33 additions & 1 deletion src/fparser/two/tests/test_fortran2003.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/fparser/two/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
"""
Expand Down
Loading