diff options
| author | Philipp A | 2018-11-24 17:03:04 +0100 | 
|---|---|---|
| committer | Philipp A | 2018-11-24 17:03:04 +0100 | 
| commit | cba80480e22d8286ea468826045aa43dfa39a1ba (patch) | |
| tree | 37440f91ed572b52d8e50f4fdab8af1aa47e2039 /src/document_tree/element_categories.rs | |
| parent | 292103bf9576d47afd9330f26a19dcea7217555c (diff) | |
| download | rust-rst-cba80480e22d8286ea468826045aa43dfa39a1ba.tar.bz2 | |
Fixed up conversion
Diffstat (limited to 'src/document_tree/element_categories.rs')
| -rw-r--r-- | src/document_tree/element_categories.rs | 42 | 
1 files changed, 25 insertions, 17 deletions
| diff --git a/src/document_tree/element_categories.rs b/src/document_tree/element_categories.rs index 1cf259d..5d0cecf 100644 --- a/src/document_tree/element_categories.rs +++ b/src/document_tree/element_categories.rs @@ -20,24 +20,33 @@ pub trait HasChildren<C> {  	}  } -macro_rules! synonymous_enum { -	( $name:ident : $super1:ident + $super2:ident { $( $entry:ident ),* $(,)* } ) => { -		synonymous_enum!($name: $super1 { $( $entry, )* }); -		$( impl Into<$super2> for $entry { -			fn into(self) -> $super2 { -				$super2::$super1($name::$entry(self).into()) +macro_rules! impl_into { +	([ $( ($subentry:tt, $supcat:tt), )+ ]) => { +		$( impl_into!($subentry => $supcat); )+ +	}; +	( ($subcat:ident :: $entry:ident) => $supcat:ident ) => { +		impl Into<$supcat> for $entry { +			fn into(self) -> $supcat { +				$supcat::$subcat($subcat::$entry(self))  			} -		} )* +		}  	}; -	( $name:ident : $super:ident { $( $entry:ident ),* $(,)* } ) => { -		synonymous_enum!($name { $( $entry, )* }); -		$( impl Into<$super> for $entry { -			fn into(self) -> $super { -				$super::$name($name::$entry(self).into()) +} + +macro_rules! synonymous_enum { +	( $subcat:ident : $($supcat:ident),+ ; $midcat:ident : $supsupcat:ident { $($entry:ident),+ $(,)* } ) => { +		synonymous_enum!($subcat : $( $supcat ),+ , $midcat { $($entry,)* }); +		$( impl Into<$supsupcat> for $entry { +			fn into(self) -> $supsupcat { +				$supsupcat::$midcat($midcat::$subcat($subcat::$entry(self)))  			} -		} )* +		} )+ +	}; +	( $subcat:ident : $($supcat:ident),+ { $($entry:ident),+ $(,)* } ) => { +		synonymous_enum!($subcat { $( $entry, )* }); +		cartesian!(impl_into, [ $( ($subcat::$entry) ),+ ], [ $($supcat),+ ]);  	}; -	( $name:ident { $( $entry:ident ),* $(,)* } ) => { +	( $name:ident { $( $entry:ident ),+ $(,)* } ) => {  		#[derive(Serialize)]  		pub enum $name {  			$( $entry($entry), )* @@ -61,8 +70,7 @@ macro_rules! synonymous_enum {  synonymous_enum!(StructuralSubElement { Title, Subtitle, Decoration, Docinfo, SubStructure });  synonymous_enum!(SubStructure: StructuralSubElement { Topic, Sidebar, Transition, Section, BodyElement }); -//TODO: also implement into: SubTopic, SubSidebar, SubBlockQuote, SubFootnote, SubFigure -synonymous_enum!(BodyElement: SubStructure + StructuralSubElement { +synonymous_enum!(BodyElement: SubTopic, SubSidebar, SubBlockQuote, SubFootnote, SubFigure; SubStructure: StructuralSubElement {  	//Simple  	Paragraph, LiteralBlock, DoctestBlock, MathBlock, Rubric, SubstitutionDefinition, Comment, Pending, Target, Raw, Image,  	//Compound @@ -95,7 +103,7 @@ synonymous_enum!(SubOption { OptionString, OptionArgument });  synonymous_enum!(SubLineBlock { LineBlock, Line });  synonymous_enum!(SubBlockQuote { Attribution, BodyElement });  synonymous_enum!(SubFootnote { Label, BodyElement }); -synonymous_enum!(SubFigure { Image, Caption, Legend, BodyElement }); +synonymous_enum!(SubFigure { Caption, Legend, BodyElement });  #[cfg(test)]  mod test { | 
