diff --git a/doc/source/changelog.rst b/doc/source/changelog.rst index 75fe024f..010c3879 100644 --- a/doc/source/changelog.rst +++ b/doc/source/changelog.rst @@ -5,6 +5,14 @@ MontePy Changelog 0.5 releases ============ +#Next Release# +-------------- + +**Bug Fixes** + +* Fixed parsing error with not being able to parse a blank ``sdef`` (:issue:`636`). +* Fixed parsing error with parsing ``SSW`` (:issue:`639`). + 0.5.3 -------------- diff --git a/montepy/input_parser/data_parser.py b/montepy/input_parser/data_parser.py index 57635454..63cc0d8b 100644 --- a/montepy/input_parser/data_parser.py +++ b/montepy/input_parser/data_parser.py @@ -38,9 +38,9 @@ def data_input(self, p): @_( "classifier_phrase", - "classifier_phrase KEYWORD padding", + "classifier_phrase MODIFIER padding", "padding classifier_phrase", - "padding classifier_phrase KEYWORD padding", + "padding classifier_phrase MODIFIER padding", ) def introduction(self, p): ret = {} @@ -49,8 +49,8 @@ def introduction(self, p): else: ret["start_pad"] = syntax_node.PaddingNode() ret["classifier"] = p.classifier_phrase - if hasattr(p, "KEYWORD"): - ret["keyword"] = syntax_node.ValueNode(p.KEYWORD, str, padding=p[-1]) + if hasattr(p, "MODIFIER"): + ret["keyword"] = syntax_node.ValueNode(p.MODIFIER, str, padding=p[-1]) else: ret["keyword"] = syntax_node.ValueNode(None, str, padding=None) return syntax_node.SyntaxNode("data intro", ret) @@ -183,6 +183,7 @@ class ParamOnlyDataParser(DataParser): debugfile = None @_( + "param_introduction", "param_introduction spec_parameters", ) def param_data_input(self, p): diff --git a/montepy/input_parser/tokens.py b/montepy/input_parser/tokens.py index a62856c2..8c5a2220 100644 --- a/montepy/input_parser/tokens.py +++ b/montepy/input_parser/tokens.py @@ -26,6 +26,7 @@ class MCNP_Lexer(Lexer): LIBRARY_SUFFIX, LOG_INTERPOLATE, MESSAGE, + MODIFIER, MULTIPLY, NUM_INTERPOLATE, NUM_JUMP, @@ -75,50 +76,6 @@ class MCNP_Lexer(Lexer): "cosy", "bflcl", "unc", - # materials - "gas", - "estep", - "hstep", - "nlib", - "plib", - "pnlib", - "elib", - "hlib", - "alib", - "slib", - "tlib", - "dlib", - "cond", - "refi", - "refc", - "refs", - # volume - "no", - # sdef - "cel", - "sur", - "erg", - "tme", - "dir", - "vec", - "nrm", - "pos", - "rad", - "ext", - "axs", - "x", - "y", - "z", - "ccc", - "ara", - "wgt", - "tr", - "eff", - "par", - "dat", - "loc", - "bem", - "bap", } """ Defines allowed keywords in MCNP. @@ -471,6 +428,7 @@ class DataLexer(ParticleLexer): JUMP, KEYWORD, LOG_INTERPOLATE, + MODIFIER, MESSAGE, MULTIPLY, NUMBER, @@ -486,6 +444,73 @@ class DataLexer(ParticleLexer): ZAID, } + _KEYWORDS = set(MCNP_Lexer._KEYWORDS) | { + # ssw + "sym", + "pty", + "cel", + # ssr + "old", + "new", + "col", + "wgt", + "tr", + "psc", + "poa", + "bcw", + # materials + "gas", + "estep", + "hstep", + "nlib", + "plib", + "pnlib", + "elib", + "hlib", + "alib", + "slib", + "tlib", + "dlib", + "cond", + "refi", + "refc", + "refs", + # volume + "no", + # sdef + "cel", + "sur", + "erg", + "tme", + "dir", + "vec", + "nrm", + "pos", + "rad", + "ext", + "axs", + "x", + "y", + "z", + "ccc", + "ara", + "wgt", + "tr", + "eff", + "par", + "dat", + "loc", + "bem", + "bap", + } + + _MODIFIERS = { + "no", # VOLUME + } + """ + A keyword flag at the beginning of a input that modifies it's behavior. + """ + @_(r"([|+\-!<>/%^_~@\*\?\#]|\#\d*)+") def PARTICLE_SPECIAL(self, t): """ @@ -493,6 +518,17 @@ def PARTICLE_SPECIAL(self, t): """ 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) + if t.value.lower() in self._KEYWORDS: + t.type = "KEYWORD" + if t.value.lower() in self._MODIFIERS: + t.type = "MODIFIER" + elif t.value.lower() in self._PARTICLES: + t.type = "PARTICLE" + return t + class SurfaceLexer(MCNP_Lexer): """ diff --git a/tests/inputs/test_complement_edge.imcnp b/tests/inputs/test_complement_edge.imcnp index e83b83fc..975379a1 100644 --- a/tests/inputs/test_complement_edge.imcnp +++ b/tests/inputs/test_complement_edge.imcnp @@ -33,5 +33,5 @@ m814 26000.55c 5.657-2 28000.50c 9.881-3 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 diff --git a/tests/inputs/test_dos.imcnp b/tests/inputs/test_dos.imcnp index c2725156..b6b6b14a 100644 --- a/tests/inputs/test_dos.imcnp +++ b/tests/inputs/test_dos.imcnp @@ -46,5 +46,7 @@ ksrc 0 0 0 kcode 100000 1.000 50 1050 phys:p j 1 2j 1 mode n p +ssw cel=5 99 +sdef $ blank one from issue #636 diff --git a/tests/test_integration.py b/tests/test_integration.py index c569c31c..44d4a430 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -51,7 +51,7 @@ def test_original_input(simple_problem): def test_original_input_dos(): dos_problem = montepy.read_input(os.path.join("tests", "inputs", "test_dos.imcnp")) - cell_order = [Message, Title] + [Input] * 16 + cell_order = [Message, Title] + [Input] * 18 for i, input_ob in enumerate(dos_problem.original_inputs): assert isinstance(input_ob, cell_order[i])