Skip to content

Commit 7950154

Browse files
author
Keegan McAllister
committed
---
yaml --- r: 152094 b: refs/heads/try2 c: 00704ea h: refs/heads/master v: v3
1 parent c45923c commit 7950154

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 5fdd0e4b05979a0a01ca6c14e0510880d320250c
8+
refs/heads/try2: 00704ea33b98dc880d9ac1e4ae7f61b45e8e4330
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libsyntax/ext/base.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ pub trait MacResult {
114114
fn make_items(&self) -> Option<SmallVector<@ast::Item>> {
115115
None
116116
}
117+
/// Create a pattern.
118+
fn make_pat(&self) -> Option<@ast::Pat> {
119+
None
120+
}
117121

118122
/// Create a statement.
119123
///
@@ -139,6 +143,20 @@ impl MacResult for MacExpr {
139143
Some(self.e)
140144
}
141145
}
146+
/// A convenience type for macros that return a single pattern.
147+
pub struct MacPat {
148+
p: @ast::Pat
149+
}
150+
impl MacPat {
151+
pub fn new(p: @ast::Pat) -> Box<MacResult> {
152+
box MacPat { p: p } as Box<MacResult>
153+
}
154+
}
155+
impl MacResult for MacPat {
156+
fn make_pat(&self) -> Option<@ast::Pat> {
157+
Some(self.p)
158+
}
159+
}
142160
/// A convenience type for macros that return a single item.
143161
pub struct MacItem {
144162
i: @ast::Item
@@ -194,12 +212,24 @@ impl DummyResult {
194212
span: sp,
195213
}
196214
}
215+
216+
/// A plain dummy pattern.
217+
pub fn raw_pat(sp: Span) -> @ast::Pat {
218+
@ast::Pat {
219+
id: ast::DUMMY_NODE_ID,
220+
node: ast::PatWild,
221+
span: sp,
222+
}
223+
}
197224
}
198225

199226
impl MacResult for DummyResult {
200227
fn make_expr(&self) -> Option<@ast::Expr> {
201228
Some(DummyResult::raw_expr(self.span))
202229
}
230+
fn make_pat(&self) -> Option<@ast::Pat> {
231+
Some(DummyResult::raw_pat(self.span))
232+
}
203233
fn make_items(&self) -> Option<SmallVector<@ast::Item>> {
204234
if self.expr_only {
205235
None

branches/try2/src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ impl<'a> MacResult for ParserAnyMacro<'a> {
6363
self.ensure_complete_parse(true);
6464
Some(ret)
6565
}
66+
fn make_pat(&self) -> Option<@ast::Pat> {
67+
let ret = self.parser.borrow_mut().parse_pat();
68+
self.ensure_complete_parse(false);
69+
Some(ret)
70+
}
6671
fn make_items(&self) -> Option<SmallVector<@ast::Item>> {
6772
let mut ret = SmallVector::zero();
6873
loop {

0 commit comments

Comments
 (0)