[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Common Lua (Logic/Style etc) Errors Detectable Through Static Analysis
- From: David Manura <dm.lua@...>
- Date: Thu, 17 Feb 2011 01:43:52 -0500
On Wed, Feb 16, 2011 at 2:20 AM, Jon Akhtar <akhtar@mindspring.com> wrote:
> I'd love to find a way to adapt what you have done with LuaInspect so
> that I could use it in my IntellJ plugin.
Part of it deals with building and maintaining an AST/tokenlist
in-sync with a changeable source; that part you might discard.
Another part analyzes the AST, which you can use if your code exposes
the same Metalua-style AST interface. A third part is the pluggable
user interface, which you would replace with your own.
There may be an advantage having the analysis done in Lua rather than
Java. There may even be an advantage using some language other than
Lua with better structural pattern matching. Metalua, for example,
provides a "match" syntax extension to simplify AST analysis, so that
code you see like this:
if ast.tag == 'Local' or ast.tag == 'Localrec' then
local vars_ast, values_ast = ast[1], ast[2]
.....
end
may be written more succinctly and declaratively like this:
match ast with
| `Local {vars_ast, values_ast} -> .....
| `Localrec {vars_ast, values_ast} -> .....
end
However, I choose the former for now, to stay within standard Lua,
while maintaining coding discipline. For one thing, I'd like the
source to be able to analyze itself, and trying to analyze source with
non-trivial syntax extensions like this is a complication. (The least
invasive solution is to mechanically translate the syntax extensions
in standard Lua syntax and then do analysis on the standard Lua or
some even lower-level format like SSA.)
> You have done some excellent work and your static analysis [...]
It would be even better if I had more time and a stronger background
in program analysis. There's an interesting mixture of ideas explored
but not fully developed. Maybe this would be good project for some
student to do a research project on. It's an important problem but
also a complex one and brings in the compiler theory stuff.