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