lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Jul 26, 2010 at 10:51 AM, Peter Odding <peter@peterodding.com> wrote:
>> Writing a Lua parser in Vim script would be sadomasochism but writing a
>> binding to an external tool that marks locals/globals/etc. shouldn't be too
>> hard. Not that I'm volunteering :P, unless someone has already written the
>> external tool...
>
> Sorry for replying to myself, but I just realized that Vim 7.3 beta includes
> the Lua interface by default, which means we can plug-in any existing Lua
> parser written in Lua (possibly using LPeg). This might make things a lot
> easier :-)

LuaInspect (like a few others) is currently using a combination of the
plain Lua portions of the Metalua libraries and loadstring.  I'm
finding reparsing on every keystroke with larger files is a bit slow
via Metalua, but I think it can be made manageable with some
techniques.  One technique that helps is to invoke loadstring (which
is fast) as a quick syntax check prior to attempting the Metalua
parse.  Another technique that likely will be done is to incrementally
re-parse only the block that has changed.  I'm trying this before
considering a more efficient parser, like maybe adapting Lpeg based
LuaFish/Leg to generate the Metalua-compatible AST or perhaps Rici's
luaparse.  The Metalua parser may be a bit more general than
necessary, but more things are being done than just detecting globals.
 There is also the question of how to best handle invalid syntax, as
can occur when the user is in the middle of typing something, and
there are some paths one can take here.  The optimal solution may be
to use multiple parsers.

I looked briefly at if_lua.html in vim73b but didn't see an example of
how this would be used for syntax-like things.  Is there a basic
example?  If so, then its just a matter of reworking
luainspectlib/luainspect/scite.lua (
http://github.com/davidm/lua-inspect/ ) to that.