Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing parser error with read card #372

Merged
merged 17 commits into from
Apr 15, 2024

Conversation

MicahGale
Copy link
Collaborator

@MicahGale MicahGale commented Feb 15, 2024

Problem

To recap the issue. The file:

Testing read card
C this is a comment
read file=file2read.imcnp

1 so 0.5 

mode n

Causes this error:

Traceback (most recent call last):
  File "/projects/experiment_analysis/tjlaboss/mcnpy_testing/numberead/TestRead.py", line 3, in <module>
    deck = montepy.read_input(fname)
  File "/projects/experiment_analysis/tjlaboss/mcnpy_testing/numberead/montepy/input_parser/input_reader.py", line 26, in read_input
    problem.parse_input()
  File "/projects/experiment_analysis/tjlaboss/mcnpy_testing/numberead/montepy/mcnp_problem.py", line 284, in parse_input
    raise e
  File "/projects/experiment_analysis/tjlaboss/mcnpy_testing/numberead/montepy/mcnp_problem.py", line 269, in parse_input
    obj = obj_parser(input)
  File "/projects/experiment_analysis/tjlaboss/mcnpy_testing/numberead/montepy/cell.py", line 82, in __init__
    super().__init__(input, self._parser)
  File "/projects/experiment_analysis/tjlaboss/mcnpy_testing/numberead/montepy/mcnp_object.py", line 57, in __init__
    raise ParsingError(
montepy.errors.ParsingError:     testRead.imcnp, line 3

         2| C this is a comment
    >    3| read file=file2read.imcnp
          |  ^^^^ not expected here.
There was an error parsing "read".
sly: Syntax error at line 2, token=KEYWORD

However after some looking into this; it is a red hearing. This is being thrown by the CellParser, and not the ReadParser. But why is that?

The key logic to decide if an input is a ReadInput is here in mcnp_input.py:

        parse_result = self._parser.parse(self.tokenize(), self)
        first_word = input_lines[0].split()[0].lower()
        if not parse_result:
            if first_word != "read":
                raise ValueError("Not a valid Read Input")
            else:
                raise ParsingError(self, "", self._parser.log.clear_queue())

So this is really a parsing error with ReadInput that is hidden.

The real error is:

>               raise ParsingError(self, "", self._parser.log.clear_queue())
E               montepy.errors.ParsingError:     tests/inputs/readEdgeCase.imcnp, line 3
E
E                        2| C this is a comment
E                   >    3| read file=file2read.imcnp
E                         |                ^^^^^ not expected here.
E               There was an error parsing "2read".
E               sly: Syntax error at line 2, token=NUMBER_WORD

montepy/input_parser/mcnp_input.py:304: ParsingError

Solution

  1. Don't use a parser to see if it a read input to increase efficiency.
  2. Make is_comment a "global function"
  3. Make searching for the keyword "read" more robust by discarding starting comments

Fixes #206.

@MicahGale MicahGale linked an issue Feb 15, 2024 that may be closed by this pull request
@MicahGale MicahGale self-assigned this Feb 16, 2024
@MicahGale MicahGale added the bugs A deviation from expected behavior that does not reach the level of being reportable as an "Error". label Feb 16, 2024
@MicahGale MicahGale added this to the Release-0.3 milestone Feb 16, 2024
@MicahGale MicahGale marked this pull request as ready for review February 16, 2024 00:00
@MicahGale MicahGale requested a review from tjlaboss February 16, 2024 00:04
@coveralls
Copy link
Collaborator

coveralls commented Mar 5, 2024

Pull Request Test Coverage Report for Build 8696428823

Details

  • 23 of 23 (100.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 98.159%

Totals Coverage Status
Change from base Build 8696419178: 0.02%
Covered Lines: 5757
Relevant Lines: 5865

💛 - Coveralls

@MicahGale MicahGale marked this pull request as draft March 5, 2024 15:49
@MicahGale MicahGale marked this pull request as ready for review March 5, 2024 16:27
@MicahGale MicahGale mentioned this pull request Mar 9, 2024
1 task
@MicahGale
Copy link
Collaborator Author

Want to review this one first @tjlaboss?

@tjlaboss
Copy link
Collaborator

yes. I don't know when I'll get to it but I'll try to make some time in the immediate future

montepy/utilities.py Outdated Show resolved Hide resolved
montepy/utilities.py Outdated Show resolved Hide resolved
montepy/utilities.py Outdated Show resolved Hide resolved
@MicahGale MicahGale requested a review from tjlaboss April 15, 2024 21:32
@MicahGale MicahGale enabled auto-merge April 15, 2024 21:38
@MicahGale MicahGale merged commit 6490485 into develop Apr 15, 2024
13 checks passed
@MicahGale MicahGale deleted the 206-sly-syntax-error-for-numbers-in-read-cards branch April 15, 2024 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugs A deviation from expected behavior that does not reach the level of being reportable as an "Error".
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SLY Syntax Error for Numbers in 'READ' cards
3 participants