use std::fmt::Display;
use crate::{ast::Symbol, symbols};
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum DelimDir {
Left,
Right,
}
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum DelimKind {
Paren,
Bracket,
}
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Delimiter {
pub dir: DelimDir,
pub kind: DelimKind,
}
impl Display for Delimiter {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.get_symbol().unicode_repr)
}
}
impl Delimiter {
pub fn get_symbol(&self) -> Symbol {
match (self.dir, self.kind) {
(DelimDir::Left, DelimKind::Paren) => symbols::LEFT_PAR.clone(),
(DelimDir::Left, DelimKind::Bracket) => symbols::LEFT_BRACKET.clone(),
(DelimDir::Right, DelimKind::Paren) => symbols::RIGHT_PAR.clone(),
(DelimDir::Right, DelimKind::Bracket) => symbols::RIGHT_BRACKET.clone(),
}
}
}
pub static LPAR: Delimiter = Delimiter {
dir: DelimDir::Left,
kind: DelimKind::Paren,
};
pub static RPAR: Delimiter = Delimiter {
dir: DelimDir::Right,
kind: DelimKind::Paren,
};
pub static LBRACKET: Delimiter = Delimiter {
dir: DelimDir::Left,
kind: DelimKind::Bracket,
};
pub static RBRACKET: Delimiter = Delimiter {
dir: DelimDir::Right,
kind: DelimKind::Bracket,
};
pub static DELIMS: [Delimiter; 4] = [LPAR, RPAR, LBRACKET, RBRACKET];