diff options
| author | Piotr Czarnecki <pioczarn@gmail.com> | 2014-10-10 19:47:20 +0100 |
|---|---|---|
| committer | Piotr Czarnecki <pioczarn@gmail.com> | 2014-11-05 23:06:01 +0100 |
| commit | a8ce669b42471863862e84148286f86040f1f4d5 (patch) | |
| tree | 4d9135ab4765c23ac3d8ec4d0185289befd414c7 /src/libsyntax | |
| parent | 6f30a4ee6c35342cc2775d77882ad26fc31ba61e (diff) | |
| download | rust-a8ce669b42471863862e84148286f86040f1f4d5.tar.gz rust-a8ce669b42471863862e84148286f86040f1f4d5.zip | |
Workaround to have doc comments desugared only in macros
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/tt/macro_rules.rs | 11 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/transcribe.rs | 14 |
2 files changed, 18 insertions, 7 deletions
diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 381e4310d89..15792b7f771 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -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] { diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index e8a2d9a2433..88253c0d24c 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -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; |
