This commit is contained in:
minish 2025-07-17 20:56:27 -04:00
parent 40bf9bc992
commit 1510dee5ae
Signed by: min
SSH Key Fingerprint: SHA256:mf+pUTmK92Y57BuCjlkBdd82LqztTfDCQIUp0fCKABc
2 changed files with 13 additions and 11 deletions

View File

@ -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),* ) )? )
)
);
)*

View File

@ -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
}