Skip to content

Commit

Permalink
Use $crate in recursive macro calls
Browse files Browse the repository at this point in the history
This makes it possible to use `ndarray::s![]` and `ndarray::azip!()`
without importing them with `macro_use` or `use`.
  • Loading branch information
jturner314 committed Nov 18, 2018
1 parent 44c7fbe commit 26b925c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
18 changes: 9 additions & 9 deletions src/slice.rs
Expand Up @@ -553,7 +553,7 @@ macro_rules! s(
#[allow(unsafe_code)]
unsafe {
$crate::SliceInfo::new_unchecked(
[$($stack)* s!(@convert r, $s)],
[$($stack)* $crate::s!(@convert r, $s)],
out_dim,
)
}
Expand All @@ -568,7 +568,7 @@ macro_rules! s(
#[allow(unsafe_code)]
unsafe {
$crate::SliceInfo::new_unchecked(
[$($stack)* s!(@convert r)],
[$($stack)* $crate::s!(@convert r)],
out_dim,
)
}
Expand All @@ -577,19 +577,19 @@ macro_rules! s(
};
// convert a..b;c into @convert(a..b, c), final item, trailing comma
(@parse $dim:expr, [$($stack:tt)*] $r:expr;$s:expr ,) => {
s![@parse $dim, [$($stack)*] $r;$s]
$crate::s![@parse $dim, [$($stack)*] $r;$s]
};
// convert a..b into @convert(a..b), final item, trailing comma
(@parse $dim:expr, [$($stack:tt)*] $r:expr ,) => {
s![@parse $dim, [$($stack)*] $r]
$crate::s![@parse $dim, [$($stack)*] $r]
};
// convert a..b;c into @convert(a..b, c)
(@parse $dim:expr, [$($stack:tt)*] $r:expr;$s:expr, $($t:tt)*) => {
match $r {
r => {
s![@parse
$crate::s![@parse
$crate::SliceNextDim::next_dim(&r, $dim),
[$($stack)* s!(@convert r, $s),]
[$($stack)* $crate::s!(@convert r, $s),]
$($t)*
]
}
Expand All @@ -599,9 +599,9 @@ macro_rules! s(
(@parse $dim:expr, [$($stack:tt)*] $r:expr, $($t:tt)*) => {
match $r {
r => {
s![@parse
$crate::s![@parse
$crate::SliceNextDim::next_dim(&r, $dim),
[$($stack)* s!(@convert r),]
[$($stack)* $crate::s!(@convert r),]
$($t)*
]
}
Expand All @@ -618,6 +618,6 @@ macro_rules! s(
($($t:tt)*) => {
// The extra `*&` is a workaround for this compiler bug:
// https://github.com/rust-lang/rust/issues/23014
&*&s![@parse ::std::marker::PhantomData::<$crate::Ix0>, [] $($t)*]
&*&$crate::s![@parse ::std::marker::PhantomData::<$crate::Ix0>, [] $($t)*]
};
);
22 changes: 11 additions & 11 deletions src/zip/zipmacro.rs
Expand Up @@ -85,11 +85,11 @@
macro_rules! azip {
// Build Zip Rule (index)
(@parse [index => $a:expr, $($aa:expr,)*] $t1:tt in $t2:tt) => {
azip!(@finish ($crate::Zip::indexed($a)) [$($aa,)*] $t1 in $t2)
$crate::azip!(@finish ($crate::Zip::indexed($a)) [$($aa,)*] $t1 in $t2)
};
// Build Zip Rule (no index)
(@parse [$a:expr, $($aa:expr,)*] $t1:tt in $t2:tt) => {
azip!(@finish ($crate::Zip::from($a)) [$($aa,)*] $t1 in $t2)
$crate::azip!(@finish ($crate::Zip::from($a)) [$($aa,)*] $t1 in $t2)
};
// Build Finish Rule (both)
(@finish ($z:expr) [$($aa:expr,)*] [$($p:pat,)+] in { $($t:tt)*}) => {
Expand All @@ -105,32 +105,32 @@ macro_rules! azip {
// parsing stack: [expressions] [patterns] (one per operand)
// index uses empty [] -- must be first
(@parse [] [] index $i:pat, $($t:tt)*) => {
azip!(@parse [index =>] [$i,] $($t)*);
$crate::azip!(@parse [index =>] [$i,] $($t)*);
};
(@parse [$($exprs:tt)*] [$($pats:tt)*] mut $x:ident ($e:expr) $($t:tt)*) => {
azip!(@parse [$($exprs)* $e,] [$($pats)* mut $x,] $($t)*);
$crate::azip!(@parse [$($exprs)* $e,] [$($pats)* mut $x,] $($t)*);
};
(@parse [$($exprs:tt)*] [$($pats:tt)*] mut $x:ident $($t:tt)*) => {
azip!(@parse [$($exprs)* &mut $x,] [$($pats)* mut $x,] $($t)*);
$crate::azip!(@parse [$($exprs)* &mut $x,] [$($pats)* mut $x,] $($t)*);
};
(@parse [$($exprs:tt)*] [$($pats:tt)*] , $($t:tt)*) => {
azip!(@parse [$($exprs)*] [$($pats)*] $($t)*);
$crate::azip!(@parse [$($exprs)*] [$($pats)*] $($t)*);
};
(@parse [$($exprs:tt)*] [$($pats:tt)*] ref $x:ident ($e:expr) $($t:tt)*) => {
azip!(@parse [$($exprs)* $e,] [$($pats)* $x,] $($t)*);
$crate::azip!(@parse [$($exprs)* $e,] [$($pats)* $x,] $($t)*);
};
(@parse [$($exprs:tt)*] [$($pats:tt)*] ref $x:ident $($t:tt)*) => {
azip!(@parse [$($exprs)* &$x,] [$($pats)* $x,] $($t)*);
$crate::azip!(@parse [$($exprs)* &$x,] [$($pats)* $x,] $($t)*);
};
(@parse [$($exprs:tt)*] [$($pats:tt)*] $x:ident ($e:expr) $($t:tt)*) => {
azip!(@parse [$($exprs)* $e,] [$($pats)* &$x,] $($t)*);
$crate::azip!(@parse [$($exprs)* $e,] [$($pats)* &$x,] $($t)*);
};
(@parse [$($exprs:tt)*] [$($pats:tt)*] $x:ident $($t:tt)*) => {
azip!(@parse [$($exprs)* &$x,] [$($pats)* &$x,] $($t)*);
$crate::azip!(@parse [$($exprs)* &$x,] [$($pats)* &$x,] $($t)*);
};
(@parse [$($exprs:tt)*] [$($pats:tt)*] $($t:tt)*) => { };
($($t:tt)*) => {
azip!(@parse [] [] $($t)*);
$crate::azip!(@parse [] [] $($t)*);
}
}

0 comments on commit 26b925c

Please sign in to comment.