Skip to content

Commit 75bf264

Browse files
committed
Improved whitespace removal
1 parent 9c68716 commit 75bf264

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

util/SQUISH.LUA

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ local function Squish(fileName)
123123
for _, token in ipairs(tokens) do
124124
if token.type == "code" then
125125
token.value = token.value:gsub("%s+", " ") -- Replace multiple spaces with a single space
126-
token.value = token.value:gsub("%s*([%(%){},;=%+%-%*/%^])%s*", "%1") -- Remove spaces around operators and punctuation
126+
token.value = token.value:gsub("%s*([%(%){}<>.,;=%+%-%*/%^])%s*", "%1") -- Remove spaces around operators and punctuation
127127
token.value = token.value:gsub("^%s+", "") -- Remove leading whitespace
128128
token.value = token.value:gsub("%s+$", "") -- Remove trailing whitespace
129129
end
@@ -142,7 +142,18 @@ local function Squish(fileName)
142142

143143
-- Concatenate data together
144144
for _, token in ipairs(tokens) do
145-
if token.type ~= "comment" then data = data .. token.value end
145+
if token.type ~= "comment" then
146+
local function pad()
147+
local last, start = #data > 1 and data:sub(-1, -1), #token.value > 1 and token.value:sub(1, 1)
148+
if (last and (last:find("%a") or last:find("%d")))
149+
and (start and (start:find("%a") or start:find("%d"))) then
150+
return " "
151+
end
152+
return ""
153+
end
154+
local sep = pad()
155+
data = data .. sep .. token.value
156+
end
146157
end
147158
print(data)
148159
end

0 commit comments

Comments
 (0)