1
Fork 0

in which ! is suggested for erroneous identifier not

Impressing confused Python users with magical diagnostics is perhaps
worth this not-grossly-unreasonable (only 40ish lines) extra complexity
in the parser?

Thanks to Vadim Petrochenkov for guidance.

This resolves #46836.
This commit is contained in:
Zack M. Davis 2018-03-21 22:38:24 -07:00
parent 944c401736
commit ba0dd8eb02
4 changed files with 146 additions and 2 deletions

View file

@ -91,7 +91,7 @@ impl Lit {
}
}
fn ident_can_begin_expr(ident: ast::Ident, is_raw: bool) -> bool {
pub(crate) fn ident_can_begin_expr(ident: ast::Ident, is_raw: bool) -> bool {
let ident_token: Token = Ident(ident, is_raw);
!ident_token.is_reserved_ident() ||
@ -348,6 +348,15 @@ impl Token {
self.lifetime().is_some()
}
/// Returns `true` if the token is a identifier whose name is the given
/// string slice.
pub fn is_ident_named(&self, name: &str) -> bool {
match self.ident() {
Some((ident, _)) => ident.name.as_str() == name,
None => false
}
}
/// Returns `true` if the token is a documentation comment.
pub fn is_doc_comment(&self) -> bool {
match *self {