temp commit

This commit is contained in:
2025-07-12 00:46:10 +02:00
parent 1868f1a506
commit fe89188c4b
60 changed files with 1536 additions and 709 deletions

View File

@@ -7,7 +7,9 @@ use orchid_extension::lexer::LexerObj;
use orchid_extension::parser::ParserObj;
use orchid_extension::system::{System, SystemCard};
use orchid_extension::system_ctor::SystemCtor;
use orchid_extension::tree::GenItem;
use orchid_extension::tree::GenMember;
use crate::macros::mactree_lexer::MacTreeLexer;
#[derive(Default)]
pub struct MacroSystem;
@@ -26,7 +28,7 @@ impl SystemCard for MacroSystem {
impl System for MacroSystem {
async fn request(_: ExtReq<'_>, req: Self::Req) -> Receipt<'_> { match req {} }
fn vfs() -> orchid_extension::fs::DeclFs { DeclFs::Mod(&[]) }
fn lexers() -> Vec<LexerObj> { vec![] }
fn lexers() -> Vec<LexerObj> { vec![&MacTreeLexer] }
fn parsers() -> Vec<ParserObj> { vec![] }
fn env() -> Vec<GenItem> { vec![] }
fn env() -> Vec<GenMember> { vec![] }
}

View File

@@ -1,15 +1,15 @@
use std::borrow::Cow;
use std::fmt::Display;
use std::rc::Rc;
use futures::future::join_all;
use orchid_api::Paren;
use orchid_base::error::OrcErrv;
use orchid_base::format::{FmtCtx, FmtUnit, Format, Variants};
use orchid_base::interner::Tok;
use orchid_base::location::Pos;
use orchid_base::name::Sym;
use orchid_base::tl_cache;
use orchid_base::tree::Ph;
use orchid_extension::atom::{Atomic, MethodSetBuilder};
use orchid_extension::atom::Atomic;
use orchid_extension::atom_owned::{OwnedAtom, OwnedVariant};
use orchid_extension::expr::Expr;
@@ -62,7 +62,7 @@ impl Format for MacTok {
},
[mtreev_fmt(body, c).await],
),
Self::Slot => format!("SLOT").into(),
Self::Slot => "SLOT".into(),
}
}
}
@@ -73,3 +73,26 @@ pub async fn mtreev_fmt<'b>(
) -> FmtUnit {
FmtUnit::sequence(" ", None, join_all(v.into_iter().map(|t| t.print(c))).await)
}
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct Ph {
pub name: Tok<String>,
pub kind: PhKind,
}
impl Display for Ph {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.kind {
PhKind::Scalar => write!(f, "${}", self.name),
PhKind::Vector { at_least_one: false, priority: 0 } => write!(f, "..${}", self.name),
PhKind::Vector { at_least_one: true, priority: 0 } => write!(f, "...${}", self.name),
PhKind::Vector { at_least_one: false, priority } => write!(f, "..${}:{priority}", self.name),
PhKind::Vector { at_least_one: true, priority } => write!(f, "...${}:{priority}", self.name),
}
}
}
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
pub enum PhKind {
Scalar,
Vector { at_least_one: bool, priority: u8 },
}

View File

