From a2566301e12364e227f0b72b51bb09698e1cb9dc Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Thu, 18 May 2017 10:37:24 +1200 Subject: Add an option to the parser to avoid parsing out of line modules This is useful if parsing from stdin or a String and don't want to try and read in a module from another file. Instead we just leave a stub in the AST. --- src/libsyntax/ext/tt/macro_parser.rs | 8 ++++++-- src/libsyntax/ext/tt/macro_rules.rs | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index bf66aa0f00b..0b6a2eb536a 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -418,9 +418,13 @@ fn inner_parse_loop(sess: &ParseSess, Success(()) } -pub fn parse(sess: &ParseSess, tts: TokenStream, ms: &[TokenTree], directory: Option) +pub fn parse(sess: &ParseSess, + tts: TokenStream, + ms: &[TokenTree], + directory: Option, + recurse_into_modules: bool) -> NamedParseResult { - let mut parser = Parser::new(sess, tts, directory, true); + let mut parser = Parser::new(sess, tts, directory, recurse_into_modules, true); let mut cur_eis = SmallVector::one(initial_matcher_pos(ms.to_owned(), parser.span.lo)); let mut next_eis = Vec::new(); // or proceed normally diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index a208f530602..73494d47fee 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -121,7 +121,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt, path: cx.current_expansion.module.directory.clone(), ownership: cx.current_expansion.directory_ownership, }; - let mut p = Parser::new(cx.parse_sess(), tts, Some(directory), false); + let mut p = Parser::new(cx.parse_sess(), tts, Some(directory), true, false); p.root_module_name = cx.current_expansion.module.mod_path.last() .map(|id| id.name.as_str().to_string()); @@ -192,7 +192,7 @@ pub fn compile(sess: &ParseSess, features: &RefCell, def: &ast::Item) ast::ItemKind::MacroDef(ref body) => body.clone().into(), _ => unreachable!(), }; - let argument_map = match parse(sess, body, &argument_gram, None) { + let argument_map = match parse(sess, body, &argument_gram, None, true) { Success(m) => m, Failure(sp, tok) => { let s = parse_failure_msg(tok); -- cgit 1.4.1-3-g733a5