How to stop (and not to skip) ply-parser at parse-error?

821 views Asked by At

How can I stop the parser if an error detected?

The example

def t_error(t):
    print("Illegal character '%s'" % t.value[0])
    t.lexer.skip(1)

shows only a skip but I need a stop. How to archive?

1

There are 1 answers

0
shreyas On

You can raise an exception when you encounter an error in the lexer. For example:

class LexerError(Exception): pass


def t_error(t):
    raise LexerError("Illegal character '%s'" % t.value)