From 1c3b1a4385447478cff9101775df1617d1c9f142 Mon Sep 17 00:00:00 2001 From: Falco Peijnenburg Date: Sun, 31 Dec 2023 16:09:53 +0100 Subject: [PATCH] Have `format: multiline` use the python-style printing --- src/GLua/AG/PrettyPrint.ag | 19 +++++- tests/golden/data/output/issue-148.lua | 88 +++++++++++++++++++------- 2 files changed, 82 insertions(+), 25 deletions(-) diff --git a/src/GLua/AG/PrettyPrint.ag b/src/GLua/AG/PrettyPrint.ag index e389aff..cdf4383 100644 --- a/src/GLua/AG/PrettyPrint.ag +++ b/src/GLua/AG/PrettyPrint.ag @@ -419,7 +419,8 @@ sem MStat sem MExprList | Cons - lhs.pretty = + lhs.pretty = if @lhs.forceMultiline then @loc.prettyForcedMultiline else @loc.prettyNotForcedMultiline + loc.prettyNotForcedMultiline = -- If there are comments before the line, render the this part as multiline (if @loc.startsWithNewline then zchr '\n' <> @@ -434,6 +435,12 @@ sem MExprList indent @lhs.ppconf (@lhs.indent + 1) @tl.pretty else @tl.pretty) + loc.prettyForcedMultiline = + renderMLComments @lhs.ppconf @lhs.indent (fst @loc.commentsBeforeLine) + $+$ indent @lhs.ppconf (@lhs.indent) @hd.pretty + <> @loc.comma + <-> renderSLComments @lhs.ppconf @lhs.indent (fst @loc.commentsAfter) + $+$ @tl.pretty loc.comma = if @tl.isLast then empty @@ -1073,10 +1080,16 @@ sem Expr sem Args | ListArgs - lhs.pretty = parens @lhs.ppconf @loc.emptyParams @args.pretty + lhs.pretty = + if @lhs.forceMultiline then + zchr '(' $+$ + @args.pretty $+$ + indent @lhs.ppconf @lhs.indent (zchr ')') + else + parens @lhs.ppconf @loc.emptyParams @args.pretty lhs.isMultiline = @args.isMultiline loc.emptyParams = toEmpty $ null @args.copy - args.indent = @lhs.indent + args.indent = if @lhs.forceMultiline then @lhs.indent + 1 else @lhs.indent args.someElementsInListAreMultiline = False | TableArg lhs.pretty = if @arg.isMultiline then @loc.prettyMulti else @loc.prettySingle diff --git a/tests/golden/data/output/issue-148.lua b/tests/golden/data/output/issue-148.lua index 4c10d47..d2b8e64 100644 --- a/tests/golden/data/output/issue-148.lua +++ b/tests/golden/data/output/issue-148.lua @@ -14,21 +14,43 @@ end -- format: multiline local normalSounds = { - Sound("honk1.wav"), - Sound("honk2.wav"), - Sound("honk3.wav"), - Sound("honk4.wav") + Sound( + "honk1.wav" + ), + Sound( + "honk2.wav" + ), + Sound( + "honk3.wav" + ), + Sound( + "honk4.wav" + ) } -- format: multiline -render.DrawBeam(self.StartPos - norm, -- Start - self.EndPos, -- End - 64 * (1 - self.Life), -- Width - texcoord, -- Start tex coord - texcoord + self.Length / 128, -- End tex coord +render.DrawBeam( + self.StartPos - norm, -- Start + self.EndPos, -- End + 64 * (1 - self.Life), -- Width + texcoord, -- Start tex coord + texcoord + self.Length / 128, -- End tex coord Color( - -- Color (optional) - Lerp(self.Life, 255, 50), Lerp(self.Life, 100, 50), 255, 255)) + -- Color (optional) + Lerp( + self.Life, + 255, + 50 + ), + Lerp( + self.Life, + 100, + 50 + ), + 255, + 255 + ) +) -- format: multiline function a() @@ -42,23 +64,45 @@ end --[[ format: multiline ]] local normalSounds = { - Sound("honk1.wav"), - Sound("honk2.wav"), - Sound("honk3.wav"), - Sound("honk4.wav") + Sound( + "honk1.wav" + ), + Sound( + "honk2.wav" + ), + Sound( + "honk3.wav" + ), + Sound( + "honk4.wav" + ) } --[[ format: multiline ]] -render.DrawBeam(self.StartPos - norm, -- Start - self.EndPos, -- End - 64 * (1 - self.Life), -- Width - texcoord, -- Start tex coord - texcoord + self.Length / 128, -- End tex coord +render.DrawBeam( + self.StartPos - norm, -- Start + self.EndPos, -- End + 64 * (1 - self.Life), -- Width + texcoord, -- Start tex coord + texcoord + self.Length / 128, -- End tex coord Color( - -- Color (optional) - Lerp(self.Life, 255, 50), Lerp(self.Life, 100, 50), 255, 255)) + -- Color (optional) + Lerp( + self.Life, + 255, + 50 + ), + Lerp( + self.Life, + 100, + 50 + ), + 255, + 255 + ) +) local normalSounds = {Sound("honk1.wav"), Sound("honk2.wav"), Sound("honk3.wav"), Sound("honk4.wav")} render.DrawBeam(self.StartPos - norm, -- Start