diff --git a/openmc/region.py b/openmc/region.py index e0c05d6741..51e1820fee 100644 --- a/openmc/region.py +++ b/openmc/region.py @@ -105,17 +105,17 @@ class Region(ABC): # If special character appears immediately after a non-operator, # create a token with the appropriate half-space if i_start >= 0: - # When an opening parenthesis appears after a non-operator, - # there's an implicit intersection operator between them - if expression[i] == '(': - tokens.append(' ') - j = int(expression[i_start:i]) if j < 0: tokens.append(-surfaces[abs(j)]) else: tokens.append(+surfaces[abs(j)]) + # When an opening parenthesis appears after a non-operator, + # there's an implicit intersection operator between them + if expression[i] == '(': + tokens.append(' ') + if expression[i] in '()|~': # For everything other than intersection, add the operator # to the list of tokens diff --git a/tests/unit_tests/test_region.py b/tests/unit_tests/test_region.py index 2e517c9652..3197a8d724 100644 --- a/tests/unit_tests/test_region.py +++ b/tests/unit_tests/test_region.py @@ -208,7 +208,8 @@ def test_from_expression(reset): # Opening parenthesis immediately after halfspace r = openmc.Region.from_expression('1(2|-3)', surfs) assert str(r) == '(1 (2 | -3))' - + r = openmc.Region.from_expression('-1|(1 2(-3))', surfs) + assert str(r) == '(-1 | (1 2 -3))' def test_translate_inplace(): sph = openmc.Sphere()