diff options
| author | bors <bors@rust-lang.org> | 2016-06-27 16:42:03 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-06-27 16:42:03 -0700 |
| commit | ea0dc9297283daff6486807f43e190b4eb561412 (patch) | |
| tree | d184776089de9911ae9e983cc692021498e21a25 /src/libsyntax/parse/mod.rs | |
| parent | a0f572e98bacc719aa211b1fe97c61339cf6c93a (diff) | |
| parent | 360dcae4197d0bf0f59d5364470e00b589d5c549 (diff) | |
| download | rust-ea0dc9297283daff6486807f43e190b4eb561412.tar.gz rust-ea0dc9297283daff6486807f43e190b4eb561412.zip | |
Auto merge of #34424 - jseyfried:breaking_batch, r=Manishearth
Batch up libsyntax breaking changes Batch of the following syntax-[breaking-change] changes: - #34213: Add a variant `Macro` to `TraitItemKind` - #34368: Merge the variant `QPath` of `PatKind` into the variant `PatKind::Path` - #34385: Move `syntax::ast::TokenTree` into a new module `syntax::tokenstream` - #33943: - Remove the type parameter from `visit::Visitor` - Remove `attr::WithAttrs` -- use `attr::HasAttrs` instead. - Change `fold_tt`/`fold_tts` to take token trees by value and avoid wrapping token trees in `Rc`. - Remove the field `ctxt` of `ast::Mac_` - Remove inherent method `attrs()` of types -- use the method `attrs` of `HasAttrs` instead. - #34316: - Remove `ast::Decl`/`ast::DeclKind` and add variants `Local` and `Item` to `StmtKind`. - Move the node id for statements from the `StmtKind` variants to a field of `Stmt` (making `Stmt` a struct instead of an alias for `Spanned<StmtKind>`) - Rename `ast::ExprKind::Again` to `Continue`. - #34339: Generalize and abstract `ThinAttributes` to `ThinVec<Attribute>` - Use `.into()` in convert between `Vec<Attribute>` and `ThinVec<Attribute>` - Use autoderef instead of `.as_attr_slice()` - #34436: Remove the optional expression from `ast::Block` and instead use a `StmtKind::Expr` at the end of the statement list. - #34403: Move errors into a separate crate (unlikely to cause breakage)
Diffstat (limited to 'src/libsyntax/parse/mod.rs')
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 67 |
1 files changed, 35 insertions, 32 deletions
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 2e4d46bc983..bbcc044d43c 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -11,12 +11,14 @@ //! The main parser interface use ast; -use codemap::{self, Span, CodeMap, FileMap}; +use codemap::CodeMap; +use syntax_pos::{self, Span, FileMap}; use errors::{Handler, ColorConfig, DiagnosticBuilder}; use parse::parser::Parser; use parse::token::InternedString; use ptr::P; use str::char_at; +use tokenstream; use std::cell::RefCell; use std::iter; @@ -160,7 +162,7 @@ pub fn parse_tts_from_source_str<'a>(name: String, source: String, cfg: ast::CrateConfig, sess: &'a ParseSess) - -> PResult<'a, Vec<ast::TokenTree>> { + -> PResult<'a, Vec<tokenstream::TokenTree>> { let mut p = new_parser_from_source_str( sess, cfg, @@ -211,8 +213,8 @@ pub fn filemap_to_parser<'a>(sess: &'a ParseSess, let end_pos = filemap.end_pos; let mut parser = tts_to_parser(sess, filemap_to_tts(sess, filemap), cfg); - if parser.token == token::Eof && parser.span == codemap::DUMMY_SP { - parser.span = codemap::mk_sp(end_pos, end_pos); + if parser.token == token::Eof && parser.span == syntax_pos::DUMMY_SP { + parser.span = syntax_pos::mk_sp(end_pos, end_pos); } parser @@ -222,7 +224,7 @@ pub fn filemap_to_parser<'a>(sess: &'a ParseSess, // compiler expands into it pub fn new_parser_from_tts<'a>(sess: &'a ParseSess, cfg: ast::CrateConfig, - tts: Vec<ast::TokenTree>) -> Parser<'a> { + tts: Vec<tokenstream::TokenTree>) -> Parser<'a> { tts_to_parser(sess, tts, cfg) } @@ -247,7 +249,7 @@ fn file_to_filemap(sess: &ParseSess, path: &Path, spanopt: Option<Span>) /// Given a filemap, produce a sequence of token-trees pub fn filemap_to_tts(sess: &ParseSess, filemap: Rc<FileMap>) - -> Vec<ast::TokenTree> { + -> Vec<tokenstream::TokenTree> { // it appears to me that the cfg doesn't matter here... indeed, // parsing tt's probably shouldn't require a parser at all. let cfg = Vec::new(); @@ -258,7 +260,7 @@ pub fn filemap_to_tts(sess: &ParseSess, filemap: Rc<FileMap>) /// Given tts and cfg, produce a parser pub fn tts_to_parser<'a>(sess: &'a ParseSess, - tts: Vec<ast::TokenTree>, + tts: Vec<tokenstream::TokenTree>, cfg: ast::CrateConfig) -> Parser<'a> { let trdr = lexer::new_tt_reader(&sess.span_diagnostic, None, None, tts); let mut p = Parser::new(sess, cfg, Box::new(trdr)); @@ -660,9 +662,9 @@ pub fn integer_lit(s: &str, #[cfg(test)] mod tests { use super::*; - use std::rc::Rc; - use codemap::{Span, BytePos, Pos, Spanned, NO_EXPANSION}; - use ast::{self, TokenTree, PatKind}; + use syntax_pos::{Span, BytePos, Pos, NO_EXPANSION}; + use codemap::Spanned; + use ast::{self, PatKind}; use abi::Abi; use attr::{first_attr_value_str_by_name, AttrMetaMethods}; use parse; @@ -670,10 +672,12 @@ mod tests { use parse::token::{str_to_ident}; use print::pprust::item_to_string; use ptr::P; + use tokenstream::{self, TokenTree}; use util::parser_testing::{string_to_tts, string_to_parser}; use util::parser_testing::{string_to_expr, string_to_item, string_to_stmt}; + use util::ThinVec; - // produce a codemap::span + // produce a syntax_pos::span fn sp(a: u32, b: u32) -> Span { Span {lo: BytePos(a), hi: BytePos(b), expn_id: NO_EXPANSION} } @@ -693,7 +697,7 @@ mod tests { ), }), span: sp(0, 1), - attrs: None, + attrs: ThinVec::new(), })) } @@ -716,7 +720,7 @@ mod tests { ) }), span: sp(0, 6), - attrs: None, + attrs: ThinVec::new(), })) } @@ -729,7 +733,7 @@ mod tests { #[test] fn string_to_tts_macro () { let tts = string_to_tts("macro_rules! zip (($a)=>($a))".to_string()); - let tts: &[ast::TokenTree] = &tts[..]; + let tts: &[tokenstream::TokenTree] = &tts[..]; match (tts.len(), tts.get(0), tts.get(1), tts.get(2), tts.get(3)) { ( @@ -759,7 +763,7 @@ mod tests { ) if first_delimed.delim == token::Paren && ident.name.as_str() == "a" => {}, - _ => panic!("value 3: {:?}", **first_delimed), + _ => panic!("value 3: {:?}", *first_delimed), } let tts = &second_delimed.tts[..]; match (tts.len(), tts.get(0), tts.get(1)) { @@ -770,10 +774,10 @@ mod tests { ) if second_delimed.delim == token::Paren && ident.name.as_str() == "a" => {}, - _ => panic!("value 4: {:?}", **second_delimed), + _ => panic!("value 4: {:?}", *second_delimed), } }, - _ => panic!("value 2: {:?}", **macro_delimed), + _ => panic!("value 2: {:?}", *macro_delimed), } }, _ => panic!("value: {:?}",tts), @@ -789,7 +793,7 @@ mod tests { TokenTree::Token(sp(3, 4), token::Ident(str_to_ident("a"))), TokenTree::Delimited( sp(5, 14), - Rc::new(ast::Delimited { + tokenstream::Delimited { delim: token::DelimToken::Paren, open_span: sp(5, 6), tts: vec![ @@ -798,10 +802,10 @@ mod tests { TokenTree::Token(sp(10, 13), token::Ident(str_to_ident("i32"))), ], close_span: sp(13, 14), - })), + }), TokenTree::Delimited( sp(15, 21), - Rc::new(ast::Delimited { + tokenstream::Delimited { delim: token::DelimToken::Brace, open_span: sp(15, 16), tts: vec![ @@ -809,7 +813,7 @@ mod tests { TokenTree::Token(sp(18, 19), token::Semi), ], close_span: sp(20, 21), - })) + }) ]; assert_eq!(tts, expected); @@ -832,16 +836,16 @@ mod tests { ), }), span:sp(7,8), - attrs: None, + attrs: ThinVec::new(), }))), span:sp(0,8), - attrs: None, + attrs: ThinVec::new(), })) } #[test] fn parse_stmt_1 () { assert!(string_to_stmt("b;".to_string()) == - Some(Spanned{ + Some(ast::Stmt { node: ast::StmtKind::Expr(P(ast::Expr { id: ast::DUMMY_NODE_ID, node: ast::ExprKind::Path(None, ast::Path { @@ -855,8 +859,8 @@ mod tests { ), }), span: sp(0,1), - attrs: None}), - ast::DUMMY_NODE_ID), + attrs: ThinVec::new()})), + id: ast::DUMMY_NODE_ID, span: sp(0,1)})) } @@ -932,7 +936,7 @@ mod tests { } }, P(ast::Block { - stmts: vec!(Spanned{ + stmts: vec!(ast::Stmt { node: ast::StmtKind::Semi(P(ast::Expr{ id: ast::DUMMY_NODE_ID, node: ast::ExprKind::Path(None, @@ -950,10 +954,9 @@ mod tests { ), }), span: sp(17,18), - attrs: None,}), - ast::DUMMY_NODE_ID), + attrs: ThinVec::new()})), + id: ast::DUMMY_NODE_ID, span: sp(17,19)}), - expr: None, id: ast::DUMMY_NODE_ID, rules: ast::BlockCheckMode::Default, // no idea span: sp(15,21), @@ -992,8 +995,8 @@ mod tests { struct PatIdentVisitor { spans: Vec<Span> } - impl<'v> ::visit::Visitor<'v> for PatIdentVisitor { - fn visit_pat(&mut self, p: &'v ast::Pat) { + impl ::visit::Visitor for PatIdentVisitor { + fn visit_pat(&mut self, p: &ast::Pat) { match p.node { PatKind::Ident(_ , ref spannedident, _) => { self.spans.push(spannedident.span.clone()); |
