1
Fork 0

Use consistent terminology for byte string literals

Avoid confusion with binary integer literals and binary operator expressions in libsyntax
This commit is contained in:
Vadim Petrochenkov 2015-09-03 10:54:53 +03:00
parent 69c3b39d0d
commit 405c616eaf
25 changed files with 69 additions and 69 deletions

View file

@ -13,8 +13,8 @@ tokens {
BINOPEQ, AT, DOT, DOTDOT, DOTDOTDOT, COMMA, SEMI, COLON, BINOPEQ, AT, DOT, DOTDOT, DOTDOTDOT, COMMA, SEMI, COLON,
MOD_SEP, RARROW, FAT_ARROW, LPAREN, RPAREN, LBRACKET, RBRACKET, MOD_SEP, RARROW, FAT_ARROW, LPAREN, RPAREN, LBRACKET, RBRACKET,
LBRACE, RBRACE, POUND, DOLLAR, UNDERSCORE, LIT_CHAR, LIT_BYTE, LBRACE, RBRACE, POUND, DOLLAR, UNDERSCORE, LIT_CHAR, LIT_BYTE,
LIT_INTEGER, LIT_FLOAT, LIT_STR, LIT_STR_RAW, LIT_BINARY, LIT_INTEGER, LIT_FLOAT, LIT_STR, LIT_STR_RAW, LIT_BYTE_STR,
LIT_BINARY_RAW, QUESTION, IDENT, LIFETIME, WHITESPACE, DOC_COMMENT, LIT_BYTE_STR_RAW, QUESTION, IDENT, LIFETIME, WHITESPACE, DOC_COMMENT,
COMMENT, SHEBANG, UTF8_BOM COMMENT, SHEBANG, UTF8_BOM
} }
@ -148,8 +148,8 @@ LIT_STR
: '"' ('\\\n' | '\\\r\n' | '\\' CHAR_ESCAPE | .)*? '"' SUFFIX? : '"' ('\\\n' | '\\\r\n' | '\\' CHAR_ESCAPE | .)*? '"' SUFFIX?
; ;
LIT_BINARY : 'b' LIT_STR ; LIT_BYTE_STR : 'b' LIT_STR ;
LIT_BINARY_RAW : 'b' LIT_STR_RAW ; LIT_BYTE_STR_RAW : 'b' LIT_STR_RAW ;
/* this is a bit messy */ /* this is a bit messy */

View file

@ -200,7 +200,7 @@ while { return WHILE; }
<ltorchar><<EOF>> { BEGIN(INITIAL); return -1; } <ltorchar><<EOF>> { BEGIN(INITIAL); return -1; }
b\x22 { BEGIN(bytestr); yymore(); } b\x22 { BEGIN(bytestr); yymore(); }
<bytestr>\x22 { BEGIN(suffix); return LIT_BINARY; } <bytestr>\x22 { BEGIN(suffix); return LIT_BYTE_STR; }
<bytestr><<EOF>> { return -1; } <bytestr><<EOF>> { return -1; }
<bytestr>\\[n\nrt\\\x27\x220] { yymore(); } <bytestr>\\[n\nrt\\\x27\x220] { yymore(); }
@ -210,7 +210,7 @@ b\x22 { BEGIN(bytestr); yymore(); }
<bytestr>(.|\n) { yymore(); } <bytestr>(.|\n) { yymore(); }
br\x22 { BEGIN(rawbytestr_nohash); yymore(); } br\x22 { BEGIN(rawbytestr_nohash); yymore(); }
<rawbytestr_nohash>\x22 { BEGIN(suffix); return LIT_BINARY_RAW; } <rawbytestr_nohash>\x22 { BEGIN(suffix); return LIT_BYTE_STR_RAW; }
<rawbytestr_nohash>(.|\n) { yymore(); } <rawbytestr_nohash>(.|\n) { yymore(); }
<rawbytestr_nohash><<EOF>> { return -1; } <rawbytestr_nohash><<EOF>> { return -1; }
@ -228,7 +228,7 @@ br/# {
end_hashes++; end_hashes++;
if (end_hashes == num_hashes) { if (end_hashes == num_hashes) {
BEGIN(INITIAL); BEGIN(INITIAL);
return LIT_BINARY_RAW; return LIT_BYTE_STR_RAW;
} }
} }
yymore(); yymore();
@ -237,7 +237,7 @@ br/# {
end_hashes = 1; end_hashes = 1;
if (end_hashes == num_hashes) { if (end_hashes == num_hashes) {
BEGIN(INITIAL); BEGIN(INITIAL);
return LIT_BINARY_RAW; return LIT_BYTE_STR_RAW;
} }
yymore(); yymore();
} }

View file

@ -52,8 +52,8 @@ extern char *yytext;
%token LIT_FLOAT %token LIT_FLOAT
%token LIT_STR %token LIT_STR
%token LIT_STR_RAW %token LIT_STR_RAW
%token LIT_BINARY %token LIT_BYTE_STR
%token LIT_BINARY_RAW %token LIT_BYTE_STR_RAW
%token IDENT %token IDENT
%token UNDERSCORE %token UNDERSCORE
%token LIFETIME %token LIFETIME
@ -1772,8 +1772,8 @@ lit
str str
: LIT_STR { $$ = mk_node("LitStr", 1, mk_atom(yytext), mk_atom("CookedStr")); } : LIT_STR { $$ = mk_node("LitStr", 1, mk_atom(yytext), mk_atom("CookedStr")); }
| LIT_STR_RAW { $$ = mk_node("LitStr", 1, mk_atom(yytext), mk_atom("RawStr")); } | LIT_STR_RAW { $$ = mk_node("LitStr", 1, mk_atom(yytext), mk_atom("RawStr")); }
| LIT_BINARY { $$ = mk_node("LitBinary", 1, mk_atom(yytext), mk_atom("BinaryStr")); } | LIT_BYTE_STR { $$ = mk_node("LitByteStr", 1, mk_atom(yytext), mk_atom("ByteStr")); }
| LIT_BINARY_RAW { $$ = mk_node("LitBinary", 1, mk_atom(yytext), mk_atom("RawBinaryStr")); } | LIT_BYTE_STR_RAW { $$ = mk_node("LitByteStr", 1, mk_atom(yytext), mk_atom("RawByteStr")); }
; ;
maybe_ident maybe_ident
@ -1815,8 +1815,8 @@ unpaired_token
| LIT_FLOAT { $$ = mk_atom(yytext); } | LIT_FLOAT { $$ = mk_atom(yytext); }
| LIT_STR { $$ = mk_atom(yytext); } | LIT_STR { $$ = mk_atom(yytext); }
| LIT_STR_RAW { $$ = mk_atom(yytext); } | LIT_STR_RAW { $$ = mk_atom(yytext); }
| LIT_BINARY { $$ = mk_atom(yytext); } | LIT_BYTE_STR { $$ = mk_atom(yytext); }
| LIT_BINARY_RAW { $$ = mk_atom(yytext); } | LIT_BYTE_STR_RAW { $$ = mk_atom(yytext); }
| IDENT { $$ = mk_atom(yytext); } | IDENT { $$ = mk_atom(yytext); }
| UNDERSCORE { $$ = mk_atom(yytext); } | UNDERSCORE { $$ = mk_atom(yytext); }
| LIFETIME { $$ = mk_atom(yytext); } | LIFETIME { $$ = mk_atom(yytext); }

View file

@ -38,8 +38,8 @@ enum Token {
LIT_FLOAT, LIT_FLOAT,
LIT_STR, LIT_STR,
LIT_STR_RAW, LIT_STR_RAW,
LIT_BINARY, LIT_BYTE_STR,
LIT_BINARY_RAW, LIT_BYTE_STR_RAW,
IDENT, IDENT,
UNDERSCORE, UNDERSCORE,
LIFETIME, LIFETIME,

View file

@ -107,8 +107,8 @@ fn parse_token_list(file: &str) -> HashMap<String, token::Token> {
"OR" => token::BinOp(token::Or), "OR" => token::BinOp(token::Or),
"GT" => token::Gt, "GT" => token::Gt,
"LE" => token::Le, "LE" => token::Le,
"LIT_BINARY" => token::Literal(token::Binary(Name(0)), None), "LIT_BYTE_STR" => token::Literal(token::ByteStr(Name(0)), None),
"LIT_BINARY_RAW" => token::Literal(token::BinaryRaw(Name(0), 0), None), "LIT_BYTE_STR_RAW" => token::Literal(token::ByteStrRaw(Name(0), 0), None),
"QUESTION" => token::Question, "QUESTION" => token::Question,
"SHEBANG" => token::Shebang(Name(0)), "SHEBANG" => token::Shebang(Name(0)),
_ => continue, _ => continue,
@ -137,8 +137,8 @@ fn str_to_binop(s: &str) -> token::BinOpToken {
} }
} }
/// Assuming a string/binary literal, strip out the leading/trailing /// Assuming a string/byte string literal, strip out the leading/trailing
/// hashes and surrounding quotes/raw/binary prefix. /// hashes and surrounding quotes/raw/byte prefix.
fn fix(mut lit: &str) -> ast::Name { fn fix(mut lit: &str) -> ast::Name {
if lit.char_at(0) == 'r' { if lit.char_at(0) == 'r' {
if lit.char_at(1) == 'b' { if lit.char_at(1) == 'b' {
@ -205,8 +205,8 @@ fn parse_antlr_token(s: &str, tokens: &HashMap<String, token::Token>, surrogate_
token::DocComment(..) => token::DocComment(nm), token::DocComment(..) => token::DocComment(nm),
token::Literal(token::Integer(..), n) => token::Literal(token::Integer(nm), n), token::Literal(token::Integer(..), n) => token::Literal(token::Integer(nm), n),
token::Literal(token::Float(..), n) => token::Literal(token::Float(nm), n), token::Literal(token::Float(..), n) => token::Literal(token::Float(nm), n),
token::Literal(token::Binary(..), n) => token::Literal(token::Binary(nm), n), token::Literal(token::ByteStr(..), n) => token::Literal(token::ByteStr(nm), n),
token::Literal(token::BinaryRaw(..), n) => token::Literal(token::BinaryRaw(fix(content), token::Literal(token::ByteStrRaw(..), n) => token::Literal(token::ByteStrRaw(fix(content),
count(content)), n), count(content)), n),
token::Ident(..) => token::Ident(ast::Ident { name: nm, ctxt: 0 }, token::Ident(..) => token::Ident(ast::Ident { name: nm, ctxt: 0 },
token::ModName), token::ModName),
@ -340,8 +340,8 @@ fn main() {
token::Literal(token::Float(..), _), token::Literal(token::Float(..), _),
token::Literal(token::Str_(..), _), token::Literal(token::Str_(..), _),
token::Literal(token::StrRaw(..), _), token::Literal(token::StrRaw(..), _),
token::Literal(token::Binary(..), _), token::Literal(token::ByteStr(..), _),
token::Literal(token::BinaryRaw(..), _), token::Literal(token::ByteStrRaw(..), _),
token::Ident(..), token::Ident(..),
token::Lifetime(..), token::Lifetime(..),
token::Interpolated(..), token::Interpolated(..),

View file

@ -269,7 +269,7 @@ pub enum ConstVal {
Int(i64), Int(i64),
Uint(u64), Uint(u64),
Str(InternedString), Str(InternedString),
Binary(Rc<Vec<u8>>), ByteStr(Rc<Vec<u8>>),
Bool(bool), Bool(bool),
Struct(ast::NodeId), Struct(ast::NodeId),
Tuple(ast::NodeId), Tuple(ast::NodeId),
@ -283,7 +283,7 @@ impl ConstVal {
Int(_) => "positive integer", Int(_) => "positive integer",
Uint(_) => "unsigned integer", Uint(_) => "unsigned integer",
Str(_) => "string literal", Str(_) => "string literal",
Binary(_) => "binary array", ByteStr(_) => "byte string literal",
Bool(_) => "boolean", Bool(_) => "boolean",
Struct(_) => "struct", Struct(_) => "struct",
Tuple(_) => "tuple", Tuple(_) => "tuple",
@ -1175,8 +1175,8 @@ fn cast_const<'tcx>(tcx: &ty::ctxt<'tcx>, val: ConstVal, ty: Ty) -> CastResult {
fn lit_to_const(lit: &hir::Lit, ty_hint: Option<Ty>) -> ConstVal { fn lit_to_const(lit: &hir::Lit, ty_hint: Option<Ty>) -> ConstVal {
match lit.node { match lit.node {
hir::LitStr(ref s, _) => Str((*s).clone()), hir::LitStr(ref s, _) => Str((*s).clone()),
hir::LitBinary(ref data) => { hir::LitByteStr(ref data) => {
Binary(data.clone()) ByteStr(data.clone())
} }
hir::LitByte(n) => Uint(n as u64), hir::LitByte(n) => Uint(n as u64),
hir::LitChar(n) => Uint(n as u64), hir::LitChar(n) => Uint(n as u64),
@ -1214,7 +1214,7 @@ pub fn compare_const_vals(a: &ConstVal, b: &ConstVal) -> Option<Ordering> {
} }
(&Str(ref a), &Str(ref b)) => a.cmp(b), (&Str(ref a), &Str(ref b)) => a.cmp(b),
(&Bool(a), &Bool(b)) => a.cmp(&b), (&Bool(a), &Bool(b)) => a.cmp(&b),
(&Binary(ref a), &Binary(ref b)) => a.cmp(b), (&ByteStr(ref a), &ByteStr(ref b)) => a.cmp(b),
_ => return None _ => return None
}) })
} }

View file

@ -838,7 +838,7 @@ pub enum Lit_ {
/// A string literal (`"foo"`) /// A string literal (`"foo"`)
LitStr(InternedString, StrStyle), LitStr(InternedString, StrStyle),
/// A byte string (`b"foo"`) /// A byte string (`b"foo"`)
LitBinary(Rc<Vec<u8>>), LitByteStr(Rc<Vec<u8>>),
/// A byte char (`b'f'`) /// A byte char (`b'f'`)
LitByte(u8), LitByte(u8),
/// A character literal (`'a'`) /// A character literal (`'a'`)

View file

@ -664,7 +664,7 @@ pub fn lower_lit(l: &Lit) -> hir::Lit {
Spanned { Spanned {
node: match l.node { node: match l.node {
LitStr(ref i, s) => hir::LitStr(i.clone(), lower_string_style(s)), LitStr(ref i, s) => hir::LitStr(i.clone(), lower_string_style(s)),
LitBinary(ref b) => hir::LitBinary(b.clone()), LitByteStr(ref b) => hir::LitByteStr(b.clone()),
LitByte(u) => hir::LitByte(u), LitByte(u) => hir::LitByte(u),
LitChar(c) => hir::LitChar(c), LitChar(c) => hir::LitChar(c),
LitInt(u, ref t) => hir::LitInt(u, lower_lit_int_type(t)), LitInt(u, ref t) => hir::LitInt(u, lower_lit_int_type(t)),
@ -680,7 +680,7 @@ pub fn unlower_lit(l: &hir::Lit) -> Lit {
Spanned { Spanned {
node: match l.node { node: match l.node {
hir::LitStr(ref i, s) => LitStr(i.clone(), unlower_string_style(s)), hir::LitStr(ref i, s) => LitStr(i.clone(), unlower_string_style(s)),
hir::LitBinary(ref b) => LitBinary(b.clone()), hir::LitByteStr(ref b) => LitByteStr(b.clone()),
hir::LitByte(u) => LitByte(u), hir::LitByte(u) => LitByte(u),
hir::LitChar(c) => LitChar(c), hir::LitChar(c) => LitChar(c),
hir::LitInt(u, ref t) => LitInt(u, unlower_lit_int_type(t)), hir::LitInt(u, ref t) => LitInt(u, unlower_lit_int_type(t)),

View file

@ -2549,7 +2549,7 @@ impl<'a> State<'a> {
hir::LitBool(val) => { hir::LitBool(val) => {
if val { word(&mut self.s, "true") } else { word(&mut self.s, "false") } if val { word(&mut self.s, "true") } else { word(&mut self.s, "false") }
} }
hir::LitBinary(ref v) => { hir::LitByteStr(ref v) => {
let mut escaped: String = String::new(); let mut escaped: String = String::new();
for &ch in v.iter() { for &ch in v.iter() {
escaped.extend(ascii::escape_default(ch) escaped.extend(ascii::escape_default(ch)

View file

@ -94,8 +94,8 @@ pub fn const_lit(cx: &CrateContext, e: &hir::Expr, lit: &hir::Lit)
} }
hir::LitBool(b) => C_bool(cx, b), hir::LitBool(b) => C_bool(cx, b),
hir::LitStr(ref s, _) => C_str_slice(cx, (*s).clone()), hir::LitStr(ref s, _) => C_str_slice(cx, (*s).clone()),
hir::LitBinary(ref data) => { hir::LitByteStr(ref data) => {
addr_of(cx, C_bytes(cx, &data[..]), "binary") addr_of(cx, C_bytes(cx, &data[..]), "byte_str")
} }
} }
} }

View file

@ -56,7 +56,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
// They can denote both statically and dynamically sized byte arrays // They can denote both statically and dynamically sized byte arrays
let mut pat_ty = expr_ty; let mut pat_ty = expr_ty;
if let hir::ExprLit(ref lt) = lt.node { if let hir::ExprLit(ref lt) = lt.node {
if let hir::LitBinary(_) = lt.node { if let hir::LitByteStr(_) = lt.node {
let expected_ty = structurally_resolved_type(fcx, pat.span, expected); let expected_ty = structurally_resolved_type(fcx, pat.span, expected);
if let ty::TyRef(_, mt) = expected_ty.sty { if let ty::TyRef(_, mt) = expected_ty.sty {
if let ty::TySlice(_) = mt.ty.sty { if let ty::TySlice(_) = mt.ty.sty {

View file

@ -2633,7 +2633,7 @@ fn check_lit<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
match lit.node { match lit.node {
hir::LitStr(..) => tcx.mk_static_str(), hir::LitStr(..) => tcx.mk_static_str(),
hir::LitBinary(ref v) => { hir::LitByteStr(ref v) => {
tcx.mk_imm_ref(tcx.mk_region(ty::ReStatic), tcx.mk_imm_ref(tcx.mk_region(ty::ReStatic),
tcx.mk_array(tcx.types.u8, v.len())) tcx.mk_array(tcx.types.u8, v.len()))
} }

View file

@ -2518,7 +2518,7 @@ impl ToSource for syntax::codemap::Span {
fn lit_to_string(lit: &hir::Lit) -> String { fn lit_to_string(lit: &hir::Lit) -> String {
match lit.node { match lit.node {
hir::LitStr(ref st, _) => st.to_string(), hir::LitStr(ref st, _) => st.to_string(),
hir::LitBinary(ref data) => format!("{:?}", data), hir::LitByteStr(ref data) => format!("{:?}", data),
hir::LitByte(b) => { hir::LitByte(b) => {
let mut res = String::from("b'"); let mut res = String::from("b'");
for c in (b as char).escape_default() { for c in (b as char).escape_default() {

View file

@ -131,7 +131,7 @@ fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader,
match lit { match lit {
// text literals // text literals
token::Byte(..) | token::Char(..) | token::Byte(..) | token::Char(..) |
token::Binary(..) | token::BinaryRaw(..) | token::ByteStr(..) | token::ByteStrRaw(..) |
token::Str_(..) | token::StrRaw(..) => "string", token::Str_(..) | token::StrRaw(..) => "string",
// number literals // number literals

View file

@ -1190,7 +1190,7 @@ pub enum Lit_ {
/// A string literal (`"foo"`) /// A string literal (`"foo"`)
LitStr(InternedString, StrStyle), LitStr(InternedString, StrStyle),
/// A byte string (`b"foo"`) /// A byte string (`b"foo"`)
LitBinary(Rc<Vec<u8>>), LitByteStr(Rc<Vec<u8>>),
/// A byte char (`b'f'`) /// A byte char (`b'f'`)
LitByte(u8), LitByte(u8),
/// A character literal (`'a'`) /// A character literal (`'a'`)

View file

@ -50,8 +50,8 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt,
accumulator.push_str(&format!("{}", b)); accumulator.push_str(&format!("{}", b));
} }
ast::LitByte(..) | ast::LitByte(..) |
ast::LitBinary(..) => { ast::LitByteStr(..) => {
cx.span_err(e.span, "cannot concatenate a binary literal"); cx.span_err(e.span, "cannot concatenate a byte string literal");
} }
} }
} }

View file

@ -189,7 +189,7 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
let filename = format!("{}", file.display()); let filename = format!("{}", file.display());
cx.codemap().new_filemap_and_lines(&filename, ""); cx.codemap().new_filemap_and_lines(&filename, "");
base::MacEager::expr(cx.expr_lit(sp, ast::LitBinary(Rc::new(bytes)))) base::MacEager::expr(cx.expr_lit(sp, ast::LitByteStr(Rc::new(bytes))))
} }
} }
} }

View file

@ -1304,7 +1304,7 @@ impl<'a> StringReader<'a> {
} }
let id = if valid { self.name_from(start) } else { token::intern("??") }; let id = if valid { self.name_from(start) } else { token::intern("??") };
self.bump(); self.bump();
return token::Binary(id); return token::ByteStr(id);
} }
fn scan_raw_byte_string(&mut self) -> token::Lit { fn scan_raw_byte_string(&mut self) -> token::Lit {
@ -1355,7 +1355,7 @@ impl<'a> StringReader<'a> {
self.bump(); self.bump();
} }
self.bump(); self.bump();
return token::BinaryRaw(self.name_from_to(content_start_bpos, return token::ByteStrRaw(self.name_from_to(content_start_bpos,
content_end_bpos), content_end_bpos),
hash_count); hash_count);
} }
@ -1546,7 +1546,7 @@ mod tests {
test!("'a'", Char, "a"); test!("'a'", Char, "a");
test!("b'a'", Byte, "a"); test!("b'a'", Byte, "a");
test!("\"a\"", Str_, "a"); test!("\"a\"", Str_, "a");
test!("b\"a\"", Binary, "a"); test!("b\"a\"", ByteStr, "a");
test!("1234", Integer, "1234"); test!("1234", Integer, "1234");
test!("0b101", Integer, "0b101"); test!("0b101", Integer, "0b101");
test!("0xABC", Integer, "0xABC"); test!("0xABC", Integer, "0xABC");
@ -1560,7 +1560,7 @@ mod tests {
token::Literal(token::StrRaw(token::intern("raw"), 3), token::Literal(token::StrRaw(token::intern("raw"), 3),
Some(token::intern("suffix")))); Some(token::intern("suffix"))));
assert_eq!(setup(&mk_sh(), "br###\"raw\"###suffix".to_string()).next_token().tok, assert_eq!(setup(&mk_sh(), "br###\"raw\"###suffix".to_string()).next_token().tok,
token::Literal(token::BinaryRaw(token::intern("raw"), 3), token::Literal(token::ByteStrRaw(token::intern("raw"), 3),
Some(token::intern("suffix")))); Some(token::intern("suffix"))));
} }

View file

@ -499,7 +499,7 @@ pub fn byte_lit(lit: &str) -> (u8, usize) {
} }
} }
pub fn binary_lit(lit: &str) -> Rc<Vec<u8>> { pub fn byte_str_lit(lit: &str) -> Rc<Vec<u8>> {
let mut res = Vec::with_capacity(lit.len()); let mut res = Vec::with_capacity(lit.len());
// FIXME #8372: This could be a for-loop if it didn't borrow the iterator // FIXME #8372: This could be a for-loop if it didn't borrow the iterator
@ -517,7 +517,7 @@ pub fn binary_lit(lit: &str) -> Rc<Vec<u8>> {
} }
} }
// binary literals *must* be ASCII, but the escapes don't have to be // byte string literals *must* be ASCII, but the escapes don't have to be
let mut chars = lit.bytes().enumerate().peekable(); let mut chars = lit.bytes().enumerate().peekable();
loop { loop {
match chars.next() { match chars.next() {

View file

@ -34,7 +34,7 @@ use ast::{ItemEnum, ItemFn, ItemForeignMod, ItemImpl, ItemConst};
use ast::{ItemMac, ItemMod, ItemStruct, ItemTrait, ItemTy, ItemDefaultImpl}; use ast::{ItemMac, ItemMod, ItemStruct, ItemTrait, ItemTy, ItemDefaultImpl};
use ast::{ItemExternCrate, ItemUse}; use ast::{ItemExternCrate, ItemUse};
use ast::{LifetimeDef, Lit, Lit_}; use ast::{LifetimeDef, Lit, Lit_};
use ast::{LitBool, LitChar, LitByte, LitBinary}; use ast::{LitBool, LitChar, LitByte, LitByteStr};
use ast::{LitStr, LitInt, Local}; use ast::{LitStr, LitInt, Local};
use ast::{MacStmtWithBraces, MacStmtWithSemicolon, MacStmtWithoutBraces}; use ast::{MacStmtWithBraces, MacStmtWithSemicolon, MacStmtWithoutBraces};
use ast::{MutImmutable, MutMutable, Mac_, MacInvocTT, MatchSource}; use ast::{MutImmutable, MutMutable, Mac_, MacInvocTT, MatchSource};
@ -1543,11 +1543,11 @@ impl<'a> Parser<'a> {
token::intern_and_get_ident(&parse::raw_str_lit(&s.as_str())), token::intern_and_get_ident(&parse::raw_str_lit(&s.as_str())),
ast::RawStr(n))) ast::RawStr(n)))
} }
token::Binary(i) => token::ByteStr(i) =>
(true, LitBinary(parse::binary_lit(&i.as_str()))), (true, LitByteStr(parse::byte_str_lit(&i.as_str()))),
token::BinaryRaw(i, _) => token::ByteStrRaw(i, _) =>
(true, (true,
LitBinary(Rc::new(i.to_string().into_bytes()))), LitByteStr(Rc::new(i.to_string().into_bytes()))),
}; };
if suffix_illegal { if suffix_illegal {
@ -5826,7 +5826,7 @@ impl<'a> Parser<'a> {
match try!(self.parse_optional_str()) { match try!(self.parse_optional_str()) {
Some((s, style, suf)) => { Some((s, style, suf)) => {
let sp = self.last_span; let sp = self.last_span;
self.expect_no_suffix(sp, "str literal", suf); self.expect_no_suffix(sp, "string literal", suf);
Ok((s, style)) Ok((s, style))
} }
_ => Err(self.fatal("expected string literal")) _ => Err(self.fatal("expected string literal"))

View file

@ -82,8 +82,8 @@ pub enum Lit {
Float(ast::Name), Float(ast::Name),
Str_(ast::Name), Str_(ast::Name),
StrRaw(ast::Name, usize), /* raw str delimited by n hash symbols */ StrRaw(ast::Name, usize), /* raw str delimited by n hash symbols */
Binary(ast::Name), ByteStr(ast::Name),
BinaryRaw(ast::Name, usize), /* raw binary str delimited by n hash symbols */ ByteStrRaw(ast::Name, usize), /* raw byte str delimited by n hash symbols */
} }
impl Lit { impl Lit {
@ -93,8 +93,8 @@ impl Lit {
Char(_) => "char", Char(_) => "char",
Integer(_) => "integer", Integer(_) => "integer",
Float(_) => "float", Float(_) => "float",
Str_(_) | StrRaw(..) => "str", Str_(_) | StrRaw(..) => "string",
Binary(_) | BinaryRaw(..) => "binary str" ByteStr(_) | ByteStrRaw(..) => "byte string"
} }
} }
} }

View file

@ -259,8 +259,8 @@ pub fn token_to_string(tok: &Token) -> String {
token::StrRaw(s, n) => format!("r{delim}\"{string}\"{delim}", token::StrRaw(s, n) => format!("r{delim}\"{string}\"{delim}",
delim=repeat("#", n), delim=repeat("#", n),
string=s), string=s),
token::Binary(v) => format!("b\"{}\"", v), token::ByteStr(v) => format!("b\"{}\"", v),
token::BinaryRaw(s, n) => format!("br{delim}\"{string}\"{delim}", token::ByteStrRaw(s, n) => format!("br{delim}\"{string}\"{delim}",
delim=repeat("#", n), delim=repeat("#", n),
string=s), string=s),
}; };
@ -2887,7 +2887,7 @@ impl<'a> State<'a> {
ast::LitBool(val) => { ast::LitBool(val) => {
if val { word(&mut self.s, "true") } else { word(&mut self.s, "false") } if val { word(&mut self.s, "true") } else { word(&mut self.s, "false") }
} }
ast::LitBinary(ref v) => { ast::LitByteStr(ref v) => {
let mut escaped: String = String::new(); let mut escaped: String = String::new();
for &ch in v.iter() { for &ch in v.iter() {
escaped.extend(ascii::escape_default(ch) escaped.extend(ascii::escape_default(ch)

View file

@ -9,8 +9,8 @@
// except according to those terms. // except according to those terms.
fn main() { fn main() {
concat!(b'f'); //~ ERROR: cannot concatenate a binary literal concat!(b'f'); //~ ERROR: cannot concatenate a byte string literal
concat!(b"foo"); //~ ERROR: cannot concatenate a binary literal concat!(b"foo"); //~ ERROR: cannot concatenate a byte string literal
concat!(foo); //~ ERROR: expected a literal concat!(foo); //~ ERROR: expected a literal
concat!(foo()); //~ ERROR: expected a literal concat!(foo()); //~ ERROR: expected a literal
} }

View file

@ -20,10 +20,10 @@ extern
{} {}
fn main() { fn main() {
""suffix; //~ ERROR str literal with a suffix is invalid ""suffix; //~ ERROR string literal with a suffix is invalid
b""suffix; //~ ERROR binary str literal with a suffix is invalid b""suffix; //~ ERROR byte string literal with a suffix is invalid
r#""#suffix; //~ ERROR str literal with a suffix is invalid r#""#suffix; //~ ERROR string literal with a suffix is invalid
br#""#suffix; //~ ERROR binary str literal with a suffix is invalid br#""#suffix; //~ ERROR byte string literal with a suffix is invalid
'a'suffix; //~ ERROR char literal with a suffix is invalid 'a'suffix; //~ ERROR char literal with a suffix is invalid
b'a'suffix; //~ ERROR byte literal with a suffix is invalid b'a'suffix; //~ ERROR byte literal with a suffix is invalid

View file

@ -11,5 +11,5 @@ all:
$(RUSTC) lib.rs --emit=asm --crate-type=staticlib $(RUSTC) lib.rs --emit=asm --crate-type=staticlib
# just check for symbol declarations with the names we're expecting. # just check for symbol declarations with the names we're expecting.
grep 'str[0-9][0-9]*:' $(OUT) grep 'str[0-9][0-9]*:' $(OUT)
grep 'binary[0-9][0-9]*:' $(OUT) grep 'byte_str[0-9][0-9]*:' $(OUT)
grep 'vtable[0-9][0-9]*' $(OUT) grep 'vtable[0-9][0-9]*' $(OUT)