mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-08 21:55:26 +00:00
clean up soft-keyword transform
This commit is contained in:
parent
f1f31324d0
commit
591036785c
1 changed files with 14 additions and 22 deletions
|
@ -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(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue