1
0
mirror of https://github.com/Adorable-Catgirl/LuaComp.git synced 2024-11-23 02:18:06 +11:00

fixed escape related regression

This commit is contained in:
Sam Roxanne 2021-06-25 10:49:40 -05:00
parent ddd8de4d67
commit 42b2ee6676
6 changed files with 19 additions and 9 deletions

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
luacomp.lua
luacomp
build/*
build/*
*.out

View File

@ -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()

View File

@ -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)

1
tests/bad_include.lua Normal file
View File

@ -0,0 +1 @@
--#include "nonexistant"

2
tests/bad_string.lua Normal file
View File

@ -0,0 +1,2 @@
--#include "fuck
"

1
tests/bad_string_2.lua Normal file
View File

@ -0,0 +1 @@
--#include "wtf\"