From 3dfcd95c6f02dc6eaf48292a1a8613727cd53765 Mon Sep 17 00:00:00 2001 From: Jean-Patrick Guerrero Date: Thu, 23 Jun 2022 14:32:59 +0200 Subject: [PATCH] Tweak preprocessor to add -- decrement --- init.lua | 2 +- src/{compress.lua => compression.lua} | 0 src/preprocessor.lua | 4 ++++ util/luacheck.lua | 12 ++++++++---- 4 files changed, 13 insertions(+), 5 deletions(-) rename src/{compress.lua => compression.lua} (100%) diff --git a/init.lua b/init.lua index 544075b..2215e5e 100644 --- a/init.lua +++ b/init.lua @@ -63,7 +63,7 @@ i3 = { caches = lf"/src/caches.lua", callbacks = lf"/src/callbacks.lua", common = lf"/src/common.lua", - compress = lf"/src/compress.lua", + compress = lf"/src/compression.lua", detached = lf"/src/detached_inv.lua", fields = lf"/src/fields.lua", groups = lf"/src/groups.lua", diff --git a/src/compress.lua b/src/compression.lua similarity index 100% rename from src/compress.lua rename to src/compression.lua diff --git a/src/preprocessor.lua b/src/preprocessor.lua index 406c9cd..a75ad39 100644 --- a/src/preprocessor.lua +++ b/src/preprocessor.lua @@ -51,6 +51,10 @@ local function compile(data) end end) + data = data:gsub("([%w_]+)-%-\n", function(a) + return fmt("%s = %s - 1", a, a) + end) + for op, func in pairs(operators) do data = data:gsub("(" .. var .. "+)%s?" .. op .. "%s?(" .. var .. "*)", func) end diff --git a/util/luacheck.lua b/util/luacheck.lua index 552c4bd..289bd5d 100755 --- a/util/luacheck.lua +++ b/util/luacheck.lua @@ -35,7 +35,7 @@ local files = { "caches", "callbacks", "common", - "compress", + "compression", "detached_inv", "fields", "groups", @@ -91,6 +91,10 @@ local function compile(data) end end) + data = data:gsub("([%w_]+)-%-\n", function(a) + return fmt("%s = %s - 1", a, a) + end) + for op, func in pairs(operators) do data = data:gsub("(" .. var .. "+)%s?" .. op .. "%s?(" .. var .. "*)", func) end @@ -123,7 +127,7 @@ for _, p in ipairs(files) do end end - local _file = io.open(path:match("(.*)%.") .. ".l", "w") + local _file = io.open(path:match("(.*)%.") .. ".lc", "w") _file:write(data) _file:close() end @@ -133,5 +137,5 @@ end exec "luacheck ../init.lua" exec "luacheck ../src/preprocessor.lua" -exec "luacheck ../src/*.l" -exec "rm ../src/*.l" +exec "luacheck ../src/*.lc" +exec "rm ../src/*.lc"