add unknown token
This commit is contained in:
parent
b5e35b128e
commit
58ac81a60f
7 changed files with 10 additions and 6 deletions
|
@ -363,7 +363,8 @@ impl<'a> HashStable<StableHashingContext<'a>> for token::TokenKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
token::DocComment(val) |
|
token::DocComment(val) |
|
||||||
token::Shebang(val) => val.hash_stable(hcx, hasher),
|
token::Shebang(val) |
|
||||||
|
token::Unknown(val) => val.hash_stable(hcx, hasher),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -237,7 +237,7 @@ impl<'a> Classifier<'a> {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
},
|
},
|
||||||
|
|
||||||
token::Whitespace => Class::None,
|
token::Whitespace | token::Unknown(..) => Class::None,
|
||||||
token::Comment => Class::Comment,
|
token::Comment => Class::Comment,
|
||||||
token::DocComment(..) => Class::DocComment,
|
token::DocComment(..) => Class::DocComment,
|
||||||
|
|
||||||
|
|
|
@ -184,7 +184,7 @@ impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec<Self>)>
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenDelim(..) | CloseDelim(..) => unreachable!(),
|
OpenDelim(..) | CloseDelim(..) => unreachable!(),
|
||||||
Whitespace | Comment | Shebang(..) | Eof => unreachable!(),
|
Whitespace | Comment | Shebang(..) | Unknown(..) | Eof => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -354,7 +354,7 @@ impl<'a> StringReader<'a> {
|
||||||
// tokens like `<<` from `rustc_lexer`, and then add fancier error recovery to it,
|
// tokens like `<<` from `rustc_lexer`, and then add fancier error recovery to it,
|
||||||
// as there will be less overall work to do this way.
|
// as there will be less overall work to do this way.
|
||||||
let token = unicode_chars::check_for_substitution(self, start, c, &mut err)
|
let token = unicode_chars::check_for_substitution(self, start, c, &mut err)
|
||||||
.unwrap_or(token::Whitespace);
|
.unwrap_or_else(|| token::Unknown(self.symbol_from(start)));
|
||||||
err.emit();
|
err.emit();
|
||||||
token
|
token
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,7 +217,7 @@ impl<'a> TokenTreesReader<'a> {
|
||||||
loop {
|
loop {
|
||||||
let token = self.string_reader.next_token();
|
let token = self.string_reader.next_token();
|
||||||
match token.kind {
|
match token.kind {
|
||||||
token::Whitespace | token::Comment | token::Shebang(_) => {
|
token::Whitespace | token::Comment | token::Shebang(_) | token::Unknown(_) => {
|
||||||
self.joint_to_prev = NonJoint;
|
self.joint_to_prev = NonJoint;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
|
|
@ -255,6 +255,8 @@ pub enum TokenKind {
|
||||||
/// A comment.
|
/// A comment.
|
||||||
Comment,
|
Comment,
|
||||||
Shebang(ast::Name),
|
Shebang(ast::Name),
|
||||||
|
/// A completely invalid token which should be skipped.
|
||||||
|
Unknown(ast::Name),
|
||||||
|
|
||||||
Eof,
|
Eof,
|
||||||
}
|
}
|
||||||
|
@ -603,7 +605,7 @@ impl Token {
|
||||||
DotDotEq | Comma | Semi | ModSep | RArrow | LArrow | FatArrow | Pound | Dollar |
|
DotDotEq | Comma | Semi | ModSep | RArrow | LArrow | FatArrow | Pound | Dollar |
|
||||||
Question | OpenDelim(..) | CloseDelim(..) |
|
Question | OpenDelim(..) | CloseDelim(..) |
|
||||||
Literal(..) | Ident(..) | Lifetime(..) | Interpolated(..) | DocComment(..) |
|
Literal(..) | Ident(..) | Lifetime(..) | Interpolated(..) | DocComment(..) |
|
||||||
Whitespace | Comment | Shebang(..) | Eof => return None,
|
Whitespace | Comment | Shebang(..) | Unknown(..) | Eof => return None,
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(Token::new(kind, self.span.to(joint.span)))
|
Some(Token::new(kind, self.span.to(joint.span)))
|
||||||
|
|
|
@ -288,6 +288,7 @@ fn token_kind_to_string_ext(tok: &TokenKind, convert_dollar_crate: Option<Span>)
|
||||||
token::Whitespace => " ".to_string(),
|
token::Whitespace => " ".to_string(),
|
||||||
token::Comment => "/* */".to_string(),
|
token::Comment => "/* */".to_string(),
|
||||||
token::Shebang(s) => format!("/* shebang: {}*/", s),
|
token::Shebang(s) => format!("/* shebang: {}*/", s),
|
||||||
|
token::Unknown(s) => s.to_string(),
|
||||||
|
|
||||||
token::Interpolated(ref nt) => nonterminal_to_string(nt),
|
token::Interpolated(ref nt) => nonterminal_to_string(nt),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue