Skip to content

Valid particles are causing parsing error #671

@MicahGale

Description

@MicahGale

Describe the bug

This is a follow-on from #669, as it actually contains two bugs.

Valid particles: (Positive|Negative) Sigma baryon, (+|-), are not being parsed properly

To Reproduce

A short code snippet of what you have ran. Please change or remove any specific values or anything that can't be public. For example:

import montepy
montepy.Cell("1 0 2 imp:+ 1")
montepy.Cell("1 0 2 imp:- 1")

Error Message (if any)

This produces the following error (note they are nearly identical so only one error is shown:

Details
---------------------------------------------------------------------------
ParsingError                              Traceback (most recent call last)
Cell In[3], line 1
----> 1 montepy.Cell("1 0 2 imp:+=1")

File ~/dev/montepy/montepy/mcnp_object.py:56, in _ExceptionContextAdder._wrap_attr_call.<locals>.wrapped(*args, **kwargs)
     54 self._handling_exception = True
     55 try:
---> 56     add_line_number_to_exception(e, self)
     57 finally:
     58     del self._handling_exception

File ~/dev/montepy/montepy/errors.py:239, in add_line_number_to_exception(error, broken_robot)
    237 # avoid calling this n times recursively
    238 if hasattr(error, "montepy_handled"):
--> 239     raise error
    240 error.montepy_handled = True
    241 args = error.args

File ~/dev/montepy/montepy/mcnp_object.py:48, in _ExceptionContextAdder._wrap_attr_call.<locals>.wrapped(*args, **kwargs)
     45 @functools.wraps(func)
     46 def wrapped(*args, **kwargs):
     47     try:
---> 48         return func(*args, **kwargs)
     49     except Exception as e:
     50         if len(args) > 0 and isinstance(args[0], MCNP_Object):

File ~/dev/montepy/montepy/cell.py:134, in Cell.__init__(self, input, number)
    132 self._surfaces = Surfaces()
    133 self._complements = Cells()
--> 134 super().__init__(input, self._parser, number)
    135 if not input:
    136     self._generate_default_tree(number)

File ~/dev/montepy/montepy/mcnp_object.py:56, in _ExceptionContextAdder._wrap_attr_call.<locals>.wrapped(*args, **kwargs)
     54 self._handling_exception = True
     55 try:
---> 56     add_line_number_to_exception(e, self)
     57 finally:
     58     del self._handling_exception

File ~/dev/montepy/montepy/errors.py:239, in add_line_number_to_exception(error, broken_robot)
    237 # avoid calling this n times recursively
    238 if hasattr(error, "montepy_handled"):
--> 239     raise error
    240 error.montepy_handled = True
    241 args = error.args

File ~/dev/montepy/montepy/mcnp_object.py:48, in _ExceptionContextAdder._wrap_attr_call.<locals>.wrapped(*args, **kwargs)
     45 @functools.wraps(func)
     46 def wrapped(*args, **kwargs):
     47     try:
---> 48         return func(*args, **kwargs)
     49     except Exception as e:
     50         if len(args) > 0 and isinstance(args[0], MCNP_Object):

File ~/dev/montepy/montepy/numbered_mcnp_object.py:59, in Numbered_MCNP_Object.__init__(self, input, parser, number)
     52 def __init__(
     53     self,
     54     input: InitInput,
     55     parser: montepy.input_parser.parser_base.MCNP_Parser,
     56     number: int = None,
     57 ):
     58     self._number = self._generate_default_node(int, -1)
---> 59     super().__init__(input, parser)
     60     self._load_init_num(number)

File ~/dev/montepy/montepy/mcnp_object.py:56, in _ExceptionContextAdder._wrap_attr_call.<locals>.wrapped(*args, **kwargs)
     54 self._handling_exception = True
     55 try:
---> 56     add_line_number_to_exception(e, self)
     57 finally:
     58     del self._handling_exception

File ~/dev/montepy/montepy/errors.py:263, in add_line_number_to_exception(error, broken_robot)
    261 args = (message,) + args[1:]
    262 error.args = args
--> 263 raise error.with_traceback(trace)

File ~/dev/montepy/montepy/mcnp_object.py:48, in _ExceptionContextAdder._wrap_attr_call.<locals>.wrapped(*args, **kwargs)
     45 @functools.wraps(func)
     46 def wrapped(*args, **kwargs):
     47     try:
---> 48         return func(*args, **kwargs)
     49     except Exception as e:
     50         if len(args) > 0 and isinstance(args[0], MCNP_Object):

File ~/dev/montepy/montepy/mcnp_object.py:139, in MCNP_Object.__init__(self, input, parser)
    135     raise MalformedInputError(
    136         input, f"Error parsing object of type: {type(self)}: {e.args[0]}"
    137     ).with_traceback(e.__traceback__)
    138 if self._tree is None:
--> 139     raise ParsingError(
    140         input,
    141         "",
    142         parser.log.clear_queue(),
    143     )
    144 if "parameters" in self._tree:
    145     self._parameters = self._tree["parameters"]

ParsingError:     , line 0

    >    0| 1 0 2 imp:+=1
          |           ^ not expected here.
There was an error parsing "+".
sly: Syntax error at line 1, token=FILE_PATH



Error came from CELL: -1, mat: 0, DENS: None from an unknown file.

Version

  • Version 1.0.0a2.dev55+g52ab1ae6
  • This will occur in most versions, but the lazy code requires >=1.0.0a1

Metadata

Metadata

Assignees

Labels

bugsA deviation from expected behavior that does not reach the level of being reportable as an "Error".parsers are hardExamples of where MCNP syntax is complicated and should be simplified.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions