Lexer test mode works

This commit is contained in:
2024-08-04 23:24:32 +02:00
parent 9d35ba8040
commit 11951ede43
36 changed files with 687 additions and 115 deletions

View File

@@ -1,7 +1,12 @@
use orchid_api::tree::{Placeholder, PlaceholderKind};
use std::fmt::Display;
use orchid_api::tree::{Paren, Placeholder, PlaceholderKind};
use crate::interner::{deintern, Tok};
pub const PARENS: &[(char, char, Paren)] =
&[('(', ')', Paren::Round), ('[', ']', Paren::Square), ('{', '}', Paren::Curly)];
#[derive(Clone, Debug)]
pub struct OwnedPh {
pub name: Tok<String>,
@@ -13,3 +18,16 @@ impl OwnedPh {
}
pub fn from_api(ph: 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),
}
}
}