Skip to content

Commit e71d1c4

Browse files
authored
Merge pull request #673 from idaholab/671-valid-particles-are-causing-parsing-error
Fixed parsing error with sigma baryons
2 parents df3d0a5 + 4b1383a commit e71d1c4

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

doc/source/changelog.rst

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ MontePy Changelog
55
0.5 releases
66
============
77

8+
#Next Version#
9+
--------------
10+
11+
**Bug Fixes**
12+
13+
* Fixed parsing bug with sigma baryon particles (e.g., ``+/-``) (:issue:`671`).
14+
815
0.5.4
916
--------------
1017

montepy/input_parser/parser_base.py

+1
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ def file_name(self, p):
381381
"FILE_PATH",
382382
"NUMBER",
383383
"PARTICLE",
384+
"PARTICLE_SPECIAL",
384385
"INTERPOLATE",
385386
"JUMP",
386387
"KEYWORD",

montepy/input_parser/syntax_node.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,7 @@ def _reverse_engineer_format(self):
14831483
if match.group(0).isupper():
14841484
upper_match += 1
14851485
total_match += 1
1486-
if upper_match / total_match >= 0.5:
1486+
if total_match and upper_match / total_match >= 0.5:
14871487
self._formatter["upper"] = True
14881488

14891489
@property

montepy/input_parser/tokens.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@ def _parse_shortcut(self, t):
220220
t.type = token_type
221221
return t
222222

223+
@_(r"([|+\-!<>/%^_~@\*\?\#]|\#\d*)+")
224+
def PARTICLE_SPECIAL(self, t):
225+
"""
226+
Particle designators that are special characters.
227+
"""
228+
return t
229+
223230
INTERPOLATE = r"\d*I"
224231
"""
225232
An interpolate shortcut.
@@ -511,13 +518,6 @@ class DataLexer(ParticleLexer):
511518
A keyword flag at the beginning of a input that modifies it's behavior.
512519
"""
513520

514-
@_(r"([|+\-!<>/%^_~@\*\?\#]|\#\d*)+")
515-
def PARTICLE_SPECIAL(self, t):
516-
"""
517-
Particle designators that are special characters.
518-
"""
519-
return t
520-
521521
@_(r"[+\-]?[0-9]*\.?[0-9]*E?[+\-]?[0-9]*[ijrml]+[a-z\./]*", r"[a-z]+[a-z\./]*")
522522
def TEXT(self, t):
523523
t = super().TEXT(t)
@@ -609,6 +609,8 @@ class SurfaceLexer(MCNP_Lexer):
609609
All allowed surface types.
610610
"""
611611

612+
PARTICLE_SPECIAL = None
613+
612614
@_(r"[+\-]?[0-9]*\.?[0-9]*E?[+\-]?[0-9]*[ijrml]+[a-z\./]*", r"[a-z]+[a-z\./]*")
613615
def TEXT(self, t):
614616
t = super().TEXT(t)

tests/inputs/test_complement_edge.imcnp

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ C Bounding water outer capsule
99
61482 0
1010
( 6 #61440 ) : (#61461 ( 7: -8))
1111
U=6000 IMP:N=1
12+
imp:+,-= 0
1213
61441 814 0.087
1314
(-61867 61870 -61759):(-61868 61869 -61759): (-61870 61868 -61759 61758)
1415
IMP:N=0
16+
imp:+ = 1
1517

1618
1 SO 5.0
1719
2 PZ 0.0
@@ -34,4 +36,4 @@ m814 26000.55c 5.657-2
3436
24000.50c 1.581-2
3537
25055.51c 1.760-3
3638
sdef cel=2 pos=0 0 0 rad=d3 ext=d3 axs=0 0 1
37-
39+
mode n + -

0 commit comments

Comments
 (0)