forked from Orchid/orchid
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:
@@ -62,8 +62,7 @@ pub fn recur<H: ExprRepr, X: ExtraTok>(
|
||||
tok @ (Token::BR | Token::Bottom(_) | Token::Comment(_) | Token::Name(_)) => tok,
|
||||
tok @ (Token::Handle(_) | Token::NewExpr(_)) => tok,
|
||||
Token::NS(n, b) => Token::NS(n, Box::new(recur(*b, f))),
|
||||
Token::LambdaHead(arg) =>
|
||||
Token::LambdaHead(arg.into_iter().map(|tt| recur(tt, f)).collect_vec()),
|
||||
Token::LambdaHead(arg) => Token::LambdaHead(Box::new(recur(*arg, f))),
|
||||
Token::S(p, b) => Token::S(p, b.into_iter().map(|tt| recur(tt, f)).collect_vec()),
|
||||
};
|
||||
TokTree { sr: range, tok }
|
||||
@@ -117,7 +116,7 @@ impl<H: ExprRepr, X: ExtraTok> TokTree<H, X> {
|
||||
NS(n => Tok::from_api(*n, i).await,
|
||||
b => Box::new(Self::from_api(b, hctx, xctx, src, i).boxed_local().await)),
|
||||
Bottom(e => OrcErrv::from_api(e, i).await),
|
||||
LambdaHead(arg => ttv_from_api(arg, hctx, xctx, src, i).await),
|
||||
LambdaHead(arg => Box::new(Self::from_api(arg, hctx, xctx, src, i).boxed_local().await)),
|
||||
Name(n => Tok::from_api(*n, i).await),
|
||||
S(*par, b => ttv_from_api(b, hctx, xctx, src, i).await),
|
||||
Comment(c.clone()),
|
||||
@@ -137,7 +136,7 @@ impl<H: ExprRepr, X: ExtraTok> TokTree<H, X> {
|
||||
NS(n.to_api(), b => Box::new(b.into_api(hctx, xctx).boxed_local().await)),
|
||||
Bottom(e.to_api()),
|
||||
Comment(c.clone()),
|
||||
LambdaHead(arg => ttv_into_api(arg, hctx, xctx).boxed_local().await),
|
||||
LambdaHead(arg => Box::new(arg.into_api(hctx, xctx).boxed_local().await)),
|
||||
Name(nn.to_api()),
|
||||
S(p, b => ttv_into_api(b, hctx, xctx).boxed_local().await),
|
||||
Handle(hand.into_api(hctx).await),
|
||||
@@ -153,18 +152,18 @@ impl<H: ExprRepr, X: ExtraTok> TokTree<H, X> {
|
||||
pub fn as_s(&self, par: Paren) -> Option<Snippet<'_, H, X>> {
|
||||
self.tok.as_s(par).map(|slc| Snippet::new(self, slc))
|
||||
}
|
||||
pub fn as_lambda(&self) -> Option<Snippet<'_, H, X>> {
|
||||
pub fn as_lambda(&self) -> Option<&Self> {
|
||||
match &self.tok {
|
||||
Token::LambdaHead(arg) => Some(Snippet::new(self, arg)),
|
||||
Token::LambdaHead(arg) => Some(&**arg),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
pub fn is_fluff(&self) -> bool { matches!(self.tok, Token::Comment(_) | Token::BR) }
|
||||
pub fn lambda(arg: Vec<Self>, mut body: Vec<Self>) -> Self {
|
||||
let arg_range = ttv_range(&arg).expect("Lambda with empty arg!");
|
||||
pub fn lambda(arg: Self, mut body: Vec<Self>) -> Self {
|
||||
let arg_range = arg.sr();
|
||||
let mut s_range = arg_range.clone();
|
||||
s_range.range.end = body.last().expect("Lambda with empty body!").sr.range.end;
|
||||
body.insert(0, Token::LambdaHead(arg).at(arg_range));
|
||||
body.insert(0, Token::LambdaHead(Box::new(arg)).at(arg_range));
|
||||
Token::S(Paren::Round, body).at(s_range)
|
||||
}
|
||||
pub fn sr(&self) -> SrcRange { self.sr.clone() }
|
||||
@@ -230,7 +229,7 @@ pub enum Token<H: ExprRepr, X: ExtraTok> {
|
||||
Comment(Rc<String>),
|
||||
/// The part of a lambda between `\` and `.` enclosing the argument. The body
|
||||
/// stretches to the end of the enclosing parens or the end of the const line
|
||||
LambdaHead(Vec<TokTree<H, X>>),
|
||||
LambdaHead(Box<TokTree<H, X>>),
|
||||
/// A binding, operator, or a segment of a namespaced::name
|
||||
Name(Tok<String>),
|
||||
/// A namespace prefix, like `my_ns::` followed by a token
|
||||
@@ -267,7 +266,7 @@ impl<H: ExprRepr, X: ExtraTok> Format for Token<H, X> {
|
||||
Self::Comment(c) => format!("--[{c}]--").into(),
|
||||
Self::LambdaHead(arg) =>
|
||||
tl_cache!(Rc<Variants>: Rc::new(Variants::default().bounded("\\{0b}.")))
|
||||
.units([ttv_fmt(arg, c).await]),
|
||||
.units([arg.print(c).boxed_local().await]),
|
||||
Self::NS(n, b) => tl_cache!(Rc<Variants>: Rc::new(Variants::default().bounded("{0}::{1l}")))
|
||||
.units([n.to_string().into(), b.print(c).boxed_local().await]),
|
||||
Self::Name(n) => format!("{n}").into(),
|
||||
|
||||
Reference in New Issue
Block a user