Skip to content

Commit fa38e9f

Browse files
youknowonecharliermarsh
authored andcommitted
clean up soft-keyword transform
1 parent 382df8e commit fa38e9f

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

compiler/parser/src/soft_keywords.rs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,7 @@ where
5656
// type hints.)
5757
if matches!(tok, Tok::Match | Tok::Case) {
5858
if !self.start_of_line {
59-
next = Some(Ok((
60-
*start,
61-
Tok::Name {
62-
name: if matches!(tok, Tok::Match) {
63-
"match".to_string()
64-
} else {
65-
"case".to_string()
66-
},
67-
},
68-
*end,
69-
)));
59+
next = Some(Ok((*start, soft_to_name(tok), *end)));
7060
} else {
7161
let mut par_count = 0;
7262
let mut sqb_count = 0;
@@ -92,17 +82,7 @@ where
9282
first = false;
9383
}
9484
if !seen_colon {
95-
next = Some(Ok((
96-
*start,
97-
Tok::Name {
98-
name: if matches!(tok, Tok::Match) {
99-
"match".to_string()
100-
} else {
101-
"case".to_string()
102-
},
103-
},
104-
*end,
105-
)));
85+
next = Some(Ok((*start, soft_to_name(tok), *end)));
10686
}
10787
}
10888
}
@@ -124,3 +104,15 @@ where
124104
next
125105
}
126106
}
107+
108+
#[inline]
109+
fn soft_to_name(tok: &Tok) -> Tok {
110+
let name = match tok {
111+
Tok::Match => "match",
112+
Tok::Case => "case",
113+
_ => unreachable!("other tokens never reach here"),
114+
};
115+
Tok::Name {
116+
name: name.to_owned(),
117+
}
118+
}

0 commit comments

Comments
 (0)