[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: A practical code analysis question
- From: Fabien <fleutot+lua@...>
- Date: Tue, 14 Feb 2012 14:00:15 +0100
So you want to find AST nodes which are:
- under either a 'Forin' or 'Fornum' node;
- are operators, with operator name 'concat';
I guess that printing the offending line number is good enough. There's a declarative tree exploration library in metalua's head, which we discussed at the last workshop, called metalua.treequery
. No proper doc yet, only a blog post
. Your problem is addressed as follows (tested with the latest version in the luaeclipse branch):
$ cat find_concats_in_loops.lua
local ast = mlc.luastring_to_ast[[
if not directly_under_for then
print "no concat, no problem"
-- predicate to find concat operators: --
local is_op_concat = |x| x.tag=='Op' and x=='concat'
local T = require 'metalua.treequery'
-- Here's the actual query: --
:under ('Forin', 'Fornum')
:foreach (function (node)
local line = node.lineinfo.first.line
printf ("Offending node on line %i", line)
$ metalua find_concats_in_loops.lua