]> git.lizzy.rs Git - metalua.git/commitdiff
missing lineinfo from gg.onkeyword() and for "|x| y" syntax
authorFabien Fleutot <fabien@MacFabien.home>
Thu, 27 Nov 2008 23:58:12 +0000 (00:58 +0100)
committerFabien Fleutot <fabien@MacFabien.home>
Thu, 27 Nov 2008 23:58:12 +0000 (00:58 +0100)
src/compiler/gg.lua
src/compiler/mlp_ext.lua

index 83c68d5ca38424d3b859daede0cd38857b0680f5..7d2900205e0c683e1c32f9141fe0606403422439 100644 (file)
@@ -191,8 +191,9 @@ function sequence (p)
       if tb == "string" then seq.tag = builder\r
       elseif tb == "function" or builder and builder.__call then seq = builder(seq)\r
       elseif builder == nil then -- nothing\r
-      else error("Invalid builder of type "..tb.." in sequence") end\r
+      else error ("Invalid builder of type "..tb.." in sequence") end\r
       seq = transform (seq, self, fli, lli)\r
+      assert (not seq or seq.lineinfo)\r
       return seq\r
    end\r
 \r
@@ -612,6 +613,11 @@ end --</list>
 -- [gg.onkeyword] parser is the result of the subparser (modulo\r
 -- [transformers] applications).\r
 --\r
+-- lineinfo: the keyword is *not* included in the boundaries of the\r
+-- resulting lineinfo. A review of all usages of gg.onkeyword() in the\r
+-- implementation of metalua has shown that it was the appropriate choice\r
+-- in every case.\r
+--\r
 -- Input fields:\r
 --\r
 -- * [name]: as usual\r
@@ -644,10 +650,12 @@ function onkeyword (p)
    -------------------------------------------------------------------\r
    function p:parse(lx)\r
       if lx:is_keyword (lx:peek(), unpack(self.keywords)) then\r
-         local fli = lx:lineinfo_right()\r
+         --local fli = lx:lineinfo_right()\r
          if not self.peek then lx:next() end\r
-         local lli = lx:lineinfo_left()\r
-         return transform (self.primary(lx), p, fli, lli)\r
+         local content = self.primary (lx)\r
+         --local lli = lx:lineinfo_left()\r
+         local fli, lli = content.lineinfo.first, content.lineinfo.last\r
+         return transform (content, p, fli, lli)\r
       else return false end\r
    end\r
 \r
index b2803040723b5f856a4be8722b8d756e87437ae5..af9780318e9dd8f867e50cdb73bf0c70f16912d9 100644 (file)
@@ -29,7 +29,10 @@ expr:add{ "`", adt, builder = fget(1) }
 local lambda_expr = gg.sequence{ 
    "|", func_params_content, "|", expr,
    builder= function (x) 
-      return {tag="Function", x[1], { {tag="Return", x[2] } } } end }
+      local li = x[2].lineinfo
+      return { tag="Function", x[1], 
+               { {tag="Return", x[2], lineinfo=li }, lineinfo=li } }
+   end }
 
 -- In an earlier version, lambda_expr took an expr_list rather than an expr
 -- after the 2nd bar. However, it happened to be much more of a burden than an