Add new literal type Err

This commit is contained in:
Yuki Okushi 2019-01-16 09:27:43 +09:00
parent e2f221c759
commit d19294feee
5 changed files with 6 additions and 0 deletions

View file

@ -329,6 +329,7 @@ fn hash_token<'a, 'gcx, W: StableHasherResult>(
match *lit {
token::Lit::Byte(val) |
token::Lit::Char(val) |
token::Lit::Err(val) |
token::Lit::Integer(val) |
token::Lit::Float(val) |
token::Lit::Str_(val) |

View file

@ -646,6 +646,7 @@ fn expr_mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> P<ast::Expr> {
token::Literal(token::Byte(i), suf) => return mk_lit!("Byte", suf, i),
token::Literal(token::Char(i), suf) => return mk_lit!("Char", suf, i),
token::Literal(token::Err(i), suf) => return mk_lit!("Err", suf, i),
token::Literal(token::Integer(i), suf) => return mk_lit!("Integer", suf, i),
token::Literal(token::Float(i), suf) => return mk_lit!("Float", suf, i),
token::Literal(token::Str_(i), suf) => return mk_lit!("Str_", suf, i),

View file

@ -466,6 +466,7 @@ crate fn lit_token(lit: token::Lit, suf: Option<Symbol>, diag: Option<(Span, &Ha
match lit {
token::Byte(i) => (true, Some(LitKind::Byte(byte_lit(&i.as_str()).0))),
token::Char(i) => (true, Some(LitKind::Char(char_lit(&i.as_str(), diag).0))),
token::Err(i) => (true, Some(LitKind::Char(char_lit(&i.as_str(), diag).0))),
// There are some valid suffixes for integer and float literals,
// so all the handling is done internally.

View file

@ -60,6 +60,7 @@ impl DelimToken {
pub enum Lit {
Byte(ast::Name),
Char(ast::Name),
Err(ast::Name),
Integer(ast::Name),
Float(ast::Name),
Str_(ast::Name),
@ -73,6 +74,7 @@ impl Lit {
match *self {
Byte(_) => "byte literal",
Char(_) => "char literal",
Err(_) => "error literal",
Integer(_) => "integer literal",
Float(_) => "float literal",
Str_(_) | StrRaw(..) => "string literal",

View file

@ -224,6 +224,7 @@ pub fn token_to_string(tok: &Token) -> String {
let mut out = match lit {
token::Byte(b) => format!("b'{}'", b),
token::Char(c) => format!("'{}'", c),
token::Err(c) => format!("'{}'", c),
token::Float(c) |
token::Integer(c) => c.to_string(),
token::Str_(s) => format!("\"{}\"", s),