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_export]
|
||||||
macro_rules! kinds {
|
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)]
|
#[derive(Debug)]
|
||||||
pub enum $b {
|
pub enum $base {
|
||||||
$( $v $( ( $($vty),* ) )?, )*
|
$( $v $( ( $($vty),* ) )?, )*
|
||||||
}
|
}
|
||||||
impl $crate::kind::Kind for $b {
|
impl $crate::kind::Kind for $base {
|
||||||
type Kinds = $k;
|
type Kinds = $kind;
|
||||||
|
|
||||||
fn kind(&self) -> $k {
|
fn kind(&self) -> $kind {
|
||||||
$k (std::mem::discriminant(self))
|
$kind(std::mem::discriminant(self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Clone, Copy)]
|
#[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)]
|
#[allow(non_upper_case_globals, dead_code)]
|
||||||
pub const $v: Self = $k (
|
pub const $v: Self = $kind (
|
||||||
std::mem::discriminant(
|
std::mem::discriminant(
|
||||||
&( $b::$v $( ( $($vval),* ) )? )
|
&( $base::$v $( ( $($vval),* ) )? )
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
)*
|
)*
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::fmt::Write;
|
||||||
|
|
||||||
use crate::parser::Expr;
|
use crate::parser::Expr;
|
||||||
|
|
||||||
pub fn display(e: Expr) {
|
pub fn display(e: Expr) {
|
||||||
|
@ -34,7 +36,7 @@ fn fmt_expr(e: Expr, depth: usize) -> String {
|
||||||
Expr::If(c, t, f) => {
|
Expr::If(c, t, f) => {
|
||||||
let mut result = format!("if ({}) ({})", fmt_expr(*c, depth), fmt_expr(*t, depth));
|
let mut result = format!("if ({}) ({})", fmt_expr(*c, depth), fmt_expr(*t, depth));
|
||||||
if let Some(f) = f {
|
if let Some(f) = f {
|
||||||
result.push_str(&format!(" else ({})", fmt_expr(*f, depth)));
|
let _ = write!(result, " else ({})", fmt_expr(*f, depth));
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue