@@ -15,6 +15,7 @@ local config = require("config");
1515local Ast = require (" prometheus.ast" );
1616local Enums = require (" prometheus.enums" );
1717local util = require (" prometheus.util" );
18+ local logger = require (" logger" );
1819
1920local lookupify = util .lookupify ;
2021local LuaVersion = Enums .LuaVersion ;
104105
105106function Unparser :unparse (ast )
106107 if (ast .kind ~= AstKind .TopNode ) then
107- error (" Unparser:unparse expects a TopNode as first argument" )
108+ logger : error (" Unparser:unparse expects a TopNode as first argument" )
108109 end
109110
110111 return self :unparseBlock (ast .body );
@@ -381,9 +382,26 @@ function Unparser:unparseStatement(statement, tabbing)
381382 code = code .. " ," .. self :optionalWhitespace () .. exprcode ;
382383 end
383384 end
384- -- While Statement
385+ 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 );
400+ else
401+ logger :error (string.format (" \" %s\" is not a valid unparseable statement in %s!" , statement .kind , self .luaVersion ));
402+ end
385403 else
386- error (string.format (" \" %s\" is not a valid unparseable statement" , statement .kind ));
404+ logger : error (string.format (" \" %s\" is not a valid unparseable statement in %s! " , statement .kind , self . luaVersion ));
387405 end
388406
389407 return self :tabs (tabbing , false ) .. code ;
@@ -839,7 +857,7 @@ function Unparser:unparseExpression(expression, tabbing)
839857 return code .. self :optionalWhitespace ((p and " ," or " " ) .. self :newline () .. self :tabs (tabbing )) .. " }" ;
840858 end
841859
842- error (string.format (" \" %s\" is not a valid unparseable expression" , expression .kind ));
860+ logger : error (string.format (" \" %s\" is not a valid unparseable expression" , expression .kind ));
843861end
844862
845863return Unparser
0 commit comments