|
4941 | 4941 | local writeNode |
4942 | 4942 | local writeStatements |
4943 | 4943 |
|
4944 | | - -- lastOutput = "" | "alphanum" | "number" | "-" |
| 4944 | + -- lastOutput = "" | "alphanum" | "number" | "-" | "." |
4945 | 4945 |
|
4946 | 4946 | local function isNumberInRange(n, min, max) |
4947 | 4947 | return n ~= nil and n >= min and n <= max |
|
4970 | 4970 | end |
4971 | 4971 | local function writeNumber(buffer, pretty, n, lastOutput) |
4972 | 4972 | local nStr = formatNumber(n) |
4973 | | - if lastOutput == "-" and stringByte(nStr, 1) == 45--[[ "-" ]] then |
| 4973 | + if (lastOutput == "-" and stringByte(nStr, 1) == 45--[[ "-" ]]) or lastOutput == "." then |
4974 | 4974 | lastOutput = writeLua(buffer, " ", "") |
4975 | 4975 | else |
4976 | 4976 | ensureSpaceIfNotPretty(buffer, pretty, lastOutput, "alphanum","number") |
@@ -5160,7 +5160,12 @@ do |
5160 | 5160 |
|
5161 | 5161 | if binary.operator == ".." then ensureSpaceIfNotPretty(buffer, pretty, lastOutput, "number") end |
5162 | 5162 |
|
5163 | | - local nextOutput = ((binary.operator == "-" and "-") or (stringFind(binary.operator, "%w") and "alphanum") or ("")) |
| 5163 | + local nextOutput = ( |
| 5164 | + (binary.operator == "-" and "-" ) or |
| 5165 | + (binary.operator == ".." and "." ) or |
| 5166 | + (stringFind(binary.operator, "%w") and "alphanum") or |
| 5167 | + "" |
| 5168 | + ) |
5164 | 5169 | if nextOutput ~= "" then ensureSpaceIfNotPretty(buffer, pretty, lastOutput, nextOutput) end |
5165 | 5170 | lastOutput = writeLua(buffer, binary.operator, nextOutput) |
5166 | 5171 |
|
|
5193 | 5198 | elseif nodeType == "vararg" then |
5194 | 5199 | local vararg = node |
5195 | 5200 | if vararg.adjustToOne then lastOutput = writeLua(buffer, "(", "") end |
5196 | | - lastOutput = writeLua(buffer, "...", "") |
| 5201 | + if lastOutput == "." then lastOutput = writeLua(buffer, " ", ".") end |
| 5202 | + lastOutput = writeLua(buffer, "...", ".") |
5197 | 5203 | if vararg.adjustToOne then lastOutput = writeLua(buffer, ")", "") end |
5198 | 5204 |
|
5199 | 5205 | elseif nodeType == "literal" then |
@@ -5332,23 +5338,24 @@ do |
5332 | 5338 |
|
5333 | 5339 | elseif nodeType == "binary" then |
5334 | 5340 | local binary = node |
| 5341 | + local op = binary.operator |
5335 | 5342 |
|
5336 | 5343 | if not maySafelyOmitParens then lastOutput = writeLua(buffer, "(", "") end -- @Polish: Only output parentheses around child unaries/binaries if associativity requires it. |
5337 | 5344 |
|
5338 | | - if binary.operator == ".." or binary.operator == "and" or binary.operator == "or" then |
| 5345 | + if op == ".." or op == "and" or op == "or" or op == "+" or op == "*" or op == "&" or op == "|" then |
5339 | 5346 | local ok;ok, lastOutput = writeBinaryOperatorChain(buffer, pretty, indent, lastOutput, binary, nodeCb) |
5340 | 5347 | if not ok then return nil, lastOutput end |
5341 | 5348 |
|
5342 | 5349 | else |
5343 | 5350 | local ok;ok, lastOutput = writeNode(buffer, pretty, indent, lastOutput, binary.left, false, nodeCb) |
5344 | 5351 | if not ok then return nil, lastOutput end |
5345 | 5352 |
|
5346 | | - local operatorOutput = ((binary.operator == "-" and "-") or (stringFind(binary.operator, "%w") and "alphanum") or ("")) |
| 5353 | + local operatorOutput = ((op == "-" and "-") or (stringFind(op, "%w") and "alphanum") or ("")) |
5347 | 5354 |
|
5348 | 5355 | if pretty then lastOutput = writeLua(buffer, " ", "") end |
5349 | 5356 |
|
5350 | 5357 | if operatorOutput ~= "" then ensureSpaceIfNotPretty(buffer, pretty, lastOutput, operatorOutput) end |
5351 | | - lastOutput = writeLua(buffer, binary.operator, operatorOutput) |
| 5358 | + lastOutput = writeLua(buffer, op, operatorOutput) |
5352 | 5359 |
|
5353 | 5360 | if pretty then lastOutput = writeLua(buffer, " ", "") end |
5354 | 5361 |
|
|
0 commit comments