jison icon indicating copy to clipboard operation
jison copied to clipboard

Implementing own parser.yy.parseError function throws error

Open mebibou opened this issue 10 years ago • 6 comments

When using the generated javascript parser file, and implementing my own parseError function like:

parser.yy.parseError = function(error, hash) {...};

gives the following error every time I parse something: TypeError: Cannot read property '0' of undefined You can find a working example here: http://jsfiddle.net/fLknW/

It seems to me that the algorithm should stop after it calls parseError(errStr, {...}) since action will always be undefined. The error is not thrown when not overriding the default implementation of parseError since by default it does throw new Error(str); which stops the algorithm

mebibou avatar Jun 04 '14 08:06 mebibou

:+1:

XavierBoubert avatar Sep 02 '14 09:09 XavierBoubert

No one ever got around to this one then?

rubenvereecken avatar Jan 13 '16 10:01 rubenvereecken

Anything new on this?

mathiasrw avatar Feb 08 '16 10:02 mathiasrw

Since jison doesn't have yyerror support anyway I just ended up catching the error somewhere in my wrapper code and working with the error object from there.

rubenvereecken avatar Feb 08 '16 10:02 rubenvereecken

:-/

mathiasrw avatar Feb 08 '16 11:02 mathiasrw

Have you tried to define a parseError function in the parser scope? This works for me.

yy = { };
yy.parseError = function(msg, hash) {
     doSomething();
}
parser.yy = yy;

yosbelms avatar Feb 08 '16 14:02 yosbelms