New plans for macros

About to move them completely to stdlib
This commit is contained in:
2024-08-18 22:57:06 +02:00
parent 11951ede43
commit 3a63894de2
78 changed files with 2557 additions and 1980 deletions

View File

@@ -1,7 +1,8 @@
use std::fmt::Display;
use orchid_api::tree::{Paren, Placeholder, PlaceholderKind};
pub use api::Paren;
use crate::api;
use crate::interner::{deintern, Tok};
pub const PARENS: &[(char, char, Paren)] =
@@ -10,24 +11,24 @@ pub const PARENS: &[(char, char, Paren)] =
#[derive(Clone, Debug)]
pub struct OwnedPh {
pub name: Tok<String>,
pub kind: PlaceholderKind,
pub kind: api::PlaceholderKind,
}
impl OwnedPh {
pub fn to_api(&self) -> Placeholder {
Placeholder { name: self.name.marker(), kind: self.kind.clone() }
pub fn to_api(&self) -> api::Placeholder {
api::Placeholder { name: self.name.marker(), kind: self.kind.clone() }
}
pub fn from_api(ph: Placeholder) -> Self { Self { name: deintern(ph.name), kind: ph.kind } }
pub fn from_api(ph: api::Placeholder) -> Self { Self { name: deintern(ph.name), kind: ph.kind } }
}
impl Display for OwnedPh {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.kind {
PlaceholderKind::Name => write!(f, "$_{}", self.name),
PlaceholderKind::Scalar => write!(f, "${}", self.name),
PlaceholderKind::Vector { nz: false, prio: 0 } => write!(f, "..${}", self.name),
PlaceholderKind::Vector { nz: true, prio: 0 } => write!(f, "...${}", self.name),
PlaceholderKind::Vector { nz: false, prio } => write!(f, "..${}:{prio}", self.name),
PlaceholderKind::Vector { nz: true, prio } => write!(f, "...${}:{prio}", self.name),
api::PlaceholderKind::Name => write!(f, "$_{}", self.name),
api::PlaceholderKind::Scalar => write!(f, "${}", self.name),
api::PlaceholderKind::Vector { nz: false, prio: 0 } => write!(f, "..${}", self.name),
api::PlaceholderKind::Vector { nz: true, prio: 0 } => write!(f, "...${}", self.name),
api::PlaceholderKind::Vector { nz: false, prio } => write!(f, "..${}:{prio}", self.name),
api::PlaceholderKind::Vector { nz: true, prio } => write!(f, "...${}:{prio}", self.name),
}
}
}
}