clean up soft-keyword transform

This commit is contained in:
Jeong YunWon 2023-02-20 14:14:08 +09:00 committed by Charlie Marsh
parent f1f31324d0
commit 591036785c

View file

@ -56,17 +56,7 @@ where
// type hints.) // type hints.)
if matches!(tok, Tok::Match | Tok::Case) { if matches!(tok, Tok::Match | Tok::Case) {
if !self.start_of_line { if !self.start_of_line {
next = Some(Ok(( next = Some(Ok((*start, soft_to_name(tok), *end)));
*start,
Tok::Name {
name: if matches!(tok, Tok::Match) {
"match".to_string()
} else {
"case".to_string()
},
},
*end,
)));
} else { } else {
let mut par_count = 0; let mut par_count = 0;
let mut sqb_count = 0; let mut sqb_count = 0;
@ -92,17 +82,7 @@ where
first = false; first = false;
} }
if !seen_colon { if !seen_colon {
next = Some(Ok(( next = Some(Ok((*start, soft_to_name(tok), *end)));
*start,
Tok::Name {
name: if matches!(tok, Tok::Match) {
"match".to_string()
} else {
"case".to_string()
},
},
*end,
)));
} }
} }
} }
@ -124,3 +104,15 @@ where
next next
} }
} }
#[inline]
fn soft_to_name(tok: &Tok) -> Tok {
let name = match tok {
Tok::Match => "match",
Tok::Case => "case",
_ => unreachable!("other tokens never reach here"),
};
Tok::Name {
name: name.to_owned(),
}
}