lua-users home
lua-l archive

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


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