]> git.lizzy.rs Git - metalua.git/commitdiff
A different approach to comments attachement
authorFabien Fleutot <fabien@MacFabien.home>
Sat, 13 Sep 2008 10:57:46 +0000 (12:57 +0200)
committerFabien Fleutot <fabien@MacFabien.home>
Sat, 13 Sep 2008 10:57:46 +0000 (12:57 +0200)
src/compiler/gg.lua
src/compiler/lexer.lua

index f54da88772684d9fdc2eda8df1e683de00cccc54..2cf9cf08f24092de2f2bcf52189437194600c3a8 100644 (file)
@@ -122,11 +122,8 @@ local function transform (ast, parser, fli, lli)
    end\r
    if type(ast) == 'table'then\r
       local ali = ast.lineinfo\r
-      local a1  = ast[1]\r
-      local comments = ali and ali.comments or \r
-         type(a1)=='table' and a1.lineinfo and a1.lineinfo.comments\r
-      if not ali or ali.first~=fli or ali.last~=lli or ali.comments~=comments then\r
-         ast.lineinfo = { first=fli, last=lli, comments = comments }\r
+      if not ali or ali.first~=fli or ali.last~=lli then\r
+         ast.lineinfo = { first = fli, last = lli }\r
       end\r
    end\r
    return ast\r
index f066d093fa4122417fbe3bab08c01dae6975d6cb..8c4752f7b597e55273286746059157e9d2a2dc62 100644 (file)
@@ -139,7 +139,10 @@ function lexer:extract ()
       if lli[2]==-1 then lli[1], lli[2] = lli[1]-1, previous_line_length-1 end
       if #self.attached_comments > 0 then 
          a.lineinfo.comments = self.attached_comments 
-         self.attached_comments = nil
+         fli.comments = self.attached_comments
+         if self.lineinfo_last then
+            self.lineinfo_last.comments = self.attached_comments
+         end
       end
       self.attached_comments = { }
       return setmetatable (a, self.token_metatable)
@@ -372,7 +375,7 @@ function lexer:sync()
       self.line, self.i = li[1], li[3]
       self.column_offset = self.i - li[2]
       self.peeked = { }
-      self.attached_comments = p1.lineinfo.comments or { }
+      self.attached_comments = p1.lineinfo.first.comments or { }
    end
 end