Skip to content

Commit

Permalink
fix: apply bounds correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
kayagokalp committed Jun 24, 2024
1 parent 32523d5 commit 71cec14
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,24 @@ define_language! {
**/
#[macro_export]
macro_rules! define_language {
($(#[$meta:meta])* $vis:vis enum $name:ident $(<$($gen:ident $(: $bound:ident $(+ $bounds:ident)*)?),+>)? { $($variants:tt)* }) => {
($(#[$meta:meta])* $vis:vis enum $name:ident $(<$($gen:ident $(: $bound:tt $(+ $bounds:tt)*)?),+>)? { $($variants:tt)* }) => {
$crate::__define_language!($(#[$meta])* $vis enum $name $(<$($gen $(: $bound $(+ $bounds)*)?),+>)? { $($variants)* } -> {} {} {} {} {} {});
};
}

#[doc(hidden)]
#[macro_export]
macro_rules! __define_language {
// Final rule to generate the enum and implementations
($(#[$meta:meta])* $vis:vis enum $name:ident $(<$($gen:ident $(: $bound:ident $(+ $bounds:ident)*)?),+>)? {} ->
// Rule for the end of the enum definition
($(#[$meta:meta])* $vis:vis enum $name:ident $(<$($gen:ident $(: $bound:tt $(+ $bounds:tt)*)?),+>)? {} ->
$decl:tt {$($matches:tt)*} $children:tt $children_mut:tt
$display:tt {$($from_op:tt)*}
) => {
$(#[$meta])*
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)]
$vis enum $name $(<$($gen $(: $bound $(+ $bounds)*)?),+>)? $decl

impl $(<$($gen $(: $bound $(+ $bounds)*)?),+>)? $crate::Language for $name $(<$($gen),+>)? {
impl<$($($gen $(: $bound $(+ $bounds)*)?),+)? > $crate::Language for $name $(<$($gen),+>)? {
type Discriminant = std::mem::Discriminant<Self>;

#[inline(always)]
Expand All @@ -99,13 +99,13 @@ macro_rules! __define_language {
fn children_mut(&mut self) -> &mut [Id] { match self $children_mut }
}

impl $(<$($gen),+>)? ::std::fmt::Display for $name $(<$($gen),+>)? {
impl<$($($gen $(: $bound $(+ $bounds)*)?),+)? > ::std::fmt::Display for $name $(<$($gen),+>)? {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match (self, f) $display
}
}

impl $(<$($gen),+>)? $crate::FromOp for $name $(<$($gen),+>)? {
impl<$($($gen $(: $bound $(+ $bounds)*)?),+)? > $crate::FromOp for $name $(<$($gen),+>)? {
type Error = $crate::FromOpError;

fn from_op(op: &str, children: ::std::vec::Vec<$crate::Id>) -> ::std::result::Result<Self, Self::Error> {
Expand All @@ -118,7 +118,7 @@ macro_rules! __define_language {
};

// Rule to handle string variants with no children
($(#[$meta:meta])* $vis:vis enum $name:ident $(<$($gen:ident $(: $bound:ident $(+ $bounds:ident)*)?),+>)?
($(#[$meta:meta])* $vis:vis enum $name:ident $(<$($gen:ident $(: $bound:tt $(+ $bounds:tt)*)?),+>)?
{
$string:literal = $variant:ident,
$($variants:tt)*
Expand All @@ -139,7 +139,7 @@ macro_rules! __define_language {
};

// Rule to handle string variants with an array of child Ids
($(#[$meta:meta])* $vis:vis enum $name:ident $(<$($gen:ident $(: $bound:ident $(+ $bounds:ident)*)?),+>)?
($(#[$meta:meta])* $vis:vis enum $name:ident $(<$($gen:ident $(: $bound:tt $(+ $bounds:tt)*)?),+>)?
{
$string:literal = $variant:ident ($ids:ty),
$($variants:tt)*
Expand All @@ -164,7 +164,7 @@ macro_rules! __define_language {
};

// Rule to handle data variants with a single field
($(#[$meta:meta])* $vis:vis enum $name:ident $(<$($gen:ident $(: $bound:ident $(+ $bounds:ident)*)?),+>)?
($(#[$meta:meta])* $vis:vis enum $name:ident $(<$($gen:ident $(: $bound:tt $(+ $bounds:tt)*)?),+>)?
{
$variant:ident ($data:ty),
$($variants:tt)*
Expand All @@ -185,7 +185,7 @@ macro_rules! __define_language {
};

// Rule to handle data variants with a data field and an array of child Ids
($(#[$meta:meta])* $vis:vis enum $name:ident $(<$($gen:ident $(: $bound:ident $(+ $bounds:ident)*)?),+>)?
($(#[$meta:meta])* $vis:vis enum $name:ident $(<$($gen:ident $(: $bound:tt $(+ $bounds:tt)*)?),+>)?
{
$variant:ident ($data:ty, $ids:ty),
$($variants:tt)*
Expand Down

0 comments on commit 71cec14

Please sign in to comment.