]> git.lizzy.rs Git - rust.git/commitdiff
Workaround to have doc comments desugared only in macros
authorPiotr Czarnecki <pioczarn@gmail.com>
Fri, 10 Oct 2014 18:47:20 +0000 (19:47 +0100)
committerPiotr Czarnecki <pioczarn@gmail.com>
Wed, 5 Nov 2014 22:06:01 +0000 (23:06 +0100)
src/libsyntax/ext/tt/macro_rules.rs
src/libsyntax/ext/tt/transcribe.rs

index 381e4310d89ecb8ccb1348bd944fd7cf470aaf16..15792b7f7716ac7102cb69128269d5b11ccbb0ed 100644 (file)
@@ -164,11 +164,12 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
                 _ => cx.span_fatal(sp, "malformed macro lhs")
             };
             // `None` is because we're not interpolating
-            let arg_rdr = new_tt_reader(&cx.parse_sess().span_diagnostic,
-                                        None,
-                                        arg.iter()
-                                           .map(|x| (*x).clone())
-                                           .collect());
+            let mut arg_rdr = new_tt_reader(&cx.parse_sess().span_diagnostic,
+                                            None,
+                                            arg.iter()
+                                               .map(|x| (*x).clone())
+                                               .collect());
+            arg_rdr.desugar_doc_comments = true;
             match parse(cx.parse_sess(), cx.cfg(), arg_rdr, lhs_tt) {
               Success(named_matches) => {
                 let rhs = match *rhses[i] {
index e8a2d9a243362bb15458b79b335ae592445bbdbf..88253c0d24c6190c4d8f397e69ed0d21c943675f 100644 (file)
@@ -43,6 +43,8 @@ pub struct TtReader<'a> {
     /* cached: */
     pub cur_tok: Token,
     pub cur_span: Span,
+    /// Transform doc comments. Only useful in macro invocations
+    pub desugar_doc_comments: bool,
 }
 
 /// This can do Macro-By-Example transcription. On the other hand, if
@@ -66,6 +68,7 @@ pub fn new_tt_reader<'a>(sp_diag: &'a SpanHandler,
         },
         repeat_idx: Vec::new(),
         repeat_len: Vec::new(),
+        desugar_doc_comments: false,
         /* dummy values, never read: */
         cur_tok: token::Eof,
         cur_span: DUMMY_SP,
@@ -279,8 +282,7 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
                 }
             }
             // TtDelimited or any token that can be unzipped
-            seq @ TtDelimited(..) | seq @ TtToken(_, DocComment(..))
-            | seq @ TtToken(_, MatchNt(..)) => {
+            seq @ TtDelimited(..) | seq @ TtToken(_, MatchNt(..)) => {
                 // do not advance the idx yet
                 r.stack.push(TtFrame {
                    forest: seq.expand_into_tts(),
@@ -290,6 +292,14 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
                 });
                 // if this could be 0-length, we'd need to potentially recur here
             }
+            TtToken(sp, DocComment(name)) if r.desugar_doc_comments => {
+                r.stack.push(TtFrame {
+                   forest: TtToken(sp, DocComment(name)).expand_into_tts(),
+                   idx: 0,
+                   dotdotdoted: false,
+                   sep: None
+                });
+            }
             TtToken(sp, tok) => {
                 r.cur_span = sp;
                 r.cur_tok = tok;