From 06cde9797dbb1183baf0c0e346ec6223432663ad Mon Sep 17 00:00:00 2001 From: Alexander Gladysh Date: Sun, 25 Jan 2009 19:05:21 +0300 Subject: [PATCH] weaver sample: removing shadow nodes from the ast Fix by Fabien --- src/samples/weaver.mlua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/samples/weaver.mlua b/src/samples/weaver.mlua index e7e765b..f428a41 100644 --- a/src/samples/weaver.mlua +++ b/src/samples/weaver.mlua @@ -59,13 +59,17 @@ function weave_ast (src, ast, name) local _acc = { } local function acc(x) table.insert (_acc, x) end + if not next(ast) then -- shadow node, remove from ast_children + local x = ast_children[ast_parent[ast]] + for i,a in ipairs (x) do if a==ast then table.remove (x, i); break end end + return "" -- no need to continue, we know that the node is empty! + end + -- ast Can't be weaved normally, try something else -- local function synthetize (ast) - if next(ast) then -- Dumping non-empty nodes only - acc "-{expr: " - acc (table.tostring (ast, 'nohash', 80, 8)) - acc " }" - end + acc "-{expr: " + acc (table.tostring (ast, 'nohash', 80, 8)) + acc " }" end -- regular weaving of chidren in the parent's sources -- -- 2.44.0