diff options
| author | Philipp A | 2023-12-28 15:43:24 +0100 | 
|---|---|---|
| committer | GitHub | 2023-12-28 15:43:24 +0100 | 
| commit | 0f4f1a420cbcf263a9118ec9b288c95f1b59ade8 (patch) | |
| tree | 030abd05e8894e4e9c6775794f890180cf6c5e91 /document_tree/src/macro_util.rs | |
| parent | 38b1c488601cfc2479f02df555b135ef01aa5618 (diff) | |
| parent | 774dd4798aedc40b38c6480e9c47f34c482f12d0 (diff) | |
| download | rust-rst-0f4f1a420cbcf263a9118ec9b288c95f1b59ade8.tar.bz2 | |
Merge branch 'main' into allow-rst-to-read-from-stdin
Diffstat (limited to 'document_tree/src/macro_util.rs')
| -rw-r--r-- | document_tree/src/macro_util.rs | 63 | 
1 files changed, 31 insertions, 32 deletions
| diff --git a/document_tree/src/macro_util.rs b/document_tree/src/macro_util.rs index dcf3725..e370011 100644 --- a/document_tree/src/macro_util.rs +++ b/document_tree/src/macro_util.rs @@ -1,42 +1,41 @@  macro_rules! cartesian_impl { -	($out:tt [] $b:tt $init_b:tt $submacro:tt) => { -		$submacro!{$out} -	}; -	($out:tt [$a:tt, $($at:tt)*] [] $init_b:tt $submacro:tt) => { -		cartesian_impl!{$out [$($at)*] $init_b $init_b $submacro} -	}; -	([$($out:tt)*] [$a:tt, $($at:tt)*] [$b:tt, $($bt:tt)*] $init_b:tt $submacro:tt) => { -		cartesian_impl!{[$($out)* ($a, $b),] [$a, $($at)*] [$($bt)*] $init_b $submacro} -	}; +    ($out:tt [] $b:tt $init_b:tt $submacro:tt) => { +        $submacro!{$out} +    }; +    ($out:tt [$a:tt, $($at:tt)*] [] $init_b:tt $submacro:tt) => { +        cartesian_impl!{$out [$($at)*] $init_b $init_b $submacro} +    }; +    ([$($out:tt)*] [$a:tt, $($at:tt)*] [$b:tt, $($bt:tt)*] $init_b:tt $submacro:tt) => { +        cartesian_impl!{[$($out)* ($a, $b),] [$a, $($at)*] [$($bt)*] $init_b $submacro} +    };  }  macro_rules! cartesian { -	( $submacro:tt, [$($a:tt)*], [$($b:tt)*]) => { -		cartesian_impl!{[] [$($a)*,] [$($b)*,] [$($b)*,] $submacro} -	}; +    ( $submacro:tt, [$($a:tt)*], [$($b:tt)*]) => { +        cartesian_impl!{[] [$($a)*,] [$($b)*,] [$($b)*,] $submacro} +    };  } -  #[cfg(test)]  mod tests { -	macro_rules! print_cartesian { -		( [ $(($a1:tt, $a2:tt)),* , ] ) => { -			fn test_f(x:i64, y:i64) -> Result<(i64, i64), ()> { -				match (x, y) { -				$( -					($a1, $a2) => { Ok(($a1, $a2)) } -				)* -				_ => { Err(()) } -				} -			} -		}; -	} +    macro_rules! print_cartesian { +        ( [ $(($a1:tt, $a2:tt)),* , ] ) => { +            fn test_f(x:i64, y:i64) -> Result<(i64, i64), ()> { +                match (x, y) { +                $( +                    ($a1, $a2) => { Ok(($a1, $a2)) } +                )* +                _ => { Err(()) } +                } +            } +        }; +    } -	#[test] -	fn print_cartesian() { -		cartesian!(print_cartesian, [1, 2, 3], [4, 5, 6]); -		assert_eq!(test_f(1, 4), Ok((1, 4))); -		assert_eq!(test_f(1, 3), Err(())); -		assert_eq!(test_f(3, 5), Ok((3, 5))); -	} +    #[test] +    fn print_cartesian() { +        cartesian!(print_cartesian, [1, 2, 3], [4, 5, 6]); +        assert_eq!(test_f(1, 4), Ok((1, 4))); +        assert_eq!(test_f(1, 3), Err(())); +        assert_eq!(test_f(3, 5), Ok((3, 5))); +    }  } | 
