Skip to content

self.errok() still creates an error token #102

@dscarr3000

Description

@dscarr3000

I've been using SLY to write a parser for a fake programming language and I think I've encountered an issue. When trying to do some error handling I created an error method matching what was used in the docs.

def error(self, p):
    if p:
        print("Syntax error at token", p.type)
        # Just discard the token and tell the parser it's okay.
        self.errok()
    else:
        print("Syntax error at EOF")

However, the docs say that self.errok() will "prevent an error token from being generated". This doesn't appear to be the case, when I test my parser with bad input I'm getting multiple error tokens happening. Here is my output:

python3 KXICompiler.py -p <<EOF
void kxi2022 main() {
        int i  0;
}
EOF
Syntax error at token INT
Syntax error at token error
Syntax error at token error
Syntax error at token error
Syntax error at token error
Syntax error at token error
Syntax error at token error
Syntax error at token error
Syntax error at token error
Syntax error at token error
Syntax error at token error
Syntax error at token INT
Syntax error at token SEMI_COLON
Syntax error at token RIGHT_CURLY_BRACE
Syntax error at EOF

Am I just understanding the docs wrong or is there not supposed to be an error token generated when I call errok?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions