Lua parser implementations in Lua?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Lua parser implementations in Lua?

Asger Kunuk Alstrup
Dear All,

I have been looking for parsers for Lua, preferably written in Lua itself, that
can construct a complete parse tree of a Lua 5 source file.

I didn't find any in Lua, but a couple of others in other languages. I have
updated a user-wiki page correspondingly:

http://lua-users.org/wiki/LuaGrammar

Do anybody on this list know of a Lua 5 parser written in Lua itself?

I would like to use such a thing as a component as part of a user friendly Lua
authoring tool: This tool would read any Lua file, construct a parse tree of it,
different transformations could be done on this representation through an
easy-to-use GUI, and then the resulting, modified parse tree spit out again.

Ideally, if there would be no transformations done on the parse tree, the entire
operation should be the identical function: The output should be identical to
the input.

Having such a component not only makes writing source-to-source Lua
optimisations in Lua itself easier, but also supports making refactoring tools
that can for instance rename variables, change the scope of variables, and other
stuff as known from the Java support in Eclipse possible.

But as mentioned, my primary aim is to use this to make an easy-to-use graphical
user interface for modifying Lua code by non-technical people. We use Lua files
for implementing various features in the products we develop. Some of these can
in principle by implemented by non-programmers, but they are not able to work
directly with source code. So rather than reverted to XML files or something
else without the expressive power of Lua, and building an ordinary GUI for
manipulating such a pure data format, I'd prefer to be able to work on the Lua
source files as data files instead.
The GUI reads in a Lua file, constructs the parse tree. The GUI presents some
parts of this tree in a nice way to the user, the user manipulates those parts
using the simple GUI, and then the result is spit out as a readable, compilable
and working Lua file with the relevant parts changed.

Why do I need a full Lua parser for this? This is because the working process
would be such that the non-technical people use the GUI tool to make a prototype
feature demonstrating what they want to do. Then the programmers take what they
have done, and extend and complete the Lua code using advanced Lua functions,
control flow and what not the non-technical people do not understand. Later, the
non-technical can change some of the stuff they did (like names and other simple
things), but the programmers work should be preserved without loosing
information.

So, does anybody know of a Lua parser in Lua? Alternatively, does anybody know
of a parser generator which can produce Lua code?

Thanks,

Asger Ottar Alstrup


Reply | Threaded
Open this post in threaded view
|

Re: Lua parser implementations in Lua?

Remo Dentato
It might not be exactly what you're looking for, but if your last resort is
to write such a parser, you can have a look at
http://gel-tool.sourceforge.net where you will find a tool that is able to
parse a text file according to a set of pattern and call lua functions when
needed.

I would love to help you with that tool if you'll find it appropriate for
the task.

``RD,,


Reply | Threaded
Open this post in threaded view
|

Re: Lua parser implementations in Lua?

Mark Hamburg-4
In reply to this post by Asger Kunuk Alstrup
Another benefit of a standard representation for Lua parse trees and a way
to generate them would be that it might pave the way to implementing a
Lisp-like macro system for Lua. See various essays on Paul Graham's web site
(http://www.paulgraham.com/) for example
(http://www.paulgraham.com/avg.html) for discussions of why macros are
potentially so valuable.

Mark