Skip to content

Commit

Permalink
fix: ast printer on comment and lambda nodes because of the parser is… (
Browse files Browse the repository at this point in the history
kcl-lang#36)

fix: ast printer on comment and lambda nodes because of the parser issue.
  • Loading branch information
Peefy authored May 25, 2022
1 parent 329fdaa commit 94b97ef
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 20 deletions.
2 changes: 1 addition & 1 deletion kclvm/parser/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl<'a> Parser<'a> {
// slice_suffix
operand = self.parse_subscript_expr(operand)
}
_ => {}
_ => break operand,
}
}
_ => break operand,
Expand Down
6 changes: 3 additions & 3 deletions kclvm/tools/src/printer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ impl<'p> Printer<'p> {
}
}
if let Some(index) = index {
let mut count = index;
while count > 0 {
let mut count = index as isize;
while count >= 0 {
match self.comments.pop_front() {
Some(comment) => {
self.writeln(&comment.node.text);
Expand Down Expand Up @@ -246,7 +246,7 @@ impl<'p> Printer<'p> {
/// Print AST to string
pub fn print_ast_module(module: &ast::Module) -> String {
let mut printer = Printer::default();
printer.walk_module(module);
printer.write_module(module);
printer.out
}

Expand Down
10 changes: 2 additions & 8 deletions kclvm/tools/src/printer/test_data/comment.output
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,9 @@ appConfiguration = AppConfiguration {
disk: "50Gi"
memory: "12Gi"
}
labels: {
key: {
key: 12
}
}
labels: {key: {key: 12}}
# Comment Six
mainContainer: Main {
name: "kusion_override"
}
mainContainer: Main {name: "kusion_override"}
# Comment Seven
# Comment Eight
overQuota: True
Expand Down
1 change: 0 additions & 1 deletion kclvm/tools/src/printer/test_data/lambda.input
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
sumFunc1 = lambda x, y {
z = x + y
z + x

}
sumFunc2 = lambda x, y = 1 {
x + y
Expand Down
8 changes: 4 additions & 4 deletions kclvm/tools/src/printer/test_data/lambda.output
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
sumFunc1 = lambda x, y {
z = x + y
z + x

}
sumFunc2 = lambda x, y = 1 {
x + y

}
sumFunc3 = lambda x = 1, y = 1 {
x + y

}
sumFunc4 = lambda x: int = 1, y: int = 1 -> int {
x + y

}
x0 = sumFunc1(1, 2)
x1 = sumFunc1(2, 3)
Expand Down
6 changes: 3 additions & 3 deletions kclvm/tools/src/printer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use pretty_assertions::assert_eq;

const FILE_INPUT_SUFFIX: &str = ".input";
const FILE_OUTPUT_SUFFIX: &str = ".output";
const TEST_CASES: &[&'static str; 10] = &[
const TEST_CASES: &[&'static str; 12] = &[
"arguments",
"empty",
"codelayout",
"collection_if",
// "comment",
"comment",
"index_sign",
"joined_str",
// "lambda",
"lambda",
"quant",
"rule",
"type_alias",
Expand Down

0 comments on commit 94b97ef

Please sign in to comment.