diff --git a/.gitignore b/.gitignore index ddd2106..431598b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ luacomp.lua luacomp -build/* \ No newline at end of file +build/* +*.out \ No newline at end of file diff --git a/src/ast2.lua b/src/ast2.lua index 7e81c03..9e38f0e 100644 --- a/src/ast2.lua +++ b/src/ast2.lua @@ -87,7 +87,7 @@ do function ast.parser_error(str, err) local y, x = str:get_yx() --print(y, x) - lc_error(@[{_GENERATOR.fname}], string.format("%s(%d:%d): %s\n", str.file, y or 0, x or 0, err)) + lc_error("@[{_GENERATOR.fname}]", string.format("%s(%d:%d): %s\n", str.file, y or 0, x or 0, err)) end function ast.unescape(escaped_string) @@ -114,8 +114,9 @@ do function ast.remove_escapes(escaped_string) local i = 1 local out_string = "" - while i < #escaped_string do + while i <= #escaped_string do local c = escaped_string:sub(i,i) + --lc_warning(c, tostring(i).." "..#escaped_string) if (c == "\\") then i = i + 1 else @@ -123,17 +124,19 @@ do end i = i + 1 end + --lc_warning("debug", out_string) return out_string end function ast.back_escape_count(str, start) - local i=1 + local i=2 while str:peek(-i):sub(1,1) == "\\" do i = i + 1 if (str:tell()-i < start) then ast.error(str, "internal error") end end + --lc_warning(tostring(i), #str:peek(1-i).." "..str:peek(1-i)) return str:peek(1-i) end @@ -152,7 +155,7 @@ do end str:set(rpos) if str:peek(-1) == "\\" then - local parsed = ast.remove_escapes(ast.back_unescape(str)) + local parsed = ast.remove_escapes(ast.back_escape_count(str, spos)) if parsed:sub(#parsed) == "\'" then goto found_end end @@ -183,14 +186,16 @@ do end end str:set(rpos) - if str:peek(-1) == "\\" then - local parsed = ast.remove_escapes(ast.back_unescape(str)) + --lc_warning(str:peek(-2), "test") + if str:peek(-2):sub(1,1) == "\\" then + local parsed = ast.remove_escapes(ast.back_escape_count(str, spos)) if parsed:sub(#parsed) == "\"" then goto found_end end else goto found_end end + --str:set(rpos) end ::found_end:: local epos = str:tell() diff --git a/src/generator2.lua b/src/generator2.lua index f324b23..56e10f0 100644 --- a/src/generator2.lua +++ b/src/generator2.lua @@ -46,9 +46,9 @@ do fenv._G = fenv fenv._GENERATOR = env function fenv.call_directive(dname, ...) - if not directives[dname] then lc_error(@[{_GENERATOR.fname}], "invalid directive "..dname) end + if not directives[dname] then lc_error("@[{_GENERATOR.fname}]", "invalid directive "..dname) end local r, er = directives[dname](env, ...) - if not r then lc_error(@[{_GENERATOR.fname}], er) end + if not r then lc_error("@[{_GENERATOR.fname}]", er) end end function fenv.write_out(code) diff --git a/tests/bad_include.lua b/tests/bad_include.lua new file mode 100644 index 0000000..493958c --- /dev/null +++ b/tests/bad_include.lua @@ -0,0 +1 @@ +--#include "nonexistant" \ No newline at end of file diff --git a/tests/bad_string.lua b/tests/bad_string.lua new file mode 100644 index 0000000..cf1e2ec --- /dev/null +++ b/tests/bad_string.lua @@ -0,0 +1,2 @@ +--#include "fuck +" \ No newline at end of file diff --git a/tests/bad_string_2.lua b/tests/bad_string_2.lua new file mode 100644 index 0000000..6ba2a2b --- /dev/null +++ b/tests/bad_string_2.lua @@ -0,0 +1 @@ +--#include "wtf\" \ No newline at end of file