Favor pattern-match over if-else when parsing assignment kinds
Equality on a union-type is potentially dangerous as the compiler won't complain if we add a new case that we don't cover. Reversing the assignment by yielding a `Token` for a given `AssignmentKind`. This way we can use a pattern-match that got us covered for future cases.
This commit is contained in:
parent
93e010b345
commit
44eb501d78
|
@ -9,23 +9,22 @@ use crate::{
|
|||
pub fn let_(
|
||||
r: Recursive<'_, Token, UntypedExpr, ParseError>,
|
||||
) -> impl Parser<Token, UntypedExpr, Error = ParseError> + '_ {
|
||||
assignment(r, Token::Let)
|
||||
assignment(r, ast::AssignmentKind::Let)
|
||||
}
|
||||
|
||||
pub fn expect(
|
||||
r: Recursive<'_, Token, UntypedExpr, ParseError>,
|
||||
) -> impl Parser<Token, UntypedExpr, Error = ParseError> + '_ {
|
||||
assignment(r, Token::Expect)
|
||||
assignment(r, ast::AssignmentKind::Expect)
|
||||
}
|
||||
|
||||
fn assignment(
|
||||
r: Recursive<'_, Token, UntypedExpr, ParseError>,
|
||||
keyword: Token,
|
||||
kind: ast::AssignmentKind,
|
||||
) -> impl Parser<Token, UntypedExpr, Error = ParseError> + '_ {
|
||||
let kind = if keyword == Token::Let {
|
||||
ast::AssignmentKind::Let
|
||||
} else {
|
||||
ast::AssignmentKind::Expect
|
||||
let keyword = match kind {
|
||||
ast::AssignmentKind::Let => Token::Let,
|
||||
ast::AssignmentKind::Expect => Token::Expect,
|
||||
};
|
||||
|
||||
just(keyword)
|
||||
|
|
Loading…
Reference in New Issue