Files
orchid/orchid-std/src/macros/macro_system.rs
Lawrence Bethlenfalvy 0909524dee
Some checks failed
Rust / build (push) Failing after 3m52s
Compiles again after command subsystem
terrified to start testing
2026-03-27 23:50:58 +01:00

78 lines
2.3 KiB
Rust

use never::Never;
use orchid_base::{Receipt, ReqHandle, Sym, sym};
use orchid_extension::tree::{GenMember, merge_trivial};
use orchid_extension::{
AtomOps, AtomicFeatures, LexerObj, ParserObj, System, SystemCard, SystemCtor, SystemHandle,
};
use crate::macros::instantiate_tpl::InstantiateTplCall;
use crate::macros::let_line::LetLine;
use crate::macros::macro_lib::gen_macro_lib;
use crate::macros::macro_line::MacroLine;
use crate::macros::macro_value::Macro;
use crate::macros::mactree_lexer::MacTreeLexer;
use crate::macros::match_macros::{MatcherAtom, gen_match_macro_lib};
use crate::macros::ph_lexer::{PhAtom, PhLexer};
use crate::macros::stdlib::gen_std_macro_lib;
use crate::macros::utils::MacroBodyArgCollector;
use crate::{MacTree, StdSystem};
#[derive(Debug, Default)]
pub struct MacroSystem;
impl SystemCtor for MacroSystem {
type Deps = StdSystem;
type Instance = MacroSystemInst;
type Card = Self;
const NAME: &'static str = "orchid::macros";
const VERSION: f64 = 0.00_01;
fn inst(&self, std: SystemHandle<StdSystem>) -> Self::Instance { MacroSystemInst { _std: std } }
}
impl SystemCard for MacroSystem {
type Ctor = Self;
type Req = Never;
fn atoms() -> impl IntoIterator<Item = Option<Box<dyn AtomOps>>> {
[
Some(InstantiateTplCall::ops()),
Some(MacTree::ops()),
Some(Macro::ops()),
Some(PhAtom::ops()),
Some(MacroBodyArgCollector::ops()),
Some(MatcherAtom::ops()),
]
}
}
#[derive(Debug)]
pub struct MacroSystemInst {
_std: SystemHandle<StdSystem>,
}
impl System for MacroSystemInst {
type Ctor = MacroSystem;
async fn request<'a>(&self, _: Box<dyn ReqHandle<'a> + 'a>, req: Never) -> Receipt<'a> {
match req {}
}
async fn prelude(&self) -> Vec<Sym> {
vec![
sym!(macros::common::+),
sym!(macros::common::*),
sym!(macros::common::,),
sym!(macros::common::;),
sym!(macros::common::..),
sym!(macros::common::_),
sym!(macros::common::=),
sym!(macros::common::.),
sym!(std::tuple::t),
sym!(std::record::r),
sym!(pattern::match),
sym!(pattern::ref),
sym!(pattern::=>),
sym!(std::fn::[|>]),
]
}
fn lexers(&self) -> Vec<LexerObj> { vec![&MacTreeLexer, &PhLexer] }
fn parsers(&self) -> Vec<ParserObj> { vec![&LetLine, &MacroLine] }
async fn env(&self) -> Vec<GenMember> {
merge_trivial([gen_macro_lib().await, gen_std_macro_lib().await, gen_match_macro_lib().await])
}
}