Skip to content

Commit 5990884

Browse files
authored
Merge pull request #141 from SpinnySpiwal/master
Update unparser.lua
2 parents 3e4619e + a8a612a commit 5990884

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

src/prometheus/unparser.lua

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -383,25 +383,22 @@ function Unparser:unparseStatement(statement, tabbing)
383383
end
384384
end
385385
elseif self.luaVersion == LuaVersion.LuaU then
386-
if statement.kind == AstKind.CompoundAddStatement then
387-
code = code .. self:unparseExpression(statement.lhs, tabbing) .. self:optionalWhitespace() .. "+=" .. self:optionalWhitespace() .. self:unparseExpression(statement.rhs, tabbing);
388-
elseif statement.kind == AstKind.CompoundSubStatement then
389-
code = code .. self:unparseExpression(statement.lhs, tabbing) .. self:optionalWhitespace() .. "-=" .. self:optionalWhitespace() .. self:unparseExpression(statement.rhs, tabbing);
390-
elseif statement.kind == AstKind.CompoundMulStatement then
391-
code = code .. self:unparseExpression(statement.lhs, tabbing) .. self:optionalWhitespace() .. "*=" .. self:optionalWhitespace() .. self:unparseExpression(statement.rhs, tabbing);
392-
elseif statement.kind == AstKind.CompoundDivStatement then
393-
code = code .. self:unparseExpression(statement.lhs, tabbing) .. self:optionalWhitespace() .. "/=" .. self:optionalWhitespace() .. self:unparseExpression(statement.rhs, tabbing);
394-
elseif statement.kind == AstKind.CompoundModStatement then
395-
code = code .. self:unparseExpression(statement.lhs, tabbing) .. self:optionalWhitespace() .. "%=" .. self:optionalWhitespace() .. self:unparseExpression(statement.rhs, tabbing);
396-
elseif statement.kind == AstKind.CompoundPowStatement then
397-
code = code .. self:unparseExpression(statement.lhs, tabbing) .. self:optionalWhitespace() .. "^=" .. self:optionalWhitespace() .. self:unparseExpression(statement.rhs, tabbing);
398-
elseif statement.kind == AstKind.CompoundConcatStatement then
399-
code = code .. self:unparseExpression(statement.lhs, tabbing) .. self:optionalWhitespace() .. "..=" .. self:optionalWhitespace() .. self:unparseExpression(statement.rhs, tabbing);
386+
local compoundOperators = {
387+
[AstKind.CompoundAddStatement] = "+=",
388+
[AstKind.CompoundSubStatement] = "-=",
389+
[AstKind.CompoundMulStatement] = "*=",
390+
[AstKind.CompoundDivStatement] = "/=",
391+
[AstKind.CompoundModStatement] = "%=",
392+
[AstKind.CompoundPowStatement] = "^=",
393+
[AstKind.CompoundConcatStatement] = "..=",
394+
}
395+
396+
local operator = compoundOperators[statement.kind]
397+
if operator then
398+
code = code .. self:unparseExpression(statement.lhs, tabbing) .. self:optionalWhitespace() .. operator .. self:optionalWhitespace() .. self:unparseExpression(statement.rhs, tabbing)
400399
else
401-
logger:error(string.format("\"%s\" is not a valid unparseable statement in %s!", statement.kind, self.luaVersion));
400+
logger:error(string.format("\"%s\" is not a valid unparseable statement in %s!", statement.kind, self.luaVersion))
402401
end
403-
else
404-
logger:error(string.format("\"%s\" is not a valid unparseable statement in %s!", statement.kind, self.luaVersion));
405402
end
406403

407404
return self:tabs(tabbing, false) .. code;

0 commit comments

Comments
 (0)