1
Fork 0

Replace some bool params with an enum

This commit is contained in:
Maybe Waffle 2022-09-15 20:27:23 +04:00
parent 38b0865248
commit d86f9cd464
7 changed files with 63 additions and 47 deletions

View file

@ -29,6 +29,7 @@ extern crate rustc_macros;
extern crate tracing;
pub mod util {
pub mod case;
pub mod classify;
pub mod comments;
pub mod literal;

View file

@ -5,6 +5,7 @@ pub use TokenKind::*;
use crate::ast;
use crate::ptr::P;
use crate::util::case::Case;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::sync::Lrc;
@ -618,10 +619,10 @@ impl Token {
self.is_non_raw_ident_where(|id| id.name == kw)
}
/// Returns `true` if the token is a given keyword, `kw` or if `case_insensitive` is true and this token is an identifier equal to `kw` ignoring the case.
pub fn is_keyword_case(&self, kw: Symbol, case_insensitive: bool) -> bool {
/// Returns `true` if the token is a given keyword, `kw` or if `case` is `Insensitive` and this token is an identifier equal to `kw` ignoring the case.
pub fn is_keyword_case(&self, kw: Symbol, case: Case) -> bool {
self.is_keyword(kw)
|| (case_insensitive
|| (case == Case::Insensitive
&& self.is_non_raw_ident_where(|id| {
id.name.as_str().to_lowercase() == kw.as_str().to_lowercase()
}))

View file

@ -0,0 +1,6 @@
/// Whatever to ignore case (`fn` vs `Fn` vs `FN`) or not. Used for recovering.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum Case {
Sensitive,
Insensitive,
}