Skip to content

Commit

Permalink
Merge tag 'v0.2'
Browse files Browse the repository at this point in the history
v0.2
  • Loading branch information
hugheaves committed Dec 15, 2023
2 parents dbc4587 + 9591ae4 commit 867a107
Show file tree
Hide file tree
Showing 6 changed files with 879 additions and 2 deletions.
27 changes: 26 additions & 1 deletion internal/formatter/formattingvisitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,13 @@ func (v *FormattingVisitor) VisitChildStatements(ctx *parser.ChildStatementsCont
}
v.formatter.unindent()
v.Visit(ctx.R_CURLY())
v.formatter.endLine()
nextToken := v.tokenStream.Get(ctx.R_CURLY().GetSymbol().GetTokenIndex() + 1)
if nextToken.GetTokenType() != parser.OpenSCADLexerELSE {
v.formatter.endLine()
} else {
v.formatter.printSpace()
}

return nil
}

Expand Down Expand Up @@ -301,6 +307,25 @@ func (v *FormattingVisitor) VisitLetStatement(ctx *parser.LetStatementContext) i
return v.VisitChildren(ctx)
}

func (v *FormattingVisitor) VisitIfElseStatement(ctx *parser.IfElseStatementContext) interface{} {
return v.VisitChildren(ctx)
}

func (v *FormattingVisitor) VisitIfStatement(ctx *parser.IfStatementContext) interface{} {
v.Visit(ctx.IF())
v.formatter.printSpace()
v.Visit(ctx.L_PAREN())
v.Visit(ctx.Expr())
v.Visit(ctx.R_PAREN())
return nil
}

func (v *FormattingVisitor) VisitElseStatement(ctx *parser.ElseStatementContext) interface{} {
v.VisitChildren(ctx)
v.formatter.printSpace()
return nil
}

// processCommentTokens processes any comment tokens in the token stream starting at
// index "startIndex".
func (v *FormattingVisitor) processCommentTokens(startIndex int, printDeferred bool) {
Expand Down
2 changes: 1 addition & 1 deletion internal/formatter/testdata/comment_test.scad.expected
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module foo(argument1) {

echo(i);

if(i % 2 == 0) {
if (i % 2 == 0) {
echo("i is even");
echo("which is good");
}
Expand Down
10 changes: 10 additions & 0 deletions internal/formatter/testdata/if-statement.scad
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if (part == "adapter") {
adapter();
} else if (part == "back_weight") {
back_weight();
} else if (part == "retaining_clip") {
retaining_clip();
} else if (part == "side_weight") {
side_weight();
translate([0,20,0]) mirror([1,0,0]) side_weight();
}
12 changes: 12 additions & 0 deletions internal/formatter/testdata/if-statement.scad.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
if (part == "adapter") {
adapter();
} else if (part == "back_weight") {
back_weight();
} else if (part == "retaining_clip") {
retaining_clip();
} else if (part == "side_weight") {
side_weight();
translate([0, 20, 0])
mirror([1, 0, 0])
side_weight();
}
Loading

0 comments on commit 867a107

Please sign in to comment.