Skip to content

Commit

Permalink
refactor: remove config/list if item newline format
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Sep 11, 2024
1 parent ded5e87 commit 1644547
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 7 deletions.
6 changes: 4 additions & 2 deletions kclvm/ast_pretty/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,9 @@ impl<'p, 'ctx> MutSelfTypedResultWalker<'ctx> for Printer<'p> {
|expr| self.expr(expr),
list_if_item_expr.exprs
);
self.write_indentation(Indentation::DedentWithNewline);
self.write_indentation(Indentation::Dedent);
if let Some(orelse) = &list_if_item_expr.orelse {
self.write_newline();
match &orelse.node {
ast::Expr::List(list_expr) => {
self.write("else:");
Expand Down Expand Up @@ -571,8 +572,9 @@ impl<'p, 'ctx> MutSelfTypedResultWalker<'ctx> for Printer<'p> {
|entry: &ast::NodeRef<ast::ConfigEntry>| self.write_entry(entry),
config_if_entry_expr.items
);
self.write_indentation(Indentation::DedentWithNewline);
self.write_indentation(Indentation::Dedent);
if let Some(orelse) = &config_if_entry_expr.orelse {
self.write_newline();
match &orelse.node {
ast::Expr::Config(config_expr) => {
self.write("else:");
Expand Down
26 changes: 25 additions & 1 deletion kclvm/ast_pretty/src/test_data/codelayout.input
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,28 @@ c =3

d = 4
e = 5
}
}
config_if_entry = {
if True: a = 1
elif False:
b = 2
else:
c = 3
d = 4
**e
if a > 3:
e = 5
elif a < 2:
f =6
if True:
g = 7
}
list_if_item = [
if True: 1
elif False:
2
else:
3, 4
*[5, 6]
if False: 2
]
28 changes: 28 additions & 0 deletions kclvm/ast_pretty/src/test_data/codelayout.output
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,31 @@ f = lambda {
d = 4
e = 5
}
config_if_entry = {
if True:
a = 1
elif False:
b = 2
else:
c = 3
d = 4
**e
if a > 3:
e = 5
elif a < 2:
f = 6
if True:
g = 7
}
list_if_item = [
if True:
1
elif False:
2
else:
3
4
*[5, 6]
if False:
2
]
4 changes: 0 additions & 4 deletions kclvm/ast_pretty/src/test_data/orelse.output
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,15 @@ d = [
else:
if True:
2

if True:
3

]
e = {
if True:
a = 1
else:
if True:
b = 2

if True:
c = 3

}

0 comments on commit 1644547

Please sign in to comment.