cleanup
This commit is contained in:
parent
40bf9bc992
commit
1510dee5ae
20
src/kind.rs
20
src/kind.rs
|
@ -6,28 +6,28 @@ pub trait Kind {
|
|||
|
||||
#[macro_export]
|
||||
macro_rules! kinds {
|
||||
($b:ident, $k:ident, $( $v:ident $( ( $($vty:ty = $vval:expr),* ) )?),* $(,)?) => {
|
||||
($base:ident, $kind:ident, $( $v:ident $( ( $($vty:ty = $vval:expr),* ) )?),* $(,)?) => {
|
||||
#[derive(Debug)]
|
||||
pub enum $b {
|
||||
pub enum $base {
|
||||
$( $v $( ( $($vty),* ) )?, )*
|
||||
}
|
||||
impl $crate::kind::Kind for $b {
|
||||
type Kinds = $k;
|
||||
impl $crate::kind::Kind for $base {
|
||||
type Kinds = $kind;
|
||||
|
||||
fn kind(&self) -> $k {
|
||||
$k (std::mem::discriminant(self))
|
||||
fn kind(&self) -> $kind {
|
||||
$kind(std::mem::discriminant(self))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||
pub struct $k(std::mem::Discriminant<$b>);
|
||||
pub struct $kind(std::mem::Discriminant<$base>);
|
||||
|
||||
impl $k {
|
||||
impl $kind {
|
||||
$(
|
||||
#[allow(non_upper_case_globals, dead_code)]
|
||||
pub const $v: Self = $k (
|
||||
pub const $v: Self = $kind (
|
||||
std::mem::discriminant(
|
||||
&( $b::$v $( ( $($vval),* ) )? )
|
||||
&( $base::$v $( ( $($vval),* ) )? )
|
||||
)
|
||||
);
|
||||
)*
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::fmt::Write;
|
||||
|
||||
use crate::parser::Expr;
|
||||
|
||||
pub fn display(e: Expr) {
|
||||
|
@ -34,7 +36,7 @@ fn fmt_expr(e: Expr, depth: usize) -> String {
|
|||
Expr::If(c, t, f) => {
|
||||
let mut result = format!("if ({}) ({})", fmt_expr(*c, depth), fmt_expr(*t, depth));
|
||||
if let Some(f) = f {
|
||||
result.push_str(&format!(" else ({})", fmt_expr(*f, depth)));
|
||||
let _ = write!(result, " else ({})", fmt_expr(*f, depth));
|
||||
}
|
||||
result
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue