Skip to main content

syntax/
utils.rs

1//! A set of utils methods to reuse on other abstraction levels
2
3use crate::SyntaxKind;
4use rustc_lexer;
5
6#[inline]
7/// Checks that the name is an identifier.
8/// This also means that it is not a strict keyword.
9/// But it may be a weak keyword.
10pub fn is_identifier(name: &str, edition: parser::Edition) -> bool {
11    if rustc_lexer::is_ident(name) {
12        if let Some(syntax_kind) = SyntaxKind::from_keyword(name, edition)
13            && syntax_kind.is_strict_keyword(edition)
14        {
15            false
16        } else {
17            true
18        }
19    } else {
20        false
21    }
22}
23
24#[inline]
25pub fn is_raw_identifier(name: &str, edition: parser::Edition) -> bool {
26    let is_keyword = SyntaxKind::from_keyword(name, edition).is_some();
27    is_keyword && !matches!(name, "self" | "crate" | "super" | "Self")
28}