@@ -3,13 +3,9 @@ use std::rc::Rc;
use futures::FutureExt;
use orchid_base::error::{OrcRes, mk_errv};
use orchid_base::location::Pos;
use orchid_base::parse::name_start;
use orchid_base::tokens::PARENS;
use orchid_extension::atom::AtomicFeatures;
use orchid_extension::gen_expr::atom;
use orchid_extension::lexer::{LexContext, Lexer, err_not_applicable};
use orchid_extension::tree::{GenTok, GenTokTree};
use orchid_extension::tree::{GenTok, GenTokTree, x_tok};
use crate::macros::mactree::{MacTok, MacTree};
@@ -17,15 +13,14 @@ use crate::macros::mactree::{MacTok, MacTree};
pub struct MacTreeLexer;
impl Lexer for MacTreeLexer {
const CHAR_FILTER: &'static [RangeInclusive<char>] = &['\''..='\''];
async fn lex<'a>(tail: &'a str, ctx: &'a LexContext<'a>) -> OrcRes<(&'a str, GenTokTree<'a>)> {
async fn lex<'a>(tail: &'a str, ctx: &'a LexContext<'a>) -> OrcRes<(&'a str, GenTokTree)> {
let Some(tail2) = tail.strip_prefix('\'') else {
return Err(err_not_applicable(ctx.i).await.into());
return Err(err_not_applicable(ctx.i()).await.into());
};
let tail3 = tail2.trim_start();
return match mac_tree(tail3, ctx).await {
Ok((tail4, mactree)) =>
Ok((tail4, GenTok::X(mactree.factory()).at(ctx.pos(tail)..ctx.pos(tail4)))),
Err(e) => Ok((tail2, GenTok::Bottom(e).at(ctx.tok_ran(1, tail2)))),
Ok((tail4, mactree)) => Ok((tail4, x_tok(mactree).at(ctx.pos_tt(tail, tail4)))),
Err(e) => Ok((tail2, GenTok::Bottom(e).at(ctx.pos_lt(1, tail2)))),
};
async fn mac_tree<'a>(tail: &'a str, ctx: &'a LexContext<'a>) -> OrcRes<(&'a str, MacTree)> {
for (lp, rp, paren) in PARENS {
@@ -35,14 +30,14 @@ impl Lexer for MacTreeLexer {
let tail2 = body_tail.trim();
if let Some(tail3) = tail2.strip_prefix(*rp) {
break Ok((tail3, MacTree {
pos: Pos::Range(ctx.pos(tail)..ctx.pos(tail3)),
pos: ctx.pos_tt(tail, tail3).pos(),
tok: Rc::new(MacTok::S(*paren, items)),
}));
} else if tail2.is_empty() {
return Err(mk_errv(
ctx.i.i("Unclosed block").await,
ctx.i().i("Unclosed block").await,
format!("Expected closing {rp}"),
[Pos::Range(ctx.tok_ran(1, tail)).into()],
[ctx.pos_lt(1, tail)],
));
}
let (new_tail, new_item) = mac_tree(tail2, ctx).boxed_local().await?;
@@ -53,11 +48,13 @@ impl Lexer for MacTreeLexer {
const INTERPOL: &[&str] = &["$", "..$"];
for pref in INTERPOL {
let Some(code) = tail.strip_prefix(pref) else { continue };
todo!("Register parameter, and push this onto the argument stack held in the atom")
}
todo!("recursive lexer call");
return Err(mk_errv(
ctx.i.i("Expected token after '").await,
ctx.i().i("Expected token after '").await,
format!("Expected a token after ', found {tail:?}"),
[Pos::Range(ctx.tok_ran(1, tail)).into()],
[ctx.pos_lt(1, tail)],
));
}
}

View File

@@ -1,11 +1,10 @@
use itertools::Itertools;
use orchid_api::PhKind;
use orchid_base::interner::Tok;
use orchid_base::side::Side;
use orchid_base::tree::Ph;
use super::shared::{AnyMatcher, ScalMatcher, VecMatcher};
use super::vec_attrs::vec_attrs;
use crate::macros::mactree::{Ph, PhKind};
use crate::macros::{MacTok, MacTree};
pub type MaxVecSplit<'a> = (&'a [MacTree], (Tok<String>, u8, bool), &'a [MacTree]);
@@ -108,24 +107,22 @@ fn mk_scalar(pattern: &MacTree) -> ScalMatcher {
mod test {
use std::rc::Rc;
use orchid_api::PhKind;
use orchid_base::interner::Interner;
use orchid_base::location::SrcRange;
use orchid_base::sym;
use orchid_base::tokens::Paren;
use orchid_base::tree::Ph;
use test_executors::spin_on;
use super::mk_any;
use crate::macros::mactree::{Ph, PhKind};
use crate::macros::{MacTok, MacTree};
#[test]
fn test_scan() {
spin_on(async {
let i = Interner::new_master();
let ex = |tok: MacTok| async {
MacTree { tok: Rc::new(tok), pos: SrcRange::mock(&i).await.pos() }
};
let ex =
|tok: MacTok| async { MacTree { tok: Rc::new(tok), pos: SrcRange::mock(&i).await.pos() } };
let pattern = vec![
ex(MacTok::Ph(Ph {
kind: PhKind::Vector { priority: 0, at_least_one: false },

View File

@@ -2,11 +2,9 @@ use std::fmt;
use std::rc::Rc;
use itertools::Itertools;
use orchid_api::PhKind;
use orchid_base::interner::Interner;
use orchid_base::location::Pos;
use orchid_base::name::Sym;
use orchid_base::tree::Ph;
use super::any_match::any_match;
use super::build::{mk_any, mk_vec};
@@ -14,6 +12,7 @@ use super::shared::{AnyMatcher, VecMatcher};
use super::state::{MatchState, StateEntry};
use super::vec_attrs::vec_attrs;
use super::vec_match::vec_match;
use crate::macros::mactree::{Ph, PhKind};
use crate::macros::{MacTok, MacTree};
pub fn first_is_vec(pattern: &[MacTree]) -> bool { vec_attrs(pattern.first().unwrap()).is_some() }

View File

@@ -1,7 +1,6 @@
use orchid_api::PhKind;
use orchid_base::interner::Tok;
use orchid_base::tree::Ph;
use crate::macros::mactree::{Ph, PhKind};
use crate::macros::{MacTok, MacTree};
/// Returns the name, priority and at_least_one of the expression if it is