Parsing incomplete statements with esprima

60 views
Skip to first unread message

Tobias Pflug

unread,
Feb 5, 2013, 2:28:34 PM2/5/13
to esp...@googlegroups.com
Hi,

unsatisfied with the available options for javascript code completion in vim I recently spent some time evaluating some options.
What I ended up with was tunnelling expressions to a running phantomjs instance for inspection.

While that wasn't all that hard I realised that deciding what part of a line of text should actually be completed/inspected isn't
quite obvious or trivial. 

Now I'm wondering if esprima might be an option for this. I'd like to ask for some input if developers think that this is a feasible
usage scenario for esprima. From what i gathered by looking at the documentation and playing around in node it of course isn't
exactly meant for this purpose, i.e it will just fail if I pass it say "if (app.foo.someVal." but I guess scenarios like this could be
fixed/handled by balancing parens and removing trailing "." and such transforming te input to "if (app.foo.someVal) {}" before
passing it to esprima. In which case I could retrieve the last (only) identifier token as "app.foo.someVal" and inspect that.

Yet i'm far from being knowledgable on this topic so any kind of input would be appreciated. Is esprima completely wrong
for this ?

thanks in advance,
Tobi

Ariya Hidayat

unread,
Feb 6, 2013, 11:36:47 AM2/6/13
to esp...@googlegroups.com
Hi Tobi,

This one might be interesting for you:
http://ariya.ofilabs.com/2012/07/code-editing-with-autocompletion-in-eclipse-orion.html.

If Orion is too big, you might want to check out
https://github.com/scripted-editor/scripted/.

Let me know if you have more questions!


Regards,


--
Ariya Hidayat, http://ariya.ofilabs.com
http://twitter.com/ariyahidayat
http://gplus.to/ariyahidayat

Andy Clement

unread,
Feb 6, 2013, 12:29:07 PM2/6/13
to esp...@googlegroups.com
Hi,

Just fleshing out what Ariya mentioned.

Both orion and scripted are using the recoverable esprima fork from here:

there is an interactive demo of it here:

If I type in your example text:

if (app.foo.someVal.

you'll see it returns errors and an Ast.

It isn't finished yet but gives us enough to offer decent content assist in some key situations.

cheers,
Andy
Reply all
Reply to author
Forward
0 new messages