@@ -6,12 +6,38 @@ use syntax::SmolStr;
66
77use crate :: { tt_iter:: TtIter , ParseError } ;
88
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+ }
1237
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+ }
1541}
1642
1743#[ derive( Clone , Debug , PartialEq , Eq ) ]
@@ -36,15 +62,6 @@ pub(crate) enum Separator {
3662 Puncts ( SmallVec < [ tt:: Punct ; 3 ] > ) ,
3763}
3864
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-
4865// Note that when we compare a Separator, we just care about its textual value.
4966impl PartialEq for Separator {
5067 fn eq ( & self , other : & Separator ) -> bool {
0 commit comments