mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-26 21:25:36 -04:00
Fix bug in tokenize algorithm
The algorithm was failing to add intersections after right parentheses when appropriate.
This commit is contained in:
parent
b92198ebc6
commit
c237f700ad
2 changed files with 13 additions and 8 deletions
|
|
@ -27,6 +27,9 @@ class Region(object):
|
|||
|
||||
"""
|
||||
|
||||
# Strip leading and trailing whitespace
|
||||
expression = expression.strip()
|
||||
|
||||
# Convert the string expression into a list of tokens, i.e., operators
|
||||
# and surface half-spaces, representing the expression in infix
|
||||
# notation.
|
||||
|
|
@ -49,13 +52,15 @@ class Region(object):
|
|||
# to the list of tokens
|
||||
tokens.append(expression[i])
|
||||
else:
|
||||
# For spaces, we need to check the context further. If it
|
||||
# doesn't appear before a right parentheses or union, it is
|
||||
# interpreted to be as an intersection operator
|
||||
# Find next non-space character
|
||||
while expression[i+1] == ' ':
|
||||
i += 1
|
||||
|
||||
if i_start >= 0 and expression[i+1] not in ')^':
|
||||
# If previous token is a halfspace or right parenthesis and next token
|
||||
# is not a left parenthese or union operator, that implies that the
|
||||
# whitespace is to be interpreted as an intersection operator
|
||||
if (i_start >= 0 or tokens[-1] == ')') and \
|
||||
expression[i+1] not in ')^':
|
||||
tokens.append(' ')
|
||||
|
||||
i_start = -1
|
||||
|
|
|
|||
|
|
@ -108,10 +108,10 @@ contains
|
|||
i = i + 1
|
||||
end do
|
||||
|
||||
! If previous token is not an operator and next token is not a left
|
||||
! parenthese or union operator, that implies that the whitespace is to
|
||||
! be interpreted as an intersection operator
|
||||
if (i_start > 0) then
|
||||
! If previous token is a halfspace or right parenthesis and next token
|
||||
! is not a left parenthese or union operator, that implies that the
|
||||
! whitespace is to be interpreted as an intersection operator
|
||||
if (i_start > 0 .or. tokens%data(tokens%size()) == OP_RIGHT_PAREN) then
|
||||
if (index(')^', string_(i+1:i+1)) == 0) then
|
||||
call tokens%push_back(OP_INTERSECTION)
|
||||
end if
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue