First steps for the macro system
This commit is contained in:
@@ -4,6 +4,7 @@ use async_stream::stream;
|
||||
use futures::future::{LocalBoxFuture, join_all};
|
||||
use futures::{FutureExt, Stream, StreamExt, pin_mut};
|
||||
use itertools::Itertools;
|
||||
use never::Never;
|
||||
use orchid_api::ResolveNames;
|
||||
use orchid_base::error::{OrcRes, Reporter};
|
||||
use orchid_base::id_store::IdStore;
|
||||
@@ -12,7 +13,7 @@ use orchid_base::location::SrcRange;
|
||||
use orchid_base::name::Sym;
|
||||
use orchid_base::parse::{Comment, ParseCtx, Snippet};
|
||||
use orchid_base::reqnot::{ReqHandlish, Requester};
|
||||
use orchid_base::tree::ttv_into_api;
|
||||
use orchid_base::tree::{TokTree, Token, ttv_into_api};
|
||||
|
||||
use crate::api;
|
||||
use crate::expr::Expr;
|
||||
@@ -20,7 +21,9 @@ use crate::gen_expr::GExpr;
|
||||
use crate::system::{SysCtx, SysCtxEntry};
|
||||
use crate::tree::GenTokTree;
|
||||
|
||||
pub type GenSnippet<'a> = Snippet<'a, Expr, GExpr>;
|
||||
pub type PTok = Token<Expr, Never>;
|
||||
pub type PTokTree = TokTree<Expr, Never>;
|
||||
pub type PSnippet<'a> = Snippet<'a, Expr, Never>;
|
||||
|
||||
pub trait Parser: Send + Sync + Sized + Default + 'static {
|
||||
const LINE_HEAD: &'static str;
|
||||
@@ -28,7 +31,7 @@ pub trait Parser: Send + Sync + Sized + Default + 'static {
|
||||
ctx: ParsCtx<'a>,
|
||||
exported: bool,
|
||||
comments: Vec<Comment>,
|
||||
line: GenSnippet<'a>,
|
||||
line: PSnippet<'a>,
|
||||
) -> impl Future<Output = OrcRes<Vec<ParsedLine>>> + 'a;
|
||||
}
|
||||
|
||||
@@ -39,7 +42,7 @@ pub trait DynParser: Send + Sync + 'static {
|
||||
ctx: ParsCtx<'a>,
|
||||
exported: bool,
|
||||
comments: Vec<Comment>,
|
||||
line: GenSnippet<'a>,
|
||||
line: PSnippet<'a>,
|
||||
) -> LocalBoxFuture<'a, OrcRes<Vec<ParsedLine>>>;
|
||||
}
|
||||
|
||||
@@ -50,7 +53,7 @@ impl<T: Parser> DynParser for T {
|
||||
ctx: ParsCtx<'a>,
|
||||
exported: bool,
|
||||
comments: Vec<Comment>,
|
||||
line: GenSnippet<'a>,
|
||||
line: PSnippet<'a>,
|
||||
) -> LocalBoxFuture<'a, OrcRes<Vec<ParsedLine>>> {
|
||||
Box::pin(async move { Self::parse(ctx, exported, comments, line).await })
|
||||
}
|
||||
@@ -73,7 +76,7 @@ impl<'a> ParsCtx<'a> {
|
||||
}
|
||||
impl ParseCtx for ParsCtx<'_> {
|
||||
fn i(&self) -> &Interner { self.ctx.i() }
|
||||
fn reporter(&self) -> &Reporter { self.reporter }
|
||||
fn rep(&self) -> &Reporter { self.reporter }
|
||||
}
|
||||
|
||||
type BoxConstCallback = Box<dyn FnOnce(ConstCtx) -> LocalBoxFuture<'static, GExpr>>;
|
||||
@@ -174,26 +177,25 @@ pub struct ConstCtx {
|
||||
impl ConstCtx {
|
||||
pub fn names<'a>(
|
||||
&'a self,
|
||||
names: impl IntoIterator<Item = &'a Sym> + Clone + 'a,
|
||||
) -> impl Stream<Item = (Sym, Option<Sym>)> + 'a {
|
||||
names: impl IntoIterator<Item = &'a Sym> + 'a,
|
||||
) -> impl Stream<Item = Option<Sym>> + 'a {
|
||||
let resolve_names = ResolveNames {
|
||||
constid: self.constid,
|
||||
sys: self.ctx.sys_id(),
|
||||
names: names.clone().into_iter().map(|n| n.to_api()).collect_vec(),
|
||||
names: names.into_iter().map(|n| n.to_api()).collect_vec(),
|
||||
};
|
||||
stream! {
|
||||
let new_names = self.ctx.reqnot().request(resolve_names).await;
|
||||
for (name, name_opt) in names.into_iter().zip(new_names) {
|
||||
yield (name.clone(), match name_opt {
|
||||
for name_opt in self.ctx.reqnot().request(resolve_names).await {
|
||||
yield match name_opt {
|
||||
None => None,
|
||||
Some(name) => Some(Sym::from_api(name, self.ctx.i()).await)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pub async fn names_n<const N: usize>(&self, names: [&Sym; N]) -> [Option<Sym>; N] {
|
||||
let mut results = [const { None }; N];
|
||||
let names = self.names(names).enumerate().filter_map(|(i, n)| async move { Some((i, n.1?)) });
|
||||
let names = self.names(names).enumerate().filter_map(|(i, n)| async move { Some((i, n?)) });
|
||||
pin_mut!(names);
|
||||
while let Some((i, name)) = names.next().await {
|
||||
results[i] = Some(name);
|
||||
|
||||
Reference in New Issue
Block a user