]> git.lizzy.rs Git - metalua.git/commitdiff
Merge branch 'better-errors' into 0.5-branch
authorFabien Fleutot <fabien@MacFabien.home>
Sat, 28 Feb 2009 12:23:42 +0000 (13:23 +0100)
committerFabien Fleutot <fabien@MacFabien.home>
Sat, 28 Feb 2009 12:23:42 +0000 (13:23 +0100)
1  2 
src/compiler/mlp_expr.lua

index 213ccde22ec172ba6e4288b0691eefcf00b728bb,a0ded1eaab5d54b19a2a7e705e9d13093a4f30fc..7e98a30681b4269faa8d6c0beffd6106204266f9
@@@ -80,8 -80,7 +80,8 @@@ method_args = gg.multisequence
     name = "function argument(s)",
     { "{", table_content, "}" },
     { "(", func_args_content, ")", builder = fget(1) },
 -   default = function(lx) local r = opt_string(lx); return r and {r} or { } end }
 +   { "+{", quote_content, "}" }, 
 +   function(lx) local r = opt_string(lx); return r and {r} or { } end }
  
  --------------------------------------------------------------------------------
  -- [func_val] parses a function, from opening parameters parenthese to
@@@ -93,7 -92,7 +93,7 @@@
  -- definitions.
  --------------------------------------------------------------------------------
  func_params_content = gg.list{ name="function parameters",
 -   gg.multisequence{ { "...", builder = "Dots" }, default = id },
 +   gg.multisequence{ { "...", builder = "Dots" }, id },
     separators  = ",", terminators = {")", "|"} } 
  
  local _func_params_content = function (lx) return func_params_content(lx) end
@@@ -109,8 -108,16 +109,16 @@@ local _func_val = function (lx) return 
  function id_or_literal (lx)
     local a = lx:next()
     if a.tag~="Id" and a.tag~="String" and a.tag~="Number" then
-       gg.parse_error (lx, "Unexpected expr token %s",
-                       _G.table.tostring (a, 'nohash'))
+       local msg
+       if a.tag=='Eof' then
+          msg = "End of file reached when an expression was expected"
+       elseif a.tag=='Keyword' then
+          msg = "An expression was expected, and `"..a[1]..
+             "' can't start an expression"
+       else
+          msg = "Unexpected expr token " .. _G.table.tostring (a, 'nohash')
+       end
+       gg.parse_error (lx, msg)
     end
     return a
  end
@@@ -164,7 -171,7 +172,7 @@@ expr = gg.expr { name = "expression"
        { "false",                   builder = "False" },
        { "...",                     builder = "Dots" },
        table,
 -      default = id_or_literal },
 +      id_or_literal },
  
     infix = { name="expr infix op",
        { "+",  prec = 60, builder = opf2 "add"  },