From 08b6057538b9bb81bb71db632344ed0312e57f5f Mon Sep 17 00:00:00 2001 From: John Clements Date: Tue, 26 Feb 2013 10:15:29 -0800 Subject: Macros now leave scope Macro scope is now delimited by function, block, and module boundaries, except for modules that are marked with #[macro_escape], which allows macros to escape. --- src/libsyntax/parse/mod.rs | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'src/libsyntax/parse/mod.rs') diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 5fa61159385..a31a73f594a 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -94,9 +94,7 @@ pub fn parse_crate_from_source_str(name: ~str, sess: @mut ParseSess) -> @ast::crate { let p = new_parser_from_source_str(sess, cfg, name, codemap::FssNone, source); - let r = p.parse_crate_mod(cfg); - p.abort_if_errors(); - return r; + maybe_aborted(p.parse_crate_mod(cfg),p) } pub fn parse_expr_from_source_str(name: ~str, @@ -105,9 +103,7 @@ pub fn parse_expr_from_source_str(name: ~str, sess: @mut ParseSess) -> @ast::expr { let p = new_parser_from_source_str(sess, cfg, name, codemap::FssNone, source); - let r = p.parse_expr(); - p.abort_if_errors(); - return r; + maybe_aborted(p.parse_expr(), p) } pub fn parse_item_from_source_str(name: ~str, @@ -118,9 +114,7 @@ pub fn parse_item_from_source_str(name: ~str, -> Option<@ast::item> { let p = new_parser_from_source_str(sess, cfg, name, codemap::FssNone, source); - let r = p.parse_item(attrs); - p.abort_if_errors(); - return r; + maybe_aborted(p.parse_item(attrs),p) } pub fn parse_stmt_from_source_str(name: ~str, @@ -130,9 +124,7 @@ pub fn parse_stmt_from_source_str(name: ~str, sess: @mut ParseSess) -> @ast::stmt { let p = new_parser_from_source_str(sess, cfg, name, codemap::FssNone, source); - let r = p.parse_stmt(attrs); - p.abort_if_errors(); - return r; + maybe_aborted(p.parse_stmt(attrs),p) } pub fn parse_tts_from_source_str(name: ~str, @@ -142,9 +134,7 @@ pub fn parse_tts_from_source_str(name: ~str, let p = new_parser_from_source_str(sess, cfg, name, codemap::FssNone, source); *p.quote_depth += 1u; - let r = p.parse_all_token_trees(); - p.abort_if_errors(); - return r; + maybe_aborted(p.parse_all_token_trees(),p) } pub fn parse_from_source_str(f: fn (p: Parser) -> T, @@ -159,8 +149,7 @@ pub fn parse_from_source_str(f: fn (p: Parser) -> T, if !p.reader.is_eof() { p.reader.fatal(~"expected end-of-string"); } - p.abort_if_errors(); - r + maybe_aborted(r,p) } pub fn next_node_id(sess: @mut ParseSess) -> node_id { @@ -181,8 +170,8 @@ pub fn new_parser_from_source_str(sess: @mut ParseSess, cfg: ast::crate_cfg, return Parser(sess, cfg, srdr as reader); } -// Read the entire source file, return a parser -// that draws from that string +/// Read the entire source file, return a parser +/// that draws from that string pub fn new_parser_result_from_file(sess: @mut ParseSess, cfg: ast::crate_cfg, path: &Path) @@ -201,7 +190,7 @@ pub fn new_parser_result_from_file(sess: @mut ParseSess, } } -/// Create a new parser for an entire crate, handling errors as appropriate +/// Create a new parser, handling errors as appropriate /// if the file doesn't exist pub fn new_parser_from_file(sess: @mut ParseSess, cfg: ast::crate_cfg, path: &Path) -> Parser { @@ -232,6 +221,13 @@ pub fn new_parser_from_tts(sess: @mut ParseSess, cfg: ast::crate_cfg, return Parser(sess, cfg, trdr as reader) } +// abort if necessary +pub fn maybe_aborted(+result : T, p: Parser) -> T { + p.abort_if_errors(); + result +} + + #[cfg(test)] mod test { -- cgit 1.4.1-3-g733a5