From 734403280469ea4138411be20c3ac8fa1fce3e2c Mon Sep 17 00:00:00 2001 From: Peefy Date: Wed, 11 Sep 2024 19:52:15 +0800 Subject: [PATCH] refactor: remove config/list if item newline format (#1643) Signed-off-by: peefy --- kclvm/ast_pretty/src/node.rs | 6 ++-- .../ast_pretty/src/test_data/codelayout.input | 26 ++++++++++++++++- .../src/test_data/codelayout.output | 28 +++++++++++++++++++ kclvm/ast_pretty/src/test_data/orelse.output | 4 --- 4 files changed, 57 insertions(+), 7 deletions(-) diff --git a/kclvm/ast_pretty/src/node.rs b/kclvm/ast_pretty/src/node.rs index 2dba0f828..30b8efbc9 100644 --- a/kclvm/ast_pretty/src/node.rs +++ b/kclvm/ast_pretty/src/node.rs @@ -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:"); @@ -571,8 +572,9 @@ impl<'p, 'ctx> MutSelfTypedResultWalker<'ctx> for Printer<'p> { |entry: &ast::NodeRef| 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:"); diff --git a/kclvm/ast_pretty/src/test_data/codelayout.input b/kclvm/ast_pretty/src/test_data/codelayout.input index a94beede7..674296717 100644 --- a/kclvm/ast_pretty/src/test_data/codelayout.input +++ b/kclvm/ast_pretty/src/test_data/codelayout.input @@ -143,4 +143,28 @@ c =3 d = 4 e = 5 -} \ No newline at end of file +} +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 +] \ No newline at end of file diff --git a/kclvm/ast_pretty/src/test_data/codelayout.output b/kclvm/ast_pretty/src/test_data/codelayout.output index 81eab93ce..152b2e8bd 100644 --- a/kclvm/ast_pretty/src/test_data/codelayout.output +++ b/kclvm/ast_pretty/src/test_data/codelayout.output @@ -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 +] diff --git a/kclvm/ast_pretty/src/test_data/orelse.output b/kclvm/ast_pretty/src/test_data/orelse.output index 613d7ec74..04de3aa85 100644 --- a/kclvm/ast_pretty/src/test_data/orelse.output +++ b/kclvm/ast_pretty/src/test_data/orelse.output @@ -13,10 +13,8 @@ d = [ else: if True: 2 - if True: 3 - ] e = { if True: @@ -24,8 +22,6 @@ e = { else: if True: b = 2 - if True: c = 3 - }