dabeaz / sly

Sly Lex Yacc
Other
816 stars 107 forks source link

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

Open dscarr3000 opened 1 year ago

dscarr3000 commented 1 year ago

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?

dabeaz commented 1 year ago

Let me look into it. This isn't a feature I've used much. I will compare against PLY and Bison.