Repository: idaholab/MontePy

Issue:
multiline parentheses cell definition appears not to be supported by the parser 
**Describe the bug**

Hello again, I am continuing my quest to try and make our inputs montepy readable. See below a minimal MCNP legal input that montepy apparently cannot parse.

**To Reproduce**

code snippet

``` python
import montepy

# Read the file
problem = montepy.read_input("extracted_cell.i")
```

**Error Message (if any)**

Error message:

``` python
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File c:\ProgramData\Anaconda3\envs\montepy\lib\site-packages\sly\yacc.py:2138, in Parser.parse(self, tokens)
   [2137](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/sly/yacc.py:2137) try:       
-> [2138](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/sly/yacc.py:2138)     value = p.func(self, pslice)
   [2139](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/sly/yacc.py:2139) except AttributeError as e:

File c:\ProgramData\Anaconda3\envs\montepy\lib\site-packages\montepy\input_parser\cell_parser.py:178, in CellParser.geometry_factory(self, p)
    [177](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/input_parser/cell_parser.py:177)     for node in p.padding.nodes:
--> [178](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/input_parser/cell_parser.py:178)         nodes["start_pad"].append(node)
    [179](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/input_parser/cell_parser.py:179) return syntax_node.GeometryTree("geom parens", nodes, ">", p.geometry_expr)

File c:\ProgramData\Anaconda3\envs\montepy\lib\site-packages\montepy\input_parser\syntax_node.py:401, in PaddingNode.append(self, val, is_comment)
    [400](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/input_parser/syntax_node.py:400)     return
--> [401](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/input_parser/syntax_node.py:401) parts = val.split("\n")
    [402](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/input_parser/syntax_node.py:402) if len(parts) > 1:

AttributeError: 'CommentNode' object has no attribute 'split'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
Cell In[20], [line 4](vscode-notebook-cell:?execution_count=20&line=4)
      [1](vscode-notebook-cell:?execution_count=20&line=1) import montepy
      [3](vscode-notebook-cell:?execution_count=20&line=3) # Read the file
----> [4](vscode-notebook-cell:?execution_count=20&line=4) problem = montepy.read_input("extracted_cell.i")

File c:\ProgramData\Anaconda3\envs\montepy\lib\site-packages\montepy\input_parser\input_reader.py:29, in read_input(input_file, mcnp_version, replace)
     [27](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/input_parser/input_reader.py:27) problem = mcnp_problem.MCNP_Problem(input_file)
     [28](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/input_parser/input_reader.py:28) problem.mcnp_version = mcnp_version
---> [29](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/input_parser/input_reader.py:29) problem.parse_input(replace=replace)
     [30](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/input_parser/input_reader.py:30) return problem

File c:\ProgramData\Anaconda3\envs\montepy\lib\site-packages\montepy\mcnp_problem.py:271, in MCNP_Problem.parse_input(self, check_input, replace)
    [269](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/mcnp_problem.py:269) if len(input.input_lines) > 0:
    [270](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/mcnp_problem.py:270)     try:
--> [271](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/mcnp_problem.py:271)         obj = obj_parser(input)
    [272](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/mcnp_problem.py:272)         obj.link_to_problem(self)
    [273](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/mcnp_problem.py:273)         obj_container.append(obj)

File c:\ProgramData\Anaconda3\envs\montepy\lib\site-packages\montepy\cell.py:88, in Cell.__init__(self, input)
     [86](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/cell.py:86) self._complements = Cells()
     [87](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/cell.py:87) self._number = self._generate_default_node(int, -1)
---> [88](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/cell.py:88) super().__init__(input, self._parser)
     [89](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/cell.py:89) if not input:
     [90](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/cell.py:90)     self._generate_default_tree()

File c:\ProgramData\Anaconda3\envs\montepy\lib\site-packages\montepy\mcnp_object.py:50, in MCNP_Object.__init__(self, input, parser)
     [48](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/mcnp_object.py:48)     except AttributeError as e:
     [49](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/mcnp_object.py:49)         pass
---> [50](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/mcnp_object.py:50)     self._tree = parser.parse(input.tokenize(), input)
     [51](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/mcnp_object.py:51)     self._input = input
     [52](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/mcnp_object.py:52) except ValueError as e:

File c:\ProgramData\Anaconda3\envs\montepy\lib\site-packages\montepy\input_parser\parser_base.py:156, in MCNP_Parser.parse(self, token_generator, input)
    [153](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/input_parser/parser_base.py:153)         yield token
    [155](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/input_parser/parser_base.py:155) # change to using `gen_wrapper()` to debug
--> [156](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/input_parser/parser_base.py:156) tree = super().parse(token_generator)
    [157](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/input_parser/parser_base.py:157) # treat any previous errors as being fatal even if it recovered.
    [158](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/montepy/input_parser/parser_base.py:158) if len(self.log) > 0:

File c:\ProgramData\Anaconda3\envs\montepy\lib\site-packages\sly\yacc.py:2140, in Parser.parse(self, tokens)
   [2138](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/sly/yacc.py:2138)     value = p.func(self, pslice)
   [2139](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/sly/yacc.py:2139) except AttributeError as e:
-> [2140](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/sly/yacc.py:2140)     raise AttributeError
   [2141](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/sly/yacc.py:2141) if value is pslice:
   [2142](file:///C:/ProgramData/Anaconda3/envs/montepy/lib/site-packages/sly/yacc.py:2142)     value = (pname, *(s.value for s in pslice._slice))

AttributeError:
```

**MCNP input file snippet**

Minimum MCNP example:

```
C-MODEL RELEASE 181031 REV 190715 ISSUED 15/07/2019
43    0   
          (                 $ a dollar comment here
            -1 2 
          )
          IMP:N=1.000000  IMP:P=1.000000

1 PZ 0
2 PZ 2

MODE N
NPS 1
```

**Version**

 - Version 0.3.2


**Additional context**

Thanks for having a look at this!


Discussion:

Patch:
diff --git a/doc/source/changelog.rst b/doc/source/changelog.rst
index c943806b..5af2893e 100644
--- a/doc/source/changelog.rst
+++ b/doc/source/changelog.rst
@@ -6,7 +6,8 @@ MontePy Changelog
 
 **Bug fixes**
 
-* Fixed bug with appending and renumbeing numbered objects from other MCNP problems (:issue:`466`).
+* Fixed bug with appending and renumbering numbered objects from other MCNP problems (:issue:`466`).
+* Fixed bug with dynamic typing and the parsers that only appear in edge cases (:issue:`461`).
 
 
 0.3.2
diff --git a/montepy/input_parser/syntax_node.py b/montepy/input_parser/syntax_node.py
index 7be1f7e2..b65dae5f 100644
--- a/montepy/input_parser/syntax_node.py
+++ b/montepy/input_parser/syntax_node.py
@@ -393,9 +393,9 @@ class PaddingNode(SyntaxNodeBase):
         :param is_comment: whether or not the node is a comment.
         :type is_comment: bool
         """
-        if is_comment:
-            if not isinstance(val, CommentNode):
-                val = CommentNode(val)
+        if is_comment and not isinstance(val, CommentNode):
+            val = CommentNode(val)
+        if isinstance(val, CommentNode):
             self.nodes.append(val)
             return
         parts = val.split("\n")


Test patch:
diff --git a/tests/test_edge_cases.py b/tests/test_edge_cases.py
index 32375dd4..2cb9d4fe 100644
--- a/tests/test_edge_cases.py
+++ b/tests/test_edge_cases.py
@@ -163,6 +163,14 @@ class EdgeCaseTests(TestCase):
             "                            3201  15i   3217",
             "                            u=20",
         ],
+        # issue #461
+        [
+            "43    0",
+            "      (                 $ a dollar comment here",
+            "        -1 2",
+            "      )",
+            "      IMP:N=1.000000 IMP:P=1.000000",
+        ],
     ],
 )
 def test_complex_cell_parsing(lines):