@@ -6,12 +6,38 @@ use syntax::SmolStr;
6
6
7
7
use crate :: { tt_iter:: TtIter , ParseError } ;
8
8
9
- pub ( crate ) fn parse_template ( template : & tt:: Subtree ) -> Result < Vec < Op > , ParseError > {
10
- parse_inner ( template, Mode :: Template ) . into_iter ( ) . collect ( )
11
- }
9
+ /// Consider
10
+ ///
11
+ /// ```
12
+ /// macro_rules! an_macro {
13
+ /// ($x:expr + $y:expr) => ($y * $x)
14
+ /// }
15
+ /// ```
16
+ ///
17
+ /// Stuff to the left of `=>` is a [`MetaTemplate`] pattern (which is matched
18
+ /// with input).
19
+ ///
20
+ /// Stuff to the right is a [`MetaTemplate`] template which is used to produce
21
+ /// output.
22
+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
23
+ pub ( crate ) struct MetaTemplate ( pub ( crate ) Vec < Op > ) ;
24
+
25
+ impl MetaTemplate {
26
+ pub ( crate ) fn parse_pattern ( pattern : & tt:: Subtree ) -> Result < MetaTemplate , ParseError > {
27
+ let ops =
28
+ parse_inner ( pattern, Mode :: Pattern ) . into_iter ( ) . collect :: < Result < _ , ParseError > > ( ) ?;
29
+ Ok ( MetaTemplate ( ops) )
30
+ }
31
+
32
+ pub ( crate ) fn parse_template ( template : & tt:: Subtree ) -> Result < MetaTemplate , ParseError > {
33
+ let ops =
34
+ parse_inner ( template, Mode :: Template ) . into_iter ( ) . collect :: < Result < _ , ParseError > > ( ) ?;
35
+ Ok ( MetaTemplate ( ops) )
36
+ }
12
37
13
- pub ( crate ) fn parse_pattern ( pattern : & tt:: Subtree ) -> Result < Vec < Op > , ParseError > {
14
- parse_inner ( pattern, Mode :: Pattern ) . into_iter ( ) . collect ( )
38
+ pub ( crate ) fn iter ( & self ) -> impl Iterator < Item = & Op > {
39
+ self . 0 . iter ( )
40
+ }
15
41
}
16
42
17
43
#[ derive( Clone , Debug , PartialEq , Eq ) ]
@@ -36,15 +62,6 @@ pub(crate) enum Separator {
36
62
Puncts ( SmallVec < [ tt:: Punct ; 3 ] > ) ,
37
63
}
38
64
39
- #[ derive( Clone , Debug , PartialEq , Eq ) ]
40
- pub ( crate ) struct MetaTemplate ( pub ( crate ) Vec < Op > ) ;
41
-
42
- impl MetaTemplate {
43
- pub ( crate ) fn iter ( & self ) -> impl Iterator < Item = & Op > {
44
- self . 0 . iter ( )
45
- }
46
- }
47
-
48
65
// Note that when we compare a Separator, we just care about its textual value.
49
66
impl PartialEq for Separator {
50
67
fn eq ( & self , other : & Separator ) -> bool {
0 commit comments