Files
orchid/orchid-std/src/macros/macro_value.rs

49 lines
1.1 KiB
Rust

use std::borrow::Cow;
use std::rc::Rc;
use hashbrown::HashSet;
use never::Never;
use orchid_base::interner::Tok;
use orchid_base::name::Sym;
use orchid_extension::atom::Atomic;
use orchid_extension::atom_owned::{OwnedAtom, OwnedVariant};
use orchid_extension::system::SysCtx;
use crate::macros::rule::matcher::{NamedMatcher, PriodMatcher};
#[derive(Debug)]
pub struct MacroData {
pub module: Sym,
pub prio: Option<u64>,
pub rules: Vec<Rule>,
}
#[derive(Clone, Debug)]
pub struct Macro(pub Rc<MacroData>);
impl Macro {
pub async fn canonical_name(&self, ctx: &SysCtx) -> Sym {
self.0.module.suffix([self.0.rules[0].body_name.clone()], ctx.i()).await
}
}
#[derive(Debug)]
pub struct Rule {
pub pattern: Matcher,
pub glossary: HashSet<Sym>,
pub placeholders: Vec<Tok<String>>,
pub body_name: Tok<String>,
}
#[derive(Debug)]
pub enum Matcher {
Named(NamedMatcher),
Priod(PriodMatcher),
}
impl Atomic for Macro {
type Data = ();
type Variant = OwnedVariant;
}
impl OwnedAtom for Macro {
type Refs = Never;
async fn val(&self) -> Cow<'_, Self::Data> { Cow::Owned(()) }
}