From 2fae134acc400a763bd7ef903f08c8d1c8f9fb60 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Fri, 28 Feb 2025 19:03:51 -0600 Subject: [PATCH 1/6] Replicated issue #671 with sigma baryons. --- tests/inputs/test_complement_edge.imcnp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/inputs/test_complement_edge.imcnp b/tests/inputs/test_complement_edge.imcnp index 975379a1..319ec7d3 100644 --- a/tests/inputs/test_complement_edge.imcnp +++ b/tests/inputs/test_complement_edge.imcnp @@ -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 @@ -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 + - From 301c837b6b4d3401926376eedfc2578fa8b5e3e0 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Fri, 28 Feb 2025 20:13:01 -0600 Subject: [PATCH 2/6] Fixed edge case in ParticleNode --- montepy/input_parser/syntax_node.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/montepy/input_parser/syntax_node.py b/montepy/input_parser/syntax_node.py index 8d92d961..57a87d1e 100644 --- a/montepy/input_parser/syntax_node.py +++ b/montepy/input_parser/syntax_node.py @@ -1483,8 +1483,9 @@ def _reverse_engineer_format(self): if match.group(0).isupper(): upper_match += 1 total_match += 1 - if upper_match / total_match >= 0.5: - self._formatter["upper"] = True + if total_match: + if upper_match / total_match >= 0.5: + self._formatter["upper"] = True @property def comments(self): From 3b1371e55a2a2fee0bd45b21111cf8f225c52e8f Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Fri, 28 Feb 2025 20:15:30 -0600 Subject: [PATCH 3/6] Switched tokens around to match +/- particles. --- montepy/input_parser/tokens.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/montepy/input_parser/tokens.py b/montepy/input_parser/tokens.py index 8c5a2220..1943132c 100644 --- a/montepy/input_parser/tokens.py +++ b/montepy/input_parser/tokens.py @@ -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. @@ -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) @@ -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) From 357026b0a9e2e22e1c74b679782148cd5ec2669d Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Fri, 28 Feb 2025 20:34:46 -0600 Subject: [PATCH 4/6] Allowed particle_special in file paths. --- montepy/input_parser/parser_base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/montepy/input_parser/parser_base.py b/montepy/input_parser/parser_base.py index d725cc24..2cc54baa 100644 --- a/montepy/input_parser/parser_base.py +++ b/montepy/input_parser/parser_base.py @@ -381,6 +381,7 @@ def file_name(self, p): "FILE_PATH", "NUMBER", "PARTICLE", + "PARTICLE_SPECIAL", "INTERPOLATE", "JUMP", "KEYWORD", From cbec7c04d84fb85fde8884c51dc17197c90d3e11 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Fri, 28 Feb 2025 20:39:51 -0600 Subject: [PATCH 5/6] Added #671 to the changelog. --- doc/source/changelog.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/source/changelog.rst b/doc/source/changelog.rst index af954143..ed666106 100644 --- a/doc/source/changelog.rst +++ b/doc/source/changelog.rst @@ -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 -------------- From 4b1383a483b88b016024ab0a2d6f2c2b1efa7765 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Mon, 3 Mar 2025 12:44:32 -0600 Subject: [PATCH 6/6] Simplified nested logic. --- montepy/input_parser/syntax_node.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/montepy/input_parser/syntax_node.py b/montepy/input_parser/syntax_node.py index 57a87d1e..07022b2d 100644 --- a/montepy/input_parser/syntax_node.py +++ b/montepy/input_parser/syntax_node.py @@ -1483,9 +1483,8 @@ def _reverse_engineer_format(self): if match.group(0).isupper(): upper_match += 1 total_match += 1 - if total_match: - if upper_match / total_match >= 0.5: - self._formatter["upper"] = True + if total_match and upper_match / total_match >= 0.5: + self._formatter["upper"] = True @property def comments(self):