diff options
| author | bors <bors@rust-lang.org> | 2014-05-02 07:06:50 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-05-02 07:06:50 -0700 |
| commit | b5d6b07370b665df6b54fa20e971e61041a233b0 (patch) | |
| tree | 4a43dbe1601f640ebb8bade6d67898c74bdea0e6 /src/libsyntax | |
| parent | e97d4e6c190764de1240c2e8a5ac253a60faac6b (diff) | |
| parent | 1ad0cba5e6a837fdebf5f5543d4b169929972705 (diff) | |
| download | rust-b5d6b07370b665df6b54fa20e971e61041a233b0.tar.gz rust-b5d6b07370b665df6b54fa20e971e61041a233b0.zip | |
auto merge of #13879 : huonw/rust/more-re, r=alexcrichton
Commits for details. This shouldn't change the generated code at all (except for switching to `LitBinary` from an explicit ExprVec of individual ExprLit bytes for `prefix_bytes`).
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/bytes.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/ext/concat.rs | 3 | ||||
| -rw-r--r-- | src/libsyntax/ext/format.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/quote.rs | 23 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 3 |
8 files changed, 35 insertions, 17 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 45f753d0e98..49617a44a86 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -653,7 +653,7 @@ pub type Lit = Spanned<Lit_>; pub enum Lit_ { LitStr(InternedString, StrStyle), LitBinary(Rc<Vec<u8> >), - LitChar(u32), + LitChar(char), LitInt(i64, IntTy), LitUint(u64, UintTy), LitIntUnsuffixed(i64), diff --git a/src/libsyntax/ext/bytes.rs b/src/libsyntax/ext/bytes.rs index f4680b27084..c6349d616ec 100644 --- a/src/libsyntax/ext/bytes.rs +++ b/src/libsyntax/ext/bytes.rs @@ -16,8 +16,6 @@ use ext::base::*; use ext::base; use ext::build::AstBuilder; -use std::char; - pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> ~base::MacResult { // Gather all argument expressions let exprs = match get_exprs_from_tts(cx, sp, tts) { @@ -59,7 +57,7 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> // char literal, push to vector expression ast::LitChar(v) => { - if char::from_u32(v).unwrap().is_ascii() { + if v.is_ascii() { bytes.push(cx.expr_u8(expr.span, v as u8)); } else { cx.span_err(expr.span, "non-ascii char literal in bytes!") diff --git a/src/libsyntax/ext/concat.rs b/src/libsyntax/ext/concat.rs index 123271c5b5e..fe7fa636e7d 100644 --- a/src/libsyntax/ext/concat.rs +++ b/src/libsyntax/ext/concat.rs @@ -14,7 +14,6 @@ use ext::base; use ext::build::AstBuilder; use parse::token; -use std::char; use std::strbuf::StrBuf; pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, @@ -35,7 +34,7 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, accumulator.push_str(s.get()); } ast::LitChar(c) => { - accumulator.push_char(char::from_u32(c).unwrap()); + accumulator.push_char(c); } ast::LitInt(i, _) | ast::LitIntUnsuffixed(i) => { accumulator.push_str(format!("{}", i)); diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index 84021f6362b..df79b105444 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -561,7 +561,7 @@ impl<'a, 'b> Context<'a, 'b> { // Translate the format let fill = match arg.format.fill { Some(c) => c, None => ' ' }; - let fill = self.ecx.expr_lit(sp, ast::LitChar(fill as u32)); + let fill = self.ecx.expr_lit(sp, ast::LitChar(fill)); let align = match arg.format.align { parse::AlignLeft => { self.ecx.path_global(sp, self.parsepath("AlignLeft")) diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 68b0ef40b16..fc7f7722354 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -125,6 +125,26 @@ pub mod rt { } } + impl ToSource for () { + fn to_source(&self) -> ~str { + "()".to_owned() + } + } + + impl ToSource for bool { + fn to_source(&self) -> ~str { + let lit = dummy_spanned(ast::LitBool(*self)); + pprust::lit_to_str(&lit) + } + } + + impl ToSource for char { + fn to_source(&self) -> ~str { + let lit = dummy_spanned(ast::LitChar(*self)); + pprust::lit_to_str(&lit) + } + } + impl ToSource for int { fn to_source(&self) -> ~str { let lit = dummy_spanned(ast::LitInt(*self as i64, ast::TyI)); @@ -227,6 +247,9 @@ pub mod rt { impl_to_tokens!(@ast::Expr) impl_to_tokens!(ast::Block) impl_to_tokens_self!(&'a str) + impl_to_tokens!(()) + impl_to_tokens!(char) + impl_to_tokens!(bool) impl_to_tokens!(int) impl_to_tokens!(i8) impl_to_tokens!(i16) 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('\''); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 7ea4dcbf28a..afb66ab8317 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -26,7 +26,6 @@ use print::pp::{Breaks, Consistent, Inconsistent, eof}; use print::pp; use std::cast; -use std::char; use std::io::{IoResult, MemWriter}; use std::io; use std::rc::Rc; @@ -2196,7 +2195,7 @@ impl<'a> State<'a> { ast::LitStr(ref st, style) => self.print_string(st.get(), style), ast::LitChar(ch) => { let mut res = StrBuf::from_str("'"); - char::from_u32(ch).unwrap().escape_default(|c| res.push_char(c)); + ch.escape_default(|c| res.push_char(c)); res.push_char('\''); word(&mut self.s, res.into_owned()) } |
