]> git.lizzy.rs Git - metalua.git/blobdiff - src/compiler/mlc.mlua
fixed error position reporting in mlc.mlua
[metalua.git] / src / compiler / mlc.mlua
index 390b5aa331c60474623f64a986d61cf5477fcaa8..05a23f771744d423335caa984074b5074b76cf9b 100644 (file)
@@ -63,7 +63,7 @@ mlc.order = table.transpose{
          }
    end
    mlp.lexer:add 'POINT'
-   mlp.stat:add{ 'POINT', mlp.string, ',', mlp.string, builder = point_builder } 
+   mlp.stat:add{ 'POINT', mlp.string, ',', mlp.string, builder = point_builder }
 } -- end of meta-block
 
 function mlc.convert (x, src_fmt, dst_fmt, name)
@@ -89,7 +89,7 @@ function mlc.convert (x, src_fmt, dst_fmt, name)
 
    local status -- status = compilation success
    local lx=x
-   if SHOW_METABUGS
+   if mlc.metabugs
    -- If SHOW_METABUGS is true, errors should be attributed to a parser bug.
    then status, x = true, mlp.chunk (lx)
    -- If SHOW_METABUGS is false, errors should be attributed to an invalid entry.
@@ -102,14 +102,16 @@ function mlc.convert (x, src_fmt, dst_fmt, name)
    if not status and x then 
       -- x = error msg; get rid of ???
       x = x:strmatch "[^:]+:[0-9]+: (.*)" or x
-      printf("Parsing error in %s line %s, char %s: \n%s",
-             filename or "?", lx.line, lx.i, x)
+      local li = lx:lineinfo()
+      error(string.format("Parsing error in %s line %s, column %i, char %s: \n%s",
+                          name or "<nofilename>", li[1], li[2], li[3], x))
       return nil
    end
    
+   if x then x.source = name end -- TODO [EVE] store debug info in the special part of ast
+
    POINT 'ast', 'table' -- x is the AST
-   x = bytecode.metalua_compile(x) 
-   x.source = name
+   x = bytecode.metalua_compile(x, name or x.source) 
    POINT 'proto', 'table' 
    x = bytecode.dump_string (x)
    POINT 'luacstring', 'string' -- normally x is a bytecode dump