diff options
| author | Felix S. Klock II <pnkfelix@pnkfx.org> | 2014-08-06 17:04:44 +0200 |
|---|---|---|
| committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2014-08-06 17:04:44 +0200 |
| commit | d3202354f5fe3860c429adc4bab6e6dc88ee83bc (patch) | |
| tree | 04140f380a93c58864e9d84503f7aad3ea6a2985 /src/libsyntax | |
| parent | b09a02b41588b2348fcce89c37c4a2cdc614d350 (diff) | |
| download | rust-d3202354f5fe3860c429adc4bab6e6dc88ee83bc.tar.gz rust-d3202354f5fe3860c429adc4bab6e6dc88ee83bc.zip | |
AST refactoring: merge PatWild and PatWildMulti into one variant with a flag.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 14 | ||||
| -rw-r--r-- | src/libsyntax/ast_util.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/base.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/build.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 3 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/visit.rs | 2 |
8 files changed, 23 insertions, 14 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 19882fecaa9..2d39a47a85e 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -324,9 +324,19 @@ pub enum BindingMode { } #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] -pub enum Pat_ { - PatWild, +pub enum PatWildKind { + /// Represents the wildcard pattern `_` + PatWildSingle, + + /// Represents the wildcard pattern `..` PatWildMulti, +} + +#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +pub enum Pat_ { + /// Represents a wildcard pattern (either `_` or `..`) + PatWild(PatWildKind), + /// A PatIdent may either be a new bound variable, /// or a nullary enum (in which case the third field /// is None). diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 99726da69c9..e58187fe30d 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -636,7 +636,7 @@ pub fn walk_pat(pat: &Pat, it: |&Pat| -> bool) -> bool { after.iter().all(|p| walk_pat(&**p, |p| it(p))) } PatMac(_) => fail!("attempted to analyze unexpanded pattern"), - PatWild | PatWildMulti | PatLit(_) | PatRange(_, _) | PatIdent(_, _, _) | + PatWild(_) | PatLit(_) | PatRange(_, _) | PatIdent(_, _, _) | PatEnum(_, _) => { true } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index d00406e07b7..01d3920a254 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -229,7 +229,7 @@ impl DummyResult { pub fn raw_pat(sp: Span) -> Gc<ast::Pat> { box(GC) ast::Pat { id: ast::DUMMY_NODE_ID, - node: ast::PatWild, + node: ast::PatWild(ast::PatWildSingle), span: sp, } } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 5acb84cf852..d500600e25d 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -763,7 +763,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { box(GC) ast::Pat { id: ast::DUMMY_NODE_ID, node: pat, span: span } } fn pat_wild(&self, span: Span) -> Gc<ast::Pat> { - self.pat(span, ast::PatWild) + self.pat(span, ast::PatWild(ast::PatWildSingle)) } fn pat_lit(&self, span: Span, expr: Gc<ast::Expr>) -> Gc<ast::Pat> { self.pat(span, ast::PatLit(expr)) diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index f3e6cf77e79..2f82702ece4 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -969,8 +969,7 @@ pub fn noop_fold_method<T: Folder>(m: &Method, folder: &mut T) -> SmallVector<Gc pub fn noop_fold_pat<T: Folder>(p: Gc<Pat>, folder: &mut T) -> Gc<Pat> { let id = folder.new_id(p.id); let node = match p.node { - PatWild => PatWild, - PatWildMulti => PatWildMulti, + PatWild(k) => PatWild(k), PatIdent(binding_mode, ref pth1, ref sub) => { PatIdent(binding_mode, Spanned{span: folder.new_span(pth1.span), diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 18b1d60d4e9..c9fba355c4d 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -39,7 +39,7 @@ use ast::{MutImmutable, MutMutable, Mac_, MacInvocTT, Matcher, MatchNonterminal} use ast::{MatchSeq, MatchTok, Method, MutTy, BiMul, Mutability}; use ast::{NamedField, UnNeg, NoReturn, UnNot, P, Pat, PatEnum}; use ast::{PatIdent, PatLit, PatRange, PatRegion, PatStruct}; -use ast::{PatTup, PatBox, PatWild, PatWildMulti}; +use ast::{PatTup, PatBox, PatWild, PatWildMulti, PatWildSingle}; use ast::{BiRem, Required}; use ast::{RetStyle, Return, BiShl, BiShr, Stmt, StmtDecl}; use ast::{StmtExpr, StmtSemi, StmtMac, StructDef, StructField}; @@ -2822,7 +2822,7 @@ impl<'a> Parser<'a> { if self.token == token::COMMA || self.token == token::RBRACKET { slice = Some(box(GC) ast::Pat { id: ast::DUMMY_NODE_ID, - node: PatWildMulti, + node: PatWild(PatWildMulti), span: self.span, }) } else { @@ -2920,7 +2920,7 @@ impl<'a> Parser<'a> { // parse _ token::UNDERSCORE => { self.bump(); - pat = PatWild; + pat = PatWild(PatWildSingle); hi = self.last_span.hi; return box(GC) ast::Pat { id: ast::DUMMY_NODE_ID, diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 095dca66164..ab0269f807a 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1732,8 +1732,8 @@ impl<'a> State<'a> { /* Pat isn't normalized, but the beauty of it is that it doesn't matter */ match pat.node { - ast::PatWild => try!(word(&mut self.s, "_")), - ast::PatWildMulti => try!(word(&mut self.s, "..")), + ast::PatWild(ast::PatWildSingle) => try!(word(&mut self.s, "_")), + ast::PatWild(ast::PatWildMulti) => try!(word(&mut self.s, "..")), ast::PatIdent(binding_mode, ref path1, sub) => { match binding_mode { ast::BindByRef(mutbl) => { @@ -1822,7 +1822,7 @@ impl<'a> State<'a> { for p in slice.iter() { if !before.is_empty() { try!(self.word_space(",")); } match **p { - ast::Pat { node: ast::PatWildMulti, .. } => { + ast::Pat { node: ast::PatWild(ast::PatWildMulti), .. } => { // this case is handled by print_pat } _ => try!(word(&mut self.s, "..")), diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 371fae53b41..733c4bfc2b0 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -481,7 +481,7 @@ pub fn walk_pat<E: Clone, V: Visitor<E>>(visitor: &mut V, pattern: &Pat, env: E) visitor.visit_expr(&**lower_bound, env.clone()); visitor.visit_expr(&**upper_bound, env) } - PatWild | PatWildMulti => (), + PatWild(_) => (), PatVec(ref prepattern, ref slice_pattern, ref postpatterns) => { for prepattern in prepattern.iter() { visitor.visit_pat(&**prepattern, env.clone()) |
