diff options
| author | bors <bors@rust-lang.org> | 2013-07-22 08:19:32 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-07-22 08:19:32 -0700 |
| commit | 52b7fc14fe4444f0de91a474c70cbf248f96b763 (patch) | |
| tree | 3eb8238a1e8ab4f9999d1185077e2bec74707ed5 /src/libsyntax/parse | |
| parent | 7a3eaf8f27bd626a9667a574bc62464a815a6ad4 (diff) | |
| parent | 5aee3e01a02e0b31ad225e70899a671937ab65ee (diff) | |
| download | rust-52b7fc14fe4444f0de91a474c70cbf248f96b763.tar.gz rust-52b7fc14fe4444f0de91a474c70cbf248f96b763.zip | |
auto merge of #7903 : michaelwoerister/rust/end_of_spanned, r=jdm
Continuation of https://github.com/mozilla/rust/pull/7826. AST spanned<T> refactoring, AST type renamings: `crate => Crate` `local => Local` `blk => Block` `crate_num => CrateNum` `crate_cfg => CrateConfig` `field => Field` Also, Crate, Field and Local are not wrapped in spanned<T> anymore.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/classify.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 36 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 69 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 2 |
4 files changed, 55 insertions, 54 deletions
diff --git a/src/libsyntax/parse/classify.rs b/src/libsyntax/parse/classify.rs index 44497f72003..e31b0ccff80 100644 --- a/src/libsyntax/parse/classify.rs +++ b/src/libsyntax/parse/classify.rs @@ -39,7 +39,7 @@ pub fn expr_requires_semi_to_be_stmt(e: @ast::expr) -> bool { pub fn expr_is_simple_block(e: @ast::expr) -> bool { match e.node { ast::expr_block( - ast::blk { rules: ast::default_blk, _ } + ast::Block { rules: ast::default_blk, _ } ) => true, _ => false } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index c7a65c80de1..bd57f123cc5 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -76,9 +76,9 @@ pub fn new_parse_sess_special_handler(sh: @span_handler, pub fn parse_crate_from_file( input: &Path, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, sess: @mut ParseSess -) -> @ast::crate { +) -> @ast::Crate { new_parser_from_file(sess, /*bad*/ cfg.clone(), input).parse_crate_mod() // why is there no p.abort_if_errors here? } @@ -86,9 +86,9 @@ pub fn parse_crate_from_file( pub fn parse_crate_from_source_str( name: @str, source: @str, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, sess: @mut ParseSess -) -> @ast::crate { +) -> @ast::Crate { let p = new_parser_from_source_str(sess, /*bad*/ cfg.clone(), name, @@ -99,7 +99,7 @@ pub fn parse_crate_from_source_str( pub fn parse_expr_from_source_str( name: @str, source: @str, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, sess: @mut ParseSess ) -> @ast::expr { let p = new_parser_from_source_str( @@ -114,7 +114,7 @@ pub fn parse_expr_from_source_str( pub fn parse_item_from_source_str( name: @str, source: @str, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, attrs: ~[ast::Attribute], sess: @mut ParseSess ) -> Option<@ast::item> { @@ -130,7 +130,7 @@ pub fn parse_item_from_source_str( pub fn parse_meta_from_source_str( name: @str, source: @str, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, sess: @mut ParseSess ) -> @ast::MetaItem { let p = new_parser_from_source_str( @@ -145,7 +145,7 @@ pub fn parse_meta_from_source_str( pub fn parse_stmt_from_source_str( name: @str, source: @str, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, attrs: ~[ast::Attribute], sess: @mut ParseSess ) -> @ast::stmt { @@ -161,7 +161,7 @@ pub fn parse_stmt_from_source_str( pub fn parse_tts_from_source_str( name: @str, source: @str, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, sess: @mut ParseSess ) -> ~[ast::token_tree] { let p = new_parser_from_source_str( @@ -184,7 +184,7 @@ pub fn parse_from_source_str<T>( f: &fn(&Parser) -> T, name: @str, ss: codemap::FileSubstr, source: @str, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, sess: @mut ParseSess ) -> T { let p = new_parser_from_source_substr( @@ -212,7 +212,7 @@ pub fn next_node_id(sess: @mut ParseSess) -> node_id { // Create a new parser from a source string pub fn new_parser_from_source_str(sess: @mut ParseSess, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, name: @str, source: @str) -> Parser { @@ -222,7 +222,7 @@ pub fn new_parser_from_source_str(sess: @mut ParseSess, // Create a new parser from a source string where the origin // is specified as a substring of another file. pub fn new_parser_from_source_substr(sess: @mut ParseSess, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, name: @str, ss: codemap::FileSubstr, source: @str) @@ -234,7 +234,7 @@ pub fn new_parser_from_source_substr(sess: @mut ParseSess, /// if the file doesn't exist pub fn new_parser_from_file( sess: @mut ParseSess, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, path: &Path ) -> Parser { filemap_to_parser(sess,file_to_filemap(sess,path,None),cfg) @@ -245,7 +245,7 @@ pub fn new_parser_from_file( /// On an error, use the given span as the source of the problem. pub fn new_sub_parser_from_file( sess: @mut ParseSess, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, path: &Path, sp: span ) -> Parser { @@ -255,14 +255,14 @@ pub fn new_sub_parser_from_file( /// Given a filemap and config, return a parser pub fn filemap_to_parser(sess: @mut ParseSess, filemap: @FileMap, - cfg: ast::crate_cfg) -> Parser { + cfg: ast::CrateConfig) -> Parser { tts_to_parser(sess,filemap_to_tts(sess,filemap),cfg) } // must preserve old name for now, because quote! from the *existing* // compiler expands into it pub fn new_parser_from_tts(sess: @mut ParseSess, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, tts: ~[ast::token_tree]) -> Parser { tts_to_parser(sess,tts,cfg) } @@ -313,7 +313,7 @@ pub fn filemap_to_tts(sess: @mut ParseSess, filemap: @FileMap) // given tts and cfg, produce a parser pub fn tts_to_parser(sess: @mut ParseSess, tts: ~[ast::token_tree], - cfg: ast::crate_cfg) -> Parser { + cfg: ast::CrateConfig) -> Parser { let trdr = lexer::new_tt_reader(sess.span_diagnostic, None, tts); Parser(sess, cfg, trdr as @reader) } @@ -551,7 +551,7 @@ mod test { lifetimes: opt_vec::Empty, ty_params: opt_vec::Empty, }, - ast::blk { + ast::Block { view_items: ~[], stmts: ~[@spanned{ node: ast::stmt_semi(@ast::expr{ diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index b2a1a8a73bd..a4fd4929400 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -16,9 +16,9 @@ use ast::{TyBareFn, TyClosure}; use ast::{RegionTyParamBound, TraitTyParamBound}; use ast::{provided, public, purity}; use ast::{_mod, add, arg, arm, Attribute, bind_by_ref, bind_infer}; -use ast::{bitand, bitor, bitxor, blk}; +use ast::{bitand, bitor, bitxor, Block}; use ast::{blk_check_mode, box}; -use ast::{crate, crate_cfg, decl, decl_item}; +use ast::{Crate, CrateConfig, decl, decl_item}; use ast::{decl_local, default_blk, deref, div, enum_def, explicit_self}; use ast::{expr, expr_, expr_addr_of, expr_match, expr_again}; use ast::{expr_assign, expr_assign_op, expr_binary, expr_block}; @@ -29,14 +29,14 @@ use ast::{expr_method_call, expr_paren, expr_path, expr_repeat}; use ast::{expr_ret, expr_self, expr_struct, expr_tup, expr_unary}; use ast::{expr_vec, expr_vstore, expr_vstore_mut_box}; use ast::{expr_vstore_slice, expr_vstore_box}; -use ast::{expr_vstore_mut_slice, expr_while, extern_fn, field, fn_decl}; +use ast::{expr_vstore_mut_slice, expr_while, extern_fn, Field, fn_decl}; use ast::{expr_vstore_uniq, Onceness, Once, Many}; use ast::{foreign_item, foreign_item_static, foreign_item_fn, foreign_mod}; use ast::{ident, impure_fn, inherited, item, item_, item_static}; use ast::{item_enum, item_fn, item_foreign_mod, item_impl}; use ast::{item_mac, item_mod, item_struct, item_trait, item_ty, lit, lit_}; use ast::{lit_bool, lit_float, lit_float_unsuffixed, lit_int}; -use ast::{lit_int_unsuffixed, lit_nil, lit_str, lit_uint, local, m_const}; +use ast::{lit_int_unsuffixed, lit_nil, lit_str, lit_uint, Local, m_const}; use ast::{m_imm, m_mutbl, mac_, mac_invoc_tt, matcher, match_nonterminal}; use ast::{match_seq, match_tok, method, mt, mul, mutability}; use ast::{named_field, neg, node_id, noreturn, not, pat, pat_box, pat_enum}; @@ -261,7 +261,7 @@ struct ParsedItemsAndViewItems { /* ident is handled by common.rs */ pub fn Parser(sess: @mut ParseSess, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, rdr: @reader) -> Parser { let tok0 = rdr.next_token(); @@ -299,7 +299,7 @@ pub fn Parser(sess: @mut ParseSess, // ooh, nasty mutable fields everywhere.... pub struct Parser { sess: @mut ParseSess, - cfg: crate_cfg, + cfg: CrateConfig, // the current token: token: @mut token::Token, // the span of the current token: @@ -1498,15 +1498,16 @@ impl Parser { } // parse ident COLON expr - pub fn parse_field(&self) -> field { + pub fn parse_field(&self) -> Field { let lo = self.span.lo; let i = self.parse_ident(); self.expect(&token::COLON); let e = self.parse_expr(); - spanned(lo, e.span.hi, ast::field_ { + ast::Field { ident: i, - expr: e - }) + expr: e, + span: mk_sp(lo, e.span.hi), + } } pub fn mk_expr(&self, lo: BytePos, hi: BytePos, node: expr_) -> @expr { @@ -2294,7 +2295,7 @@ impl Parser { let lo = self.last_span.lo; let decl = parse_decl(); let body = parse_body(); - let fakeblock = ast::blk { + let fakeblock = ast::Block { view_items: ~[], stmts: ~[], expr: Some(body), @@ -2460,7 +2461,7 @@ impl Parser { self.eat(&token::COMMA); } - let blk = ast::blk { + let blk = ast::Block { view_items: ~[], stmts: ~[], expr: Some(expr), @@ -2916,7 +2917,7 @@ impl Parser { } // parse a local variable declaration - fn parse_local(&self, is_mutbl: bool) -> @local { + fn parse_local(&self, is_mutbl: bool) -> @Local { let lo = self.span.lo; let pat = self.parse_pat(); @@ -2931,17 +2932,14 @@ impl Parser { }; if self.eat(&token::COLON) { ty = self.parse_ty(false); } let init = self.parse_initializer(); - @spanned( - lo, - self.last_span.hi, - ast::local_ { - is_mutbl: is_mutbl, - ty: ty, - pat: pat, - init: init, - id: self.get_id(), - } - ) + @ast::Local { + is_mutbl: is_mutbl, + ty: ty, + pat: pat, + init: init, + id: self.get_id(), + span: mk_sp(lo, self.last_span.hi), + } } // parse a "let" stmt @@ -3077,7 +3075,7 @@ impl Parser { } // parse a block. No inner attrs are allowed. - pub fn parse_block(&self) -> blk { + pub fn parse_block(&self) -> Block { maybe_whole!(self, nt_block); let lo = self.span.lo; @@ -3091,7 +3089,7 @@ impl Parser { // parse a block. Inner attrs are allowed. fn parse_inner_attrs_and_block(&self) - -> (~[Attribute], blk) { + -> (~[Attribute], Block) { maybe_whole!(pair_empty self, nt_block); @@ -3109,13 +3107,13 @@ impl Parser { // I guess that also means "already parsed the 'impure'" if // necessary, and this should take a qualifier. // some blocks start with "#{"... - fn parse_block_tail(&self, lo: BytePos, s: blk_check_mode) -> blk { + fn parse_block_tail(&self, lo: BytePos, s: blk_check_mode) -> Block { self.parse_block_tail_(lo, s, ~[]) } // parse the rest of a block expression or function body fn parse_block_tail_(&self, lo: BytePos, s: blk_check_mode, - first_item_attrs: ~[Attribute]) -> blk { + first_item_attrs: ~[Attribute]) -> Block { let mut stmts = ~[]; let mut expr = None; @@ -3237,7 +3235,7 @@ impl Parser { let hi = self.span.hi; self.bump(); - ast::blk { + ast::Block { view_items: view_items, stmts: stmts, expr: expr, @@ -4946,7 +4944,7 @@ impl Parser { // Parses a source module as a crate. This is the main // entry point for the parser. - pub fn parse_crate_mod(&self) -> @crate { + pub fn parse_crate_mod(&self) -> @Crate { let lo = self.span.lo; // parse the crate's inner attrs, maybe (oops) one // of the attrs of an item: @@ -4954,10 +4952,13 @@ impl Parser { let first_item_outer_attrs = next; // parse the items inside the crate: let m = self.parse_mod_items(token::EOF, first_item_outer_attrs); - @spanned(lo, self.span.lo, - ast::crate_ { module: m, - attrs: inner, - config: self.cfg.clone() }) + + @ast::Crate { + module: m, + attrs: inner, + config: self.cfg.clone(), + span: mk_sp(lo, self.span.lo) + } } pub fn parse_str(&self) -> @str { diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 322424b90fb..2d15d0ab7e8 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -99,7 +99,7 @@ pub enum Token { /// For interpolation during macro expansion. pub enum nonterminal { nt_item(@ast::item), - nt_block(ast::blk), + nt_block(ast::Block), nt_stmt(@ast::stmt), nt_pat( @ast::pat), nt_expr(@ast::expr), |
