From 50233658c8950ecbe003d6cd70bf5add544083ea Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Fri, 3 May 2024 13:11:52 +0000 Subject: [PATCH] IR: Fix false "end" matches in pragma_regions_attached utility The problem are false matches if "end" appears in pragma content after the initial `end` keyword. --- loki/ir/pragma_utils.py | 4 ++-- loki/ir/tests/test_pragma_utils.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/loki/ir/pragma_utils.py b/loki/ir/pragma_utils.py index 99d9362c0..3a17a822a 100644 --- a/loki/ir/pragma_utils.py +++ b/loki/ir/pragma_utils.py @@ -487,12 +487,12 @@ def _matches_starting_pragma(start, p): matches = [] stack = [] for i, p in enumerate(pragmas): - if 'end' not in p.content.lower(): + if 'end' not in p.content.lower().split(' '): # If we encounter one that does have a match, stack it if any(_matches_starting_pragma(p, p2) for p2 in pragmas[i:]): stack.append(p) - elif 'end' in p.content.lower() and stack: + elif 'end' in p.content.lower().split(' ') and stack: # If we and end that matches our last stacked, keep it! if _matches_starting_pragma(stack[-1], p): p1 = stack.pop() diff --git a/loki/ir/tests/test_pragma_utils.py b/loki/ir/tests/test_pragma_utils.py index 92e05d001..f785a67f2 100644 --- a/loki/ir/tests/test_pragma_utils.py +++ b/loki/ir/tests/test_pragma_utils.py @@ -513,7 +513,7 @@ def test_tools_pragma_regions_attached_nested(frontend): out(0) = -2.0 - !$loki data nofoo + !$loki data nofoo endfoo do i=1,n !$loki do_nothing out(i) = 0.0