Skip to content

Commit

Permalink
bugfix: endless loop in if stmt error recovery (#630)
Browse files Browse the repository at this point in the history
  • Loading branch information
He1pa authored Jul 31, 2023
1 parent 17c4cbe commit 0b64afa
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions kclvm/parser/src/parser/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ impl<'a> Parser<'a> {

self.bump_token(open_tok);
loop {
if self.token.kind == TokenKind::Eof {
self.bump();
break;
}

if self.token.kind == close_tok {
self.bump_token(close_tok);
break;
Expand Down
1 change: 1 addition & 0 deletions kclvm/parser/src/tests/error_recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ parse_module_snapshot! { if_stmt_recovery_3, r#"if True: a = 1 else b = 2"#}
parse_module_snapshot! { if_stmt_recovery_4, r#"if True: else: b = 2"#}
parse_module_snapshot! { if_stmt_recovery_5, r#"if"#}
parse_module_snapshot! { if_stmt_recovery_6, r#"if else"#}
parse_module_snapshot! { if_stmt_recovery_7, r#"if True:"#}
parse_module_snapshot! { schema_stmt_recovery_0, r#"schema"#}
parse_module_snapshot! { schema_stmt_recovery_1, r#"schema A"#}
parse_module_snapshot! { schema_stmt_recovery_2, r#"schema A["#}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
source: parser/src/tests/error_recovery.rs
expression: "crate::tests::parsing_module_string(r#\"if True:\"#)"
---
Module {
filename: "",
pkg: "",
doc: "",
name: "",
body: [
Node {
node: If(
IfStmt {
body: [],
cond: Node {
node: NameConstantLit(
NameConstantLit {
value: True,
},
),
filename: "",
line: 1,
column: 3,
end_line: 1,
end_column: 7,
},
orelse: [],
},
),
filename: "",
line: 1,
column: 0,
end_line: 1,
end_column: 8,
},
],
comments: [],
}

0 comments on commit 0b64afa

Please sign in to comment.