Skip to content

Commit

Permalink
Further improvements to auto-formatter #100
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed May 10, 2023
1 parent e9e2b2d commit 99121a4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
17 changes: 15 additions & 2 deletions src/main/java/intellij_awk/AwkFormattingModelBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,23 @@ private static SpacingBuilder createSpaceBuilder(CodeStyleSettings settings) {
.spaces(1)
.after(TokenSet.create(LPAREN, LBRACKET))
.none()
.before(TokenSet.create(RPAREN, RBRACKET))
.before(TokenSet.create(RPAREN, RBRACKET, LBRACKET))
.none()
.after(NOT)
.none();
.none()
.between(TokenSet.create(FOR, IF, WHILE), LPAREN)
.spaces(1)
.between(DO, STATEMENT) // do {
.spaces(1)
.between(STATEMENT, WHILE) // } while
.spaces(1)
.between(STATEMENT, ELSE) // } else
.spaces(1)
.between(ELSE, STATEMENT) // else if
.spaces(1)
.between(RPAREN, STATEMENT) // ) {
.spaces(1)
;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/test/testData/auto_format/file5After.awk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BEGIN {
for(i = 0; i < 10; i++)
for (i = 0; i < 10; i++)
print i
}
2 changes: 1 addition & 1 deletion src/test/testData/auto_format/file8After.awk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BEGIN {
while (1)
for(i = 1; i < 10; i++)
for (i = 1; i < 10; i++)
if (i % 2 == 0)
print "even"
else
Expand Down
1 change: 1 addition & 0 deletions src/test/testData/auto_format/issue100.awk
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@ include "x"
BEGIN {
for( i=0;i<7;i++ )print i
if(1){}else if(2){}else{}
while(1){}
do{}while(1)
print - 7
Expand Down
1 change: 1 addition & 0 deletions src/test/testData/auto_format/issue100After.awk
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@include "x"
BEGIN {
for (i = 0; i < 7; i++) print i
if (1) {} else if (2) {} else {}
while (1) {}
do {} while (1)
print -7
Expand Down

0 comments on commit 99121a4

Please sign in to comment.