Skip to content

Commit

Permalink
parser(error): detects compexpr in if statement
Browse files Browse the repository at this point in the history
  • Loading branch information
chanbengz committed Dec 8, 2024
1 parent 126c1ef commit e4eaf2e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/parser/src/grammar.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,21 @@ OpenExpr: tree::Expr = {
)
)
},

// if ( error ) { ... }
"if" "(" <l:@L> <cond:CompExpr> ")" <body:Expr> => {
let error = ErrorRecovery {
error: ParseError::User {
error: LexicalError::StatementError(Span {
source: source.to_string(),
start: l - 1,
end: l + 1
}, "Must be condition".to_string())
},
dropped_tokens: Vec::new(),
};
errors.push(error);
tree::Expr::Error
},
// if error Condition ) { ... }
"if" <l:@L> ! <r:@R> CondExpr ")" Expr => {
let error = ErrorRecovery {
Expand Down

0 comments on commit e4eaf2e

Please sign in to comment.