1 require 'metalua.compiler'
3 -- Ecapsulates funcion mlc.luastring_to_ast in order to protect call and parse
4 -- error string when an error occurs.
6 -- @param src string containg Lua code to evaluate
7 -- @return AST of table type, as returned by mlc.luastring_to_ast. Contains an
8 -- error when AST generation fails
11 local status, result = pcall(mlc.luastring_to_ast, src)
12 if status then return result else
13 local line, column, offset = result:match '%(l.(%d+), c.(%d+), k.(%d+)%)'
14 local filename = result :match '^([^:]+)'
15 local msg = result :match 'line %d+, char %d+: (.-)\n'
16 local li = {line, column, offset, filename}
17 return {tag='Error', lineinfo={first=li, last=li}, msg}