Skip to content

Commit

Permalink
Merge pull request #673 from idaholab/671-valid-particles-are-causing…
Browse files Browse the repository at this point in the history
…-parsing-error

Fixed parsing error with sigma baryons
  • Loading branch information
MicahGale authored Mar 3, 2025
2 parents df3d0a5 + 4b1383a commit e71d1c4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
7 changes: 7 additions & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ MontePy Changelog
0.5 releases
============

#Next Version#
--------------

**Bug Fixes**

* Fixed parsing bug with sigma baryon particles (e.g., ``+/-``) (:issue:`671`).

0.5.4
--------------

Expand Down
1 change: 1 addition & 0 deletions montepy/input_parser/parser_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ def file_name(self, p):
"FILE_PATH",
"NUMBER",
"PARTICLE",
"PARTICLE_SPECIAL",
"INTERPOLATE",
"JUMP",
"KEYWORD",
Expand Down
2 changes: 1 addition & 1 deletion montepy/input_parser/syntax_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ def _reverse_engineer_format(self):
if match.group(0).isupper():
upper_match += 1
total_match += 1
if upper_match / total_match >= 0.5:
if total_match and upper_match / total_match >= 0.5:
self._formatter["upper"] = True

@property
Expand Down
16 changes: 9 additions & 7 deletions montepy/input_parser/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ def _parse_shortcut(self, t):
t.type = token_type
return t

@_(r"([|+\-!<>/%^_~@\*\?\#]|\#\d*)+")
def PARTICLE_SPECIAL(self, t):
"""
Particle designators that are special characters.
"""
return t

INTERPOLATE = r"\d*I"
"""
An interpolate shortcut.
Expand Down Expand Up @@ -511,13 +518,6 @@ class DataLexer(ParticleLexer):
A keyword flag at the beginning of a input that modifies it's behavior.
"""

@_(r"([|+\-!<>/%^_~@\*\?\#]|\#\d*)+")
def PARTICLE_SPECIAL(self, t):
"""
Particle designators that are special characters.
"""
return t

@_(r"[+\-]?[0-9]*\.?[0-9]*E?[+\-]?[0-9]*[ijrml]+[a-z\./]*", r"[a-z]+[a-z\./]*")
def TEXT(self, t):
t = super().TEXT(t)
Expand Down Expand Up @@ -609,6 +609,8 @@ class SurfaceLexer(MCNP_Lexer):
All allowed surface types.
"""

PARTICLE_SPECIAL = None

@_(r"[+\-]?[0-9]*\.?[0-9]*E?[+\-]?[0-9]*[ijrml]+[a-z\./]*", r"[a-z]+[a-z\./]*")
def TEXT(self, t):
t = super().TEXT(t)
Expand Down
4 changes: 3 additions & 1 deletion tests/inputs/test_complement_edge.imcnp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ C Bounding water outer capsule
61482 0
( 6 #61440 ) : (#61461 ( 7: -8))
U=6000 IMP:N=1
imp:+,-= 0
61441 814 0.087
(-61867 61870 -61759):(-61868 61869 -61759): (-61870 61868 -61759 61758)
IMP:N=0
imp:+ = 1

1 SO 5.0
2 PZ 0.0
Expand All @@ -34,4 +36,4 @@ m814 26000.55c 5.657-2
24000.50c 1.581-2
25055.51c 1.760-3
sdef cel=2 pos=0 0 0 rad=d3 ext=d3 axs=0 0 1

mode n + -

0 comments on commit e71d1c4

Please sign in to comment.