Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [wtp-dev] JSDT Parser

In Orion, we have a modified version of Esprima (its a bit old now, version 2.0), that has more tolerance in it than the stock Esprima does. It might provide the level of recovery you are looking for.
Our recovery is done in a few ways:
1. we catch and record all exceptions, to make it far less 'throwy'
2. we perform node fill-ins when an exception would leave the AST is bad state
3. in some cases we rewind and try again based on state / tokens / and line endings
Our version can be found here:
The tests we run on it (to give an idea of the kinds of things we can recover from):
And lastly, the bug for us to upgrade to the latest version of Esprima:
Michael Rennie
----- Original message -----
From: Eugene Melekhov <emvv@xxxxxxx>
Sent by: wtp-dev-bounces@xxxxxxxxxxx
To: "General discussion of project-wide or architectural issues." <wtp-dev@xxxxxxxxxxx>
Subject: Re: [wtp-dev] JSDT Parser
Date: Sat, Mar 12, 2016 10:31 AM

Yes, sure, I used that option. The problem is that esprima actually throws a lot of syntax exceptions:

grep -c throwUnexpectedToken esprima.js
grep -c tolerateUnexpectedToken esprima.js

That means that in 2/3 error cases it throws exception and tolerate only 1/3. Shift meanwhile doesn't throws exceptions
in "Early Error" cases like this 0=0, which is tolerated by esprima. I have a suspicion that most of esprima
"tolerated errors" are from that "Early Error" category, which means that in fact Shift behaves like esprima :-)

I thought that it would be interesting to compare shift and esprima behavior on large enough set of erroneous code
fragments. It might happen that they are very close actually :-)

> I'm not a big expert with esprima, but do you use tolerant option like explained at ?

> 2016-03-12 10:25 GMT+01:00 Eugene Melekhov <emvv@xxxxxxx>:

> Angelo,
>  One more thing about parser tolerance. esprima for example throws an exception parsing this "relatively simple"
>  declarations:
>  //function foo(a, b {}
>  //function foo(a, b, c,) {}
>  //function foo(a, b, {} {}
 >> Yes sure, but it seems that Shift doesn't support tolerant parser which is very required for a JS editor. See
> --
>  Eugene Melekhov
>  _______________________________________________
>  wtp-dev mailing list
>  wtp-dev@xxxxxxxxxxx
>  To change your delivery options, retrieve your password, or unsubscribe from this list, visit

Eugene Melekhov

wtp-dev mailing list
To change your delivery options, retrieve your password, or unsubscribe from this list, visit

Back to the top