From 591036785c470da54e004eaf88ed9701ef56c7e3 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Mon, 20 Feb 2023 14:14:08 +0900 Subject: [PATCH] clean up soft-keyword transform --- parser/src/soft_keywords.rs | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/parser/src/soft_keywords.rs b/parser/src/soft_keywords.rs index b2c16f9..d5eaa29 100644 --- a/parser/src/soft_keywords.rs +++ b/parser/src/soft_keywords.rs @@ -56,17 +56,7 @@ where // type hints.) if matches!(tok, Tok::Match | Tok::Case) { if !self.start_of_line { - next = Some(Ok(( - *start, - Tok::Name { - name: if matches!(tok, Tok::Match) { - "match".to_string() - } else { - "case".to_string() - }, - }, - *end, - ))); + next = Some(Ok((*start, soft_to_name(tok), *end))); } else { let mut par_count = 0; let mut sqb_count = 0; @@ -92,17 +82,7 @@ where first = false; } if !seen_colon { - next = Some(Ok(( - *start, - Tok::Name { - name: if matches!(tok, Tok::Match) { - "match".to_string() - } else { - "case".to_string() - }, - }, - *end, - ))); + next = Some(Ok((*start, soft_to_name(tok), *end))); } } } @@ -124,3 +104,15 @@ where 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(), + } +}