opened
abdulmuizzf
username_0
When `on_error` is set to resume parsing for any `UnexpectedToken`, it skips the unexpected tokens inside the stream. But if the unexpected token is a `$END`, it gets into an infinite loop since the user has not made any change to the puppet before it resumes.

Using the `error_puppet` example, if we set input without a closing bracket, the $END token will be unexpected
```
def main():
    s = "[ 0 1, 2, 3,, 4, 5 6 "
    res = json_parser.parse(s, on_error=ignore_errors)
    print(res)      
```
and if `ignore_errors` returns `True` on `$END` tokens, it will loop indefinitely.

```
def ignore_errors(e):
    if e.token.type == 'COMMA':
        # Skip comma
        return True
    elif e.token.type == 'SIGNED_NUMBER':
        # Try to feed a comma and retry the number
        e.puppet.feed_token(Token('COMMA', ','))
        e.puppet.feed_token(e.token)
        return True
    
    elif e.token.type == "$END":
        # not doing anything for $END token
        print("Unexpected $END")
        return True   
    
    return False
```
Infinite loop on mishandled $END token (on_error)
issue
created
erezsh
username_1
Pushed bugfix. Test it now please.
comment
created
abdulmuizzf
username_0
Yeah, it's fixed now. Thanks!
Is it possible to pretty print the remaining tokens on the stack?

P.S. Please ignore the title changes
comment
created
erezsh
username_1
Great.

What do you mean by remaining tokens? If you get to `$END`, it means there's no more tokens to read
comment
created
abdulmuizzf
username_0
I mean the trees and tokens left in `value_stack` when it raises the exception here.
comment
created
erezsh
username_1
Just catch the exception and go to `e.puppet._value_stack`
comment
closed
erezsh
username_1
issue