File tree Expand file tree Collapse file tree 3 files changed +36
-1
lines changed
branches/dist-snap/src/libsyntax/ext Expand file tree Collapse file tree 3 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ refs/heads/try: 1813e5aa1a03b0596b8de7abd1af31edf5d6098f
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
7
7
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8
8
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9
- refs/heads/dist-snap: 5fdd0e4b05979a0a01ca6c14e0510880d320250c
9
+ refs/heads/dist-snap: 00704ea33b98dc880d9ac1e4ae7f61b45e8e4330
10
10
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
11
11
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
12
12
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
Original file line number Diff line number Diff line change @@ -114,6 +114,10 @@ pub trait MacResult {
114
114
fn make_items ( & self ) -> Option < SmallVector < @ast:: Item > > {
115
115
None
116
116
}
117
+ /// Create a pattern.
118
+ fn make_pat ( & self ) -> Option < @ast:: Pat > {
119
+ None
120
+ }
117
121
118
122
/// Create a statement.
119
123
///
@@ -139,6 +143,20 @@ impl MacResult for MacExpr {
139
143
Some ( self . e )
140
144
}
141
145
}
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
+ }
142
160
/// A convenience type for macros that return a single item.
143
161
pub struct MacItem {
144
162
i : @ast:: Item
@@ -194,12 +212,24 @@ impl DummyResult {
194
212
span : sp,
195
213
}
196
214
}
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
+ }
197
224
}
198
225
199
226
impl MacResult for DummyResult {
200
227
fn make_expr ( & self ) -> Option < @ast:: Expr > {
201
228
Some ( DummyResult :: raw_expr ( self . span ) )
202
229
}
230
+ fn make_pat ( & self ) -> Option < @ast:: Pat > {
231
+ Some ( DummyResult :: raw_pat ( self . span ) )
232
+ }
203
233
fn make_items ( & self ) -> Option < SmallVector < @ast:: Item > > {
204
234
if self . expr_only {
205
235
None
Original file line number Diff line number Diff line change @@ -63,6 +63,11 @@ impl<'a> MacResult for ParserAnyMacro<'a> {
63
63
self . ensure_complete_parse ( true ) ;
64
64
Some ( ret)
65
65
}
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
+ }
66
71
fn make_items ( & self ) -> Option < SmallVector < @ast:: Item > > {
67
72
let mut ret = SmallVector :: zero ( ) ;
68
73
loop {
You can’t perform that action at this time.
0 commit comments