]> git.lizzy.rs Git - rust.git/commitdiff
add token::LIT_STR_RAW(ident, num of # symbols)
authorBenjamin Herr <ben@0x539.de>
Wed, 2 Oct 2013 01:32:29 +0000 (03:32 +0200)
committerBenjamin Herr <ben@0x539.de>
Mon, 7 Oct 2013 23:44:05 +0000 (01:44 +0200)
Treat it as a synonym for LIT_STR for now.

src/libsyntax/ext/base.rs
src/libsyntax/ext/quote.rs
src/libsyntax/parse/lexer.rs
src/libsyntax/parse/parser.rs
src/libsyntax/parse/token.rs

index 3b4be1de3e81b34c69967cc565ea9318e2741f34..5a3c3a86fed044d7ed7c6aa0ebb4a0f42c5b6d6c 100644 (file)
@@ -437,7 +437,8 @@ pub fn get_single_str_from_tts(cx: @ExtCtxt,
     }
 
     match tts[0] {
-        ast::tt_tok(_, token::LIT_STR(ident)) => cx.str_of(ident),
+        ast::tt_tok(_, token::LIT_STR(ident))
+        | ast::tt_tok(_, token::LIT_STR_RAW(ident, _)) => cx.str_of(ident),
         _ => cx.span_fatal(sp, format!("{} requires a string.", name)),
     }
 }
index bfd1e9cc9943a6d58d913a3b20d8156f0dbf4f2e..59d55933fa3794a8e225fd9e99be46a7194eeac4 100644 (file)
@@ -464,6 +464,13 @@ fn mk_token(cx: @ExtCtxt, sp: Span, tok: &token::Token) -> @ast::Expr {
                                       ~[mk_ident(cx, sp, ident)]);
         }
 
+        LIT_STR_RAW(ident, n) => {
+            return cx.expr_call_ident(sp,
+                                      id_ext("LIT_STR_RAW"),
+                                      ~[mk_ident(cx, sp, ident),
+                                        cx.expr_uint(sp, n)]);
+        }
+
         IDENT(ident, b) => {
             return cx.expr_call_ident(sp,
                                       id_ext("IDENT"),
index 902c7f27fe6ce53f650bf1ade2c40edf3c3d1d13..a43e018cf49493e193af3f48aeb19be38435abcd 100644 (file)
@@ -883,7 +883,7 @@ fn binop(rdr: @mut StringReader, op: token::binop) -> token::Token {
                                            content_start_bpos,
                                            content_end_bpos,
                                            str_to_ident);
-        return token::LIT_STR(str_content);
+        return token::LIT_STR_RAW(str_content, hash_count);
       }
       '-' => {
         if nextch(rdr) == '>' {
@@ -1048,7 +1048,7 @@ fn mk_ident (id: &str, is_mod_name: bool) -> token::Token {
         let TokenAndSpan {tok, sp: _} =
             env.string_reader.next_token();
         let id = token::str_to_ident("\"#a\\b\x00c\"");
-        assert_eq!(tok, token::LIT_STR(id));
+        assert_eq!(tok, token::LIT_STR_RAW(id, 3));
     }
 
     #[test] fn line_doc_comments() {
index cad19543608ba1ab19d387c6ee3381e2cb3f3c5a..c8689db417c7409defc09796b89b0ecd7d9bfdb8 100644 (file)
@@ -1283,6 +1283,7 @@ pub fn lit_from_token(&self, tok: &token::Token) -> lit_ {
             token::LIT_FLOAT_UNSUFFIXED(s) =>
                 lit_float_unsuffixed(self.id_to_str(s)),
             token::LIT_STR(s) => lit_str(self.id_to_str(s)),
+            token::LIT_STR_RAW(s, _) => lit_str(self.id_to_str(s)),
             token::LPAREN => { self.expect(&token::RPAREN); lit_nil },
             _ => { self.unexpected_last(tok); }
         }
@@ -4345,7 +4346,8 @@ fn fn_expr_lookahead(&self, tok: &token::Token) -> bool {
     // parse a string as an ABI spec on an extern type or module
     fn parse_opt_abis(&self) -> Option<AbiSet> {
         match *self.token {
-            token::LIT_STR(s) => {
+            token::LIT_STR(s)
+            | token::LIT_STR_RAW(s, _) => {
                 self.bump();
                 let the_string = ident_to_str(&s);
                 let mut abis = AbiSet::empty();
@@ -4932,7 +4934,8 @@ pub fn parse_crate_mod(&self) -> Crate {
 
     pub fn parse_optional_str(&self) -> Option<@str> {
         match *self.token {
-            token::LIT_STR(s) => {
+            token::LIT_STR(s)
+            | token::LIT_STR_RAW(s, _) => {
                 self.bump();
                 Some(ident_to_str(&s))
             }
index d0faf917688d7ad9188aed11488429c27d2652ba..ba4c2637d10e337f19753f5219d7ea27e2211f34 100644 (file)
@@ -79,6 +79,7 @@ pub enum Token {
     LIT_FLOAT(ast::Ident, ast::float_ty),
     LIT_FLOAT_UNSUFFIXED(ast::Ident),
     LIT_STR(ast::Ident),
+    LIT_STR_RAW(ast::Ident, uint), /* raw str delimited by n hash symbols */
 
     /* Name components */
     // an identifier contains an "is_mod_name" boolean,
@@ -194,6 +195,10 @@ pub fn to_str(input: @ident_interner, t: &Token) -> ~str {
         body
       }
       LIT_STR(ref s) => { format!("\"{}\"", ident_to_str(s).escape_default()) }
+      LIT_STR_RAW(ref s, n) => {
+          format!("r{delim}\"{string}\"{delim}",
+                  delim="#".repeat(n), string=ident_to_str(s))
+      }
 
       /* Name components */
       IDENT(s, _) => input.get(s.name).to_owned(),
@@ -243,6 +248,7 @@ pub fn can_begin_expr(t: &Token) -> bool {
       LIT_FLOAT(_, _) => true,
       LIT_FLOAT_UNSUFFIXED(_) => true,
       LIT_STR(_) => true,
+      LIT_STR_RAW(_, _) => true,
       POUND => true,
       AT => true,
       NOT => true,
@@ -284,6 +290,7 @@ pub fn is_lit(t: &Token) -> bool {
       LIT_FLOAT(_, _) => true,
       LIT_FLOAT_UNSUFFIXED(_) => true,
       LIT_STR(_) => true,
+      LIT_STR_RAW(_, _) => true,
       _ => false
     }
 }