Skip to content

Commit

Permalink
bugfix: If stmt position error
Browse files Browse the repository at this point in the history
  • Loading branch information
He1pa committed Apr 3, 2023
1 parent 5ee0fec commit f627748
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 11 deletions.
6 changes: 3 additions & 3 deletions kclvm/parser/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ impl<'a> Parser<'a> {
/// Syntax:
/// test: if_expr | simple_expr
pub(crate) fn parse_expr(&mut self) -> NodeRef<Expr> {
let token = self.token;
let operand = self.parse_simple_expr();

// try if expr
if self.token.is_keyword(kw::If) {
return self.parse_if_expr(operand);
return self.parse_if_expr(operand, token);
}

operand
Expand Down Expand Up @@ -199,8 +200,7 @@ impl<'a> Parser<'a> {
/// Syntax:
/// if_expr: simple_expr IF simple_expr ELSE test
/// test: if_expr | simple_expr
fn parse_if_expr(&mut self, body: NodeRef<Expr>) -> NodeRef<Expr> {
let token = self.token;
fn parse_if_expr(&mut self, body: NodeRef<Expr>, token: kclvm_ast::token::Token) -> NodeRef<Expr> {
if self.token.is_keyword(kw::If) {
self.bump();
let cond = self.parse_simple_expr();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: parser/src/tests/error_recovery.rs
assertion_line: 79
expression: "crate::tests::parsing_expr_string(r#\"1 if\"#)"
---
Node {
Expand Down Expand Up @@ -45,7 +44,7 @@ Node {
),
filename: "",
line: 1,
column: 2,
column: 0,
end_line: 1,
end_column: 4,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: parser/src/tests/error_recovery.rs
assertion_line: 80
expression: "crate::tests::parsing_expr_string(r#\"1 if\"#)"
---
Node {
Expand Down Expand Up @@ -45,7 +44,7 @@ Node {
),
filename: "",
line: 1,
column: 2,
column: 0,
end_line: 1,
end_column: 4,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: parser/src/tests/error_recovery.rs
assertion_line: 81
expression: "crate::tests::parsing_expr_string(r#\"1 if True\"#)"
---
Node {
Expand Down Expand Up @@ -47,7 +46,7 @@ Node {
),
filename: "",
line: 1,
column: 2,
column: 0,
end_line: 1,
end_column: 9,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: parser/src/tests/error_recovery.rs
assertion_line: 82
expression: "crate::tests::parsing_expr_string(r#\"1 if True else\"#)"
---
Node {
Expand Down Expand Up @@ -47,7 +46,7 @@ Node {
),
filename: "",
line: 1,
column: 2,
column: 0,
end_line: 1,
end_column: 14,
}
Expand Down

0 comments on commit f627748

Please sign in to comment.