]> git.lizzy.rs Git - metalua.git/commitdiff
weaver sample: sorting ast children in appearance order
authorAlexander Gladysh <agladysh@gmail.com>
Sun, 25 Jan 2009 16:04:11 +0000 (19:04 +0300)
committerAlexander Gladysh <agladysh@gmail.com>
Sun, 25 Jan 2009 16:04:11 +0000 (19:04 +0300)
Fix by Fabien. This fixes ">" and ">=" node duplication on weaving

src/samples/weaver.mlua

index a5d43a93ae2c56a9f9da0bed953b2ac01d5666a2..e7e765ba9505a867a3b9cb714ad3d0443f3b84f5 100644 (file)
@@ -70,15 +70,19 @@ function weave_ast (src, ast, name)
 
       -- regular weaving of chidren in the parent's sources --
       local function weave (ast)
+         -- sort children in appearence order
+         local comp = |a,b| a.lineinfo.first[3] < b.lineinfo.first[3]
+         table.sort (ast_children [ast], comp)
          local li = ast.lineinfo
          if not li then return synthetize (ast) end
          local a, d = li.first[3], li.last[3]
          for child in ivalues (ast_children [ast]) do
             local li = child.lineinfo
             local b, c = li.first[3], li.last[3]
-            acc (src:sub (a, b-1))
+            acc (src:sub (a, b - 1))
             acc (translation [child])
-            a = c+1
+            a = c + 1
          end
          acc (src:sub (a, d))
       end