]> git.lizzy.rs Git - metalua.git/commitdiff
weaver sample: removing shadow nodes from the ast
authorAlexander Gladysh <agladysh@gmail.com>
Sun, 25 Jan 2009 16:05:21 +0000 (19:05 +0300)
committerAlexander Gladysh <agladysh@gmail.com>
Sun, 25 Jan 2009 16:05:21 +0000 (19:05 +0300)
Fix by Fabien

src/samples/weaver.mlua

index e7e765ba9505a867a3b9cb714ad3d0443f3b84f5..f428a419d857e8d7141459431ea750daae6005f0 100644 (file)
@@ -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 --