Skip to content

Commit

Permalink
Allow whitespaces in START STENCIL directive for name argument (#414)
Browse files Browse the repository at this point in the history
* Allow whitespaces in START STENCIL directive for name argument

* Fixed names of stencils used in repeated_stencils test

* Added test for whitespaces in name argument

* Fixed tests for whitespaces not containing DECLARE and IMPORTS directives

* Small fix

* Revert "Fixed names of stencils used in repeated_stencils test"

This reverts commit a7dd889.

* Changed test name

---------

Co-authored-by: Mikael Stellio <[email protected]>
  • Loading branch information
stelliom and Mikael Stellio authored Apr 10, 2024
1 parent db65aee commit 9b90345
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tools/src/icon4pytools/liskov/parsing/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def validate(self, directives: Sequence[ts.ParsedDirective]) -> None:


def _extract_arg_from_directive(directive: str, arg: str) -> str:
match = re.search(f"{arg}=([^;)]+)", directive)
match = re.search(f"{arg}\s*=\s*([^\s;)]+)", directive)
if match:
return match.group(1)
else:
Expand Down
23 changes: 23 additions & 0 deletions tools/tests/liskov/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,29 @@ def test_directive_semantics_validation_unbalanced_stencil_directives(
parser(directives)


@mark.parametrize(
"stencil, directive",
[
(
SINGLE_STENCIL_WITH_COMMENTS,
"!$DSL START STENCIL( name = foo ; x = bar )\n!$DSL END STENCIL(name = foo)",
),
(
SINGLE_STENCIL_WITH_COMMENTS,
"!$DSL START FUSED STENCIL( name = foo ; x = bar )\n!$DSL END FUSED STENCIL(name = foo)",
),
],
)
def test_directive_semantics_validation_allow_whitespaces_in_name_arg(
make_f90_tmpfile, stencil, directive
):
fpath = make_f90_tmpfile(stencil + directive)
opath = fpath.with_suffix(".gen")
directives = scan_for_directives(fpath)
parser = DirectivesParser(fpath, opath)
parser(directives)


@mark.parametrize(
"directive",
(
Expand Down

0 comments on commit 9b90345

Please sign in to comment.