1
0
Fork 0
mirror of https://github.com/Reuh/candran.git synced 2025-10-27 17:59:30 +00:00

don't add line mappin comments ad infinitum

This commit is contained in:
Étienne Fildadut 2017-08-23 19:22:18 +02:00
parent c0f7934d92
commit 9b809fc8a4
2 changed files with 11 additions and 5 deletions

View file

@ -38,12 +38,15 @@ function candran.preprocess(input, options={})
i += 1 i += 1
if line:match("^%s*#") and not line:match("^#!") then -- exclude shebang if line:match("^%s*#") and not line:match("^#!") then -- exclude shebang
preprocessor ..= line:gsub("^%s*#", "") preprocessor ..= line:gsub("^%s*#", "")
elseif options.mapLines then else
preprocessor ..= ("write(%q)"):format(line:sub(1, -2) .. " -- "..options.chunkname..":" .. i) .. "\n" local l = line:sub(1, -2)
if options.mapLines and not l:match("%-%- (.-)%:(%d+)$") then
preprocessor ..= ("write(%q)"):format(l .. " -- "..options.chunkname..":" .. i) .. "\n"
else else
preprocessor ..= ("write(%q)"):format(line:sub(1, -2)) .. "\n" preprocessor ..= ("write(%q)"):format(line:sub(1, -2)) .. "\n"
end end
end end
end
preprocessor ..= "return output" preprocessor ..= "return output"
-- make preprocessor environement -- make preprocessor environement

View file

@ -1922,14 +1922,17 @@ for line in (input .. "\
i = i + 1 i = i + 1
if line:match("^%s*#") and not line:match("^#!") then if line:match("^%s*#") and not line:match("^#!") then
preprocessor = preprocessor .. line:gsub("^%s*#", "") preprocessor = preprocessor .. line:gsub("^%s*#", "")
elseif options["mapLines"] then else
preprocessor = preprocessor .. ("write(%q)"):format(line:sub(1, - 2) .. " -- " .. options["chunkname"] .. ":" .. i) .. "\ local l = line:sub(1, - 2)
if options["mapLines"] and not l:match("%-%- (.-)%:(%d+)$") then
preprocessor = preprocessor .. ("write(%q)"):format(l .. " -- " .. options["chunkname"] .. ":" .. i) .. "\
" "
else else
preprocessor = preprocessor .. ("write(%q)"):format(line:sub(1, - 2)) .. "\ preprocessor = preprocessor .. ("write(%q)"):format(line:sub(1, - 2)) .. "\
" "
end end
end end
end
preprocessor = preprocessor .. "return output" preprocessor = preprocessor .. "return output"
local env = util["merge"](_G, options) local env = util["merge"](_G, options)
env["candran"] = candran env["candran"] = candran