lua-users home
lua-l archive

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


If getting a robust AST is a means to an end rather than fun for the sake of it, I'd suggest that you look at Metalua:
$ luarocks install metalua-parser --local
[...]
$ lua -l luarocks.loader
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> mlc = require 'metalua.compiler'.new() -- parser
> pp  = require 'metalua.pprint' -- pretty-printer
> ast = mlc:src_to_ast [[ for i=1, 10 do print(i) end ]]
> pp.print(ast,{hide_hash=true,metalua_tag=true})
{ `Fornum{ `Id "i", `Number "1", `Number "10", { `Call{ `Id "print", `Id "i" } } } }

Even if your goal is to have fun with LPeg, I believe it's wise to stick with Metalua's AST definition, unless you've got a good reason: there are many fixed mistakes in it, which could avoid being repeated :)

A complete description of the AST format is available here: http://git.eclipse.org/c/koneki/org.eclipse.koneki.metalua.git/tree/README-parser.md