diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-11-02 18:44:27 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-11-03 08:31:44 -0800 |
| commit | 6478fcfafe390355c4cc2f7e22cfbf4cd1f5eeee (patch) | |
| tree | 043fbec89cb67ff0f10a117c326d3d853b6417a0 /src/libsyntax/ext/base.rs | |
| parent | 566ee9ecb3f40d8de93a9b4c5c90e1c26b12b5e1 (diff) | |
| parent | 8e6e846d8a26e5a9d3aafd0bdcc18ed3ddf0cbca (diff) | |
| download | rust-6478fcfafe390355c4cc2f7e22cfbf4cd1f5eeee.tar.gz rust-6478fcfafe390355c4cc2f7e22cfbf4cd1f5eeee.zip | |
rollup merge of #18470 : alexcrichton/dash-l
Diffstat (limited to 'src/libsyntax/ext/base.rs')
| -rw-r--r-- | src/libsyntax/ext/base.rs | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index e641abbfeee..bd6df9cb497 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -675,26 +675,19 @@ pub fn check_zero_tts(cx: &ExtCtxt, /// Extract the string literal from the first token of `tts`. If this /// is not a string literal, emit an error and return None. -pub fn get_single_str_from_tts(cx: &ExtCtxt, +pub fn get_single_str_from_tts(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree], name: &str) -> Option<String> { - if tts.len() != 1 { - cx.span_err(sp, format!("{} takes 1 argument.", name).as_slice()); - } else { - match tts[0] { - ast::TtToken(_, token::LitStr(ident)) => return Some(parse::str_lit(ident.as_str())), - ast::TtToken(_, token::LitStrRaw(ident, _)) => { - return Some(parse::raw_str_lit(ident.as_str())) - } - _ => { - cx.span_err(sp, - format!("{} requires a string.", name).as_slice()) - } - } + let mut p = cx.new_parser_from_tts(tts); + let ret = cx.expander().fold_expr(p.parse_expr()); + if p.token != token::Eof { + cx.span_err(sp, format!("{} takes 1 argument", name).as_slice()); } - None + expr_to_string(cx, ret, "argument must be a string literal").map(|(s, _)| { + s.get().to_string() + }) } /// Extract comma-separated expressions from `tts`. If there is a |
