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
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
-- 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
-- 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
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
-------------------------------------------------------------------
-- 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
-------------------------------------------------------------------
# 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
# --- 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 ***'
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 ***'
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