]> git.lizzy.rs Git - metalua.git/commitdiff
Merge branch 'better-errors' of git@github.com:fab13n/metalua into better-errors
authorFabien Fleutot <metalua@gmail.com>
Wed, 25 Feb 2009 16:11:14 +0000 (17:11 +0100)
committerFabien Fleutot <metalua@gmail.com>
Wed, 25 Feb 2009 16:11:14 +0000 (17:11 +0100)
1  2 
src/compiler/gg.lua
src/compiler/metalua.mlua
src/make.sh

diff --combined src/compiler/gg.lua
index 67ed3a9598d9045649d42aea098776c1e1693cb7,9a9ba2efc1a74e96df1297ec8828bb092084f8ac..0c0af636432d435bf52d6dae98c6911c5cb3a429
@@@ -53,8 -53,12 +53,12 @@@ function parser_metatable.__call (parse
        local li = lx:lineinfo_right() or { "?", "?", "?", "?" }
        local status, ast = pcall (parser.parse, parser, lx, ...)      
        if status then return ast else
+          -- Try to replace the gg.lua location, in the error msg, with
+          -- the place where the current parser started handling the
+          -- lexstream.
+          -- Since the error is rethrown, these places are stacked. 
           error (string.format ("%s\n - (l.%s, c.%s, k.%s) in parser %s", 
-                                ast:strmatch "gg.lua:%d+: (.*)" or ast,
+                                ast :strmatch "gg.lua:%d+: (.*)" or ast,
                                 li[1], li[2], li[3], parser.name or parser.kind))
        end
     end
@@@ -90,11 -94,11 +94,11 @@@ local function raw_parse_sequence (lx, 
        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
@@@ -201,10 -205,14 +205,14 @@@ function sequence (p
     -- Construction
     -------------------------------------------------------------------
     -- Try to build a proper name
-    if not p.name and type(p[1])=="string" then 
-       p.name = p[1].." ..." 
-       if type(p[#p])=="string" then p.name = p.name .. " " .. p[#p] end
-    else
+    if p.name then
+       -- don't touch existing name
+    elseif type(p[1])=="string" then -- find name based on 1st keyword
+       if #p==1 then p.name=p[1]
+       elseif type(p[#p])=="string" then
+          p.name = p[1] .. " ... " . p[#p]
+       else p.name = p[1] .. " ..." end
+    else -- can't find a decent name
        p.name = "<anonymous>"
     end
  
@@@ -460,7 -468,7 +468,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 203925f3ce851409ec63e3c4ab2ce1d010f6c7e6,b3bdf0325c501795df37ca7709fd50fa91a2fb59..c25b981762df49b632c6992cb925f051dd1f7655
@@@ -70,7 -70,7 +70,7 @@@ Compile and/or execute metalua programs
  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
@@@ -131,6 -131,7 +131,7 @@@ local function main (...
  
     -------------------------------------------------------------------
     -- Get ASTs from sources
+    mlc.metabugs = cfg.metabugs
     local last_file
     for x in values(chunks) do
        verb_print("Compiling %s", table.tostring(x))
           end
        end
        if not st then
-          printf ("Cannot compile %s: %s", table.tostring(x), ast or "no msg")
+          printf ("Cannot compile %s:\n%s", table.tostring(x), ast or "no msg")
           os.exit (AST_COMPILE_ERROR_NUMBER)
        end
        ast.origin = x
        end
     end
  
+    -- FIXME: canonize/check AST
     -------------------------------------------------------------------
     -- Insert runtime loader
     if cfg['no-runtime'] then
        table.insert(code, 1, +{require'metalua.runtime'})
     end
  
-    -- FIXME: check for failures
-    mlc.metabugs = cfg.metabugs
     local bytecode = mlc.luacstring_of_ast (code)
     code = nil
  
     -------------------------------------------------------------------
     -- Insert #!... command
     if cfg.sharpbang then
-       verb_print ("Adding sharp-bang directive %q", cfg.sharpbang)
-       if not cfg.sharpbang:strmatch'^#!' then cfg.sharpbang='#!'..cfg.sharpbang end
-       if not cfg.sharpbang:strmatch'\n$' then cfg.sharpbang=cfg.sharpbang..'\n' end
-       bytecode = cfg.sharpbang..bytecode
+       local shbang = cfg.sharpbang
+       verb_print ("Adding sharp-bang directive %q", shbang)
+       if not shbang :strmatch'^#!' then shbang = '#!' .. shbang end
+       if not shbang :strmatch'\n$' then shbang = shbang .. '\n' end
+       bytecode = shbang .. bytecode
     end
  
     -------------------------------------------------------------------
diff --combined src/make.sh
index 8de0e4fb18cfb0e012d347f1751dcd214aa584fb,242ec2b1389a8f0448d39d05ff0a3e1b59d8db36..b6e52ab6a35685807c2586bfc9f6ce438d462cae
@@@ -9,7 -9,7 +9,7 @@@ BASE=${PWD
  # Upon installation, everything will be moved to ${INSTALL_LIB} and ${INSTALL_BIN}
  
  if [ -z "${BUILD}" ]; then
 -  BUILD=/tmp/metalua-build
 +  BUILD= $(cd ../build; pwd)
  fi
  
  if [ -z "${BUILD_BIN}" ]; then
@@@ -38,6 -38,10 +38,10 @@@ LUAC=$(which luac
  
  # --- END OF USER-EDITABLE PART ---
  
+ if [ -z ${LUA}  ] ; then echo "Error: no lua interpreter found"; fi
+ if [ -z ${LUAC} ] ; then echo "Error: no lua compiler found"; fi
+ if [ -f ~/.metaluabuildrc ] ; then . ~/.metaluabuildrc; fi
  
  echo '*** Lua paths setup ***'
  
@@@ -48,7 -52,7 +52,7 @@@ echo '*** Create the distribution direc
  
  mkdir -p ${BUILD_BIN}
  mkdir -p ${BUILD_LIB}
- cp -R lib/* ${BUILD_LIB}/
+ cp -Rp lib/* ${BUILD_LIB}/
  # cp -R bin/* ${BUILD_BIN}/ # No binaries provided for unix (for now)
  
  echo '*** Generate a callable metalua shell script ***'
@@@ -101,12 -105,15 +105,15 @@@ cat > ${INSTALL_BIN}/metalua <<EO
  METALUA_LIB=${INSTALL_LIB}
  export LUA_PATH="?.luac;?.lua;\\\${METALUA_LIB}/?.luac;\\\${METALUA_LIB}/?.lua"
  export LUA_MPATH="?.mlua;\\\${METALUA_LIB}/?.mlua"
- exec ${LUA} \\\${METALUA_LIB}/metalua.luac "\\\$@"
+ exec ${LINEREADER} ${LUA} \\\${METALUA_LIB}/metalua.luac "\\\$@"
  EOF
  
  chmod a+x ${INSTALL_BIN}/metalua
  
  cp -R ${BUILD_LIB}/* ${INSTALL_LIB}/
+ echo "metalua libs installed in ${INSTALL_LIB};"
+ echo "metalua executable in ${INSTALL_BIN}."
  EOF2
  chmod a+x make-install.sh