@@ -138,43 +138,41 @@ pub enum Statement {
138138 Print ( Print ) ,
139139}
140140
141- /// A constant declaration.
142- #[ derive( Clone , Debug , PartialEq ) ]
143- pub struct Constant ( NamePos , ExpressionPos ) ;
144-
145- impl From < Constant > for ( NamePos , ExpressionPos ) {
146- fn from ( value : Constant ) -> Self {
147- ( value. 0 , value. 1 )
148- }
149- }
150-
151- impl < ' a > From < & ' a Constant > for ( & ' a NamePos , & ' a ExpressionPos ) {
152- fn from ( value : & ' a Constant ) -> Self {
153- ( & value. 0 , & value. 1 )
154- }
155- }
141+ macro_rules! bi_tuple {
142+ ( $( #[ $( $attrss: tt) * ] ) * $name: ident( $left: ty, $right: ty) ) => {
143+ $( #[ $( $attrss) * ] ) *
144+ #[ derive( Clone , Debug , PartialEq ) ]
145+ pub struct $name( $left, $right) ;
146+
147+ impl $name {
148+ pub fn new( left: $left, right: $right) -> Self {
149+ Self ( left, right)
150+ }
151+ }
156152
157- /// An assignment statement.
158- #[ derive( Clone , Debug , PartialEq ) ]
159- pub struct Assignment ( Expression , ExpressionPos ) ;
153+ impl From <$name> for ( $left, $right) {
154+ fn from( value: $name) -> Self {
155+ ( value. 0 , value. 1 )
156+ }
157+ }
160158
161- impl Assignment {
162- pub fn new ( left : Expression , right : ExpressionPos ) -> Self {
163- Self ( left, right)
164- }
159+ impl <' a> From <& ' a $name> for ( & ' a $left, & ' a $right) {
160+ fn from( value: & ' a $name) -> Self {
161+ ( & value. 0 , & value. 1 )
162+ }
163+ }
164+ } ;
165165}
166166
167- impl From < Assignment > for ( Expression , ExpressionPos ) {
168- fn from ( value : Assignment ) -> Self {
169- ( value. 0 , value. 1 )
170- }
171- }
167+ bi_tuple ! (
168+ /// A constant declaration.
169+ Constant ( NamePos , ExpressionPos )
170+ ) ;
172171
173- impl < ' a > From < & ' a Assignment > for ( & ' a Expression , & ' a ExpressionPos ) {
174- fn from ( value : & ' a Assignment ) -> Self {
175- ( & value. 0 , & value. 1 )
176- }
177- }
172+ bi_tuple ! (
173+ /// An assignment statement.
174+ Assignment ( Expression , ExpressionPos )
175+ ) ;
178176
179177/// A list of variables defined in a DIM statement.
180178#[ derive( Clone , Debug , PartialEq ) ]
0 commit comments