Various progress, doesnt compile
Added prelude, made lambdas a single-token prefix like NS, made progress on implementations, removed const line type
This commit is contained in:
59
orchid-std/src/macros/let_line.rs
Normal file
59
orchid-std/src/macros/let_line.rs
Normal file
@@ -0,0 +1,59 @@
|
||||
use futures::future::LocalBoxFuture;
|
||||
use itertools::Itertools;
|
||||
use orchid_base::error::{OrcRes, mk_errv};
|
||||
use orchid_base::interner::Tok;
|
||||
use orchid_base::name::Sym;
|
||||
use orchid_base::parse::{Comment, ParseCtx, Parsed, expect_tok, token_errv, try_pop_no_fluff};
|
||||
use orchid_extension::gen_expr::GExpr;
|
||||
use orchid_extension::parser::{
|
||||
ConstCtx, GenSnippet, ParsCtx, ParsedLine, ParsedLineKind, ParsedMem, ParsedMemKind, Parser,
|
||||
};
|
||||
use substack::Substack;
|
||||
|
||||
type ExprGenerator =
|
||||
Box<dyn for<'a> FnOnce(ConstCtx, Substack<'a, Sym>) -> LocalBoxFuture<'a, GExpr>>;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct LetLine;
|
||||
impl Parser for LetLine {
|
||||
const LINE_HEAD: &'static str = "let";
|
||||
async fn parse<'a>(
|
||||
ctx: ParsCtx<'a>,
|
||||
exported: bool,
|
||||
comments: Vec<Comment>,
|
||||
line: GenSnippet<'a>,
|
||||
) -> OrcRes<Vec<ParsedLine>> {
|
||||
let Parsed { output: name_tok, tail } = try_pop_no_fluff(&ctx, line).await?;
|
||||
let Some(name) = name_tok.as_name() else {
|
||||
let err = token_errv(&ctx, name_tok, "Constant must have a name", |t| {
|
||||
format!("Expected a name but found {t}")
|
||||
});
|
||||
return Err(err.await);
|
||||
};
|
||||
let Parsed { tail, .. } = expect_tok(&ctx, tail, ctx.i().i("=").await).await?;
|
||||
fn do_tokv(line: GenSnippet<'_>) -> ExprGenerator {
|
||||
let first: ExprGenerator = if let Some((idx, arg)) =
|
||||
line.iter().enumerate().find_map(|(i, x)| Some((i, x.as_lambda()?)))
|
||||
{
|
||||
Box::new(move |ctx, stack| Box::pin(async move {
|
||||
let name = ctx.names([])
|
||||
}))
|
||||
} else {
|
||||
|
||||
};
|
||||
todo!()
|
||||
}
|
||||
let expr_generator = do_tokv(tail);
|
||||
Ok(vec![ParsedLine {
|
||||
comments,
|
||||
sr: line.sr(),
|
||||
kind: ParsedLineKind::Mem(ParsedMem {
|
||||
exported,
|
||||
name,
|
||||
kind: ParsedMemKind::cnst(async |ctx| expr_generator(ctx, Substack::Bottom).await),
|
||||
}),
|
||||
}])
|
||||
}
|
||||
}
|
||||
|
||||
fn update_names(tree: MacTree)
|
||||
Reference in New Issue
Block a user