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

"maximum recursion depth exceeded" while parsing file with comments #914

Open
sibuk-harabudjasim opened this issue Jul 24, 2024 · 0 comments

Comments

@sibuk-harabudjasim
Copy link

Steps to reproduce:

  1. Create YANG file with content:
module test {
   yang-version 1.1;
   namespace urn:test-yang;
   prefix test;
   //
   //
   //
   // ... repeat comments 1000 times
   //
   

   container foo{}
}
  1. Run pyang -f tree test.yang
  2. Observe stacktrace:
(.venv)  manitou@Olegs-MacBook-Pro  ~/dev/utils/pyang  pyang -f tree test.yang
Traceback (most recent call last):
  File "/Users/manitou/dev/utils/pyang/.venv/bin/pyang", line 8, in <module>
    sys.exit(run())
             ^^^^^
  File "/Users/manitou/dev/utils/pyang/.venv/lib/python3.11/site-packages/pyang/scripts/pyang_tool.py", line 389, in run
    module = ctx.add_module(filename, text, in_format, name, rev,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/manitou/dev/utils/pyang/.venv/lib/python3.11/site-packages/pyang/context.py", line 81, in add_module
    module = p.parse(self, ref, text)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/manitou/dev/utils/pyang/.venv/lib/python3.11/site-packages/pyang/yang_parser.py", line 290, in parse
    stmt = self._parse_statement(None)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/manitou/dev/utils/pyang/.venv/lib/python3.11/site-packages/pyang/yang_parser.py", line 353, in _parse_statement
    while self.tokenizer.peek() != '}':
          ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/manitou/dev/utils/pyang/.venv/lib/python3.11/site-packages/pyang/yang_parser.py", line 148, in peek
    self.skip(self.keep_comments)
  File "/Users/manitou/dev/utils/pyang/.venv/lib/python3.11/site-packages/pyang/yang_parser.py", line 74, in skip
    return self.skip(keep_comments=keep_comments)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/manitou/dev/utils/pyang/.venv/lib/python3.11/site-packages/pyang/yang_parser.py", line 74, in skip
    return self.skip(keep_comments=keep_comments)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/manitou/dev/utils/pyang/.venv/lib/python3.11/site-packages/pyang/yang_parser.py", line 74, in skip
    return self.skip(keep_comments=keep_comments)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  [Previous line repeated 989 more times]
  File "/Users/manitou/dev/utils/pyang/.venv/lib/python3.11/site-packages/pyang/yang_parser.py", line 73, in skip
    self.readline()
  File "/Users/manitou/dev/utils/pyang/.venv/lib/python3.11/site-packages/pyang/yang_parser.py", line 37, in readline
    self.buf = self.lines.popleft()
               ^^^^^^^^^^^^^^^^^^^^
RecursionError: maximum recursion depth exceeded while calling a Python object

YANG files can be very big and quite often part of it is commented out to verify smth or just reduce load.
Personally, I don't see any logic in recursive call during skipping commented lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant