|
$ cat find_concats_in_loops.luarequire 'metalua.compiler'local ast = mlc.luastring_to_ast[[x = this..is..allowedfor i=1,10 doprint(nasty..cat)endfor _ in generator() doif not directly_under_for thenprint(nasty..anyway)endendfor i=1, math.huge doprint "no concat, no problem"end]]-- predicate to find concat operators: --local is_op_concat = |x| x.tag=='Op' and x[1]=='concat'local T = require 'metalua.treequery'-- Here's the actual query: --T(ast):under ('Forin', 'Fornum'):filter (is_op_concat):foreach (function (node)local line = node.lineinfo.first.lineprintf ("Offending node on line %i", line)end)$ metalua find_concats_in_loops.luaOffending node on line 3Offending node on line 7$ _