]> git.lizzy.rs Git - metalua.git/commitdiff
improved messages clarity, following suggestions by D. Manura
authorFabien Fleutot <metalua@gmail.com>
Wed, 25 Feb 2009 16:10:39 +0000 (17:10 +0100)
committerFabien Fleutot <metalua@gmail.com>
Wed, 25 Feb 2009 16:10:39 +0000 (17:10 +0100)
src/compiler/gg.lua
src/compiler/metalua.mlua
src/compiler/mlp_expr.lua
src/compiler/mlp_misc.lua
src/compiler/mlp_stat.lua

index afab9965042afba47315f509078d52a46a15ffc4..67ed3a9598d9045649d42aea098776c1e1693cb7 100644 (file)
@@ -90,11 +90,11 @@ local function raw_parse_sequence (lx, p)
       e=p[i]
       if type(e) == "string" then 
          if not lx:is_keyword (lx:next(), e) then
-            parse_error (lx, "Keyword '%s' expected", e) end
+            parse_error (lx, "A keyword was expected, probably `%s'.", e) end
       elseif is_parser (e) then
          table.insert (r, e (lx)) 
       else 
-         gg.parse_error (lx,"Sequence `%s': element #%i is not a string "..
+         gg.parse_error (lx,"Sequence `%s': element #%i is neither a string "..
                          "nor a parser: %s", 
                          p.name, i, table.tostring(e))
       end
@@ -460,7 +460,7 @@ function expr (p)
          -- Check for non-associative operators, and complain if applicable. 
          -----------------------------------------
          elseif p2.assoc=="none" and p2.prec==prec then
-            parser_error (lx, "non-associative operator!")
+            parse_error (lx, "non-associative operator!")
 
          -----------------------------------------
          -- No infix operator suitable at that precedence
index 3c3564d0c37b167e47cf329f27cde1ae0ad92d63..203925f3ce851409ec63e3c4ab2ce1d010f6c7e6 100644 (file)
@@ -70,7 +70,7 @@ Compile and/or execute metalua programs. Parameters passed to the
 compiler should be prefixed with an option flag, hinting what must be
 done with them: take tham as file names to compile, as library names
 to load, as parameters passed to the running program... When option
-flags lack, metalua tries to adopt a "Do What I Mean" approach:
+flags are absent, metalua tries to adopt a "Do What I Mean" approach:
 
 - if no code (no library, no literal expression and no file) is
   specified, the first flag-less parameter is taken as a file name to
index 091f92e2c26bf381ec574d2ef5555e0704113a57..a0ded1eaab5d54b19a2a7e705e9d13093a4f30fc 100644 (file)
@@ -108,8 +108,16 @@ local _func_val = function (lx) return func_val(lx) end
 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
index c09483d47be4d335c238778429d9eee3103ec380..51d180eb632cc25e752e341a2dbb9e7a82b02214 100644 (file)
@@ -135,7 +135,7 @@ function id2string (id)
       -- That is, without sugar:
       return {tag="String",  {tag="Index", {tag="Splice", id[1] }, 
                                            {tag="Number", 1 } } }
-   else error ("Identifier expected: "..table.tostring(id)) end
+   else error ("Identifier expected: ".._G.table.tostring(id)) end
 end
 
 --------------------------------------------------------------------------------
index b959d96551bc3908b46d8c9faf7c1c874a35c451..282954edcb3231748a0d3ed305ea1808355208d0 100644 (file)
@@ -169,11 +169,18 @@ local function assign_or_call_stat_parser (lx)
    else 
       assert (#e > 0)
       if #e > 1 then 
-         gg.parse_error (lx, "comma is not a valid statement separator") end
+         gg.parse_error (lx, 
+            "comma is not a valid statement separator; statement can be "..
+            "separated by semicolons, or not separated at all") end
       if e[1].tag ~= "Call" and e[1].tag ~= "Invoke" then
-         gg.parse_error (lx, "This expression is of type '%s'; "..
-            "only function and method calls make valid statements", 
-            e[1].tag or "<list>")
+         local typename
+         if e[1].tag == 'Id' then typename = "an identifier"
+         elseif e[1].tag == 'Op' then typename = "an arithmetic operation"
+         else typename = "of type '"..(e[1].tag or "<list>".."'" end
+
+         gg.parse_error (lx, "This expression is " .. typename ..
+            "; only function and method call expressions "..
+            "can be used as statements");
       end
       return e[1]
    end