diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2014-05-01 23:35:06 +1000 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2014-05-02 22:54:55 +1000 |
| commit | 5c424ba34ad8b45cfba4619832d23b0278ede696 (patch) | |
| tree | bd4d05b358352d1b306044a04545386bf3ded77e /src/libsyntax/parse | |
| parent | 239557de6de72748a5c7604081b202d53f7d9ac9 (diff) | |
| download | rust-5c424ba34ad8b45cfba4619832d23b0278ede696.tar.gz rust-5c424ba34ad8b45cfba4619832d23b0278ede696.zip | |
syntax: store char literals/tokens as `char`s rather than u32s.
Clearly storing them as `char` is semantically nicer, but this also fixes a bug whereby `quote_expr!(cx, 'a')` wasn't working, because the code created by quotation was not matching the actual AST definitions.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/lexer.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 5 |
2 files changed, 7 insertions, 8 deletions
diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 992d289b4e9..c1f6e21f923 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -874,7 +874,7 @@ fn next_token_inner(rdr: &mut StringReader) -> token::Token { "unterminated character constant".to_owned()); } bump(rdr); // advance curr past token - return token::LIT_CHAR(c2 as u32); + return token::LIT_CHAR(c2); } '"' => { let mut accum_str = StrBuf::new(); @@ -1097,17 +1097,17 @@ mod test { #[test] fn character_a() { assert_eq!(setup(&mk_sh(), "'a'".to_owned()).next_token().tok, - token::LIT_CHAR('a' as u32)); + token::LIT_CHAR('a')); } #[test] fn character_space() { assert_eq!(setup(&mk_sh(), "' '".to_owned()).next_token().tok, - token::LIT_CHAR(' ' as u32)); + token::LIT_CHAR(' ')); } #[test] fn character_escaped() { assert_eq!(setup(&mk_sh(), "'\\n'".to_owned()).next_token().tok, - token::LIT_CHAR('\n' as u32)); + token::LIT_CHAR('\n')); } #[test] fn lifetime_name() { @@ -1128,7 +1128,7 @@ mod test { #[test] fn nested_block_comments() { assert_eq!(setup(&mk_sh(), "/* /* */ */'a'".to_owned()).next_token().tok, - token::LIT_CHAR('a' as u32)); + token::LIT_CHAR('a')); } } diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 611ce7cc527..519a7d141d3 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -18,7 +18,6 @@ use util::interner; use serialize::{Decodable, Decoder, Encodable, Encoder}; use std::cast; -use std::char; use std::fmt; use std::local_data; use std::path::BytesContainer; @@ -81,7 +80,7 @@ pub enum Token { DOLLAR, /* Literals */ - LIT_CHAR(u32), + LIT_CHAR(char), LIT_INT(i64, ast::IntTy), LIT_UINT(u64, ast::UintTy), LIT_INT_UNSUFFIXED(i64), @@ -195,7 +194,7 @@ pub fn to_str(t: &Token) -> ~str { /* Literals */ LIT_CHAR(c) => { let mut res = StrBuf::from_str("'"); - char::from_u32(c).unwrap().escape_default(|c| { + c.escape_default(|c| { res.push_char(c); }); res.push_char('\''); |
