Skip to content

Commit

Permalink
Have format: multiline use the python-style printing
Browse files Browse the repository at this point in the history
  • Loading branch information
FPtje committed Jan 1, 2024
1 parent b1bbdb7 commit 1c3b1a4
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 25 deletions.
19 changes: 16 additions & 3 deletions src/GLua/AG/PrettyPrint.ag
Original file line number Diff line number Diff line change
Expand Up @@ -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' <>
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
88 changes: 66 additions & 22 deletions tests/golden/data/output/issue-148.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down

0 comments on commit 1c3b1a4

Please sign in to comment.