Closed Renegade85 closed 3 years ago
The easiest way to terminate everything would be to raise an exception. For example:
raise SystemExit("Goodbye")
(Of course, you could make your own exception too).
Seems the restart of the parser was not necessary. Just pumping out all the tokens and returning the last one does the trick.
def error(self, t):
while True:
tok = next(self.tokens, None)
if not tok:
break
return tok
In case this will cause issues in the future, I'll go the exception way. :-)
Thank you very much for your help.
Hello,
this is more a question then a bug report. How to properly terminate parsing, if the parser stumbles on an error? I just want to report that one error, but don't want to continue on parsing nor execute the AST. Just throw away everything and terminate gracefully reporting the line where the error has been detected.
Is there a way to clear the parsing stack and iterate over the rest of the tokens in the input or something similar?
My error function follows:
However, this seems to be not working. Just one more point, which may be important, the error is "artificial" meaning, I got parts of my grammar which are unsupported and if the parser parses such code, the "error()" method is invoked.
The error I'm getting from python:
File "C:\Users\nxf25094\Documents\sProjects\git_repos\spsdk\venv38\lib\site-packages\sly\yacc.py", line 2091, in parse self.state = goto[statestack[-1]][pname] IndexError: list index out of range