Removed macro facets

Macros, placeholders, etc. will all be handled by std eventually so they shouldn't appear in the protocol or the host
This commit is contained in:
2024-08-22 18:05:57 +02:00
parent 3a63894de2
commit 84cbcdd4fe
37 changed files with 210 additions and 350 deletions

View File

@@ -2,9 +2,9 @@ use std::sync::Arc;
use itertools::Itertools;
use crate::api;
use crate::interner::{deintern, Tok};
use crate::location::Pos;
use crate::api;
/// A point of interest in resolving the error, such as the point where
/// processing got stuck, a command that is likely to be incorrect
@@ -90,4 +90,4 @@ pub fn mk_err(
pub trait Reporter {
fn report(&self, e: OrcErr);
}
}

View File

@@ -7,7 +7,7 @@ use std::{fmt, hash};
use hashbrown::{HashMap, HashSet};
use itertools::Itertools as _;
use orchid_api_traits::{Encode, Decode, Request};
use orchid_api_traits::{Decode, Encode, Request};
use crate::api;
use crate::reqnot::{DynRequester, Requester};
@@ -59,9 +59,7 @@ impl<T: Interned + Encode> Encode for Tok<T> {
fn encode<W: std::io::Write + ?Sized>(&self, write: &mut W) { self.data.encode(write) }
}
impl<T: Interned + Decode> Decode for Tok<T> {
fn decode<R: std::io::Read + ?Sized>(read: &mut R) -> Self {
intern(&T::decode(read))
}
fn decode<R: std::io::Read + ?Sized>(read: &mut R) -> Self { intern(&T::decode(read)) }
}
pub trait Interned: Eq + hash::Hash + Clone + Internable<Interned = Self> {

View File

@@ -13,4 +13,4 @@ pub fn recv_msg(read: &mut impl io::Read) -> io::Result<Vec<u8>> {
let mut msg = vec![0u8; len as usize];
read.read_exact(&mut msg)?;
Ok(msg)
}
}

View File

@@ -93,7 +93,7 @@ impl<T: NameIndex> Index<T> for PathSlice {
mod idx_impls {
use std::ops;
use super::{NameIndex, PathSlice, conv_range};
use super::{conv_range, NameIndex, PathSlice};
use crate::interner::Tok;
impl NameIndex for u16 {
@@ -146,7 +146,7 @@ pub fn conv_bound<T: Into<U> + Clone, U>(bound: Bound<&T>) -> Bound<U> {
}
}
pub fn conv_range<'a, T: Into<U> + Clone + 'a, U: 'a>(
range: impl RangeBounds<T>
range: impl RangeBounds<T>,
) -> (Bound<U>, Bound<U>) {
(conv_bound(range.start_bound()), conv_bound(range.end_bound()))
}

View File

@@ -143,16 +143,17 @@ pub fn expect_end(snip: Snippet<'_, '_, impl AtomInTok, impl Sized>) -> OrcRes<(
}
pub fn expect_tok<'a, 'b, A: AtomInTok, X: fmt::Display>(
snip: Snippet<'a, 'b, A, X>, tok: Tok<String>
snip: Snippet<'a, 'b, A, X>,
tok: Tok<String>,
) -> OrcRes<Snippet<'a, 'b, A, X>> {
let (head, tail) = try_pop_no_fluff(snip)?;
match &head.tok {
Token::Name(n) if *n == tok => Ok(tail),
t => Err(vec![mk_err(
intern!(str: "Expected specific keyword"),
intern!(str: "Expected specific keyword"),
format!("Expected {tok} but found {t}"),
[Pos::Range(head.range.clone()).into()]
)])
[Pos::Range(head.range.clone()).into()],
)]),
}
}
@@ -277,10 +278,10 @@ impl CompName {
#[cfg(test)]
mod test {
use never::Never;
use never::Never;
use super::Snippet;
use super::Snippet;
fn _covary_snip_a<'a, 'b>(x: Snippet<'static, 'b, Never, ()>) -> Snippet<'a, 'b, Never, ()> { x }
fn _covary_snip_b<'a, 'b>(x: Snippet<'a, 'static, Never, ()>) -> Snippet<'a, 'b, Never, ()> { x }
}
}

View File

@@ -14,7 +14,8 @@ pub struct ReplyToken;
trait_set! {
pub trait SendFn<T: MsgSet> = for<'a> FnMut(&'a [u8], ReqNot<T>) + DynClone + Send + 'static;
pub trait ReqFn<T: MsgSet> = FnMut(RequestHandle<T>) -> ReplyToken + DynClone + Send + Sync + 'static;
pub trait ReqFn<T: MsgSet> =
FnMut(RequestHandle<T>) -> ReplyToken + DynClone + Send + Sync + 'static;
pub trait NotifFn<T: MsgSet> =
for<'a> FnMut(<T::In as Channel>::Notif, ReqNot<T>) + DynClone + Send + Sync + 'static;
}

View File

@@ -1,34 +1,6 @@
use std::fmt::Display;
pub use api::Paren;
use crate::api;
use crate::interner::{deintern, Tok};
pub const PARENS: &[(char, char, Paren)] =
&[('(', ')', Paren::Round), ('[', ']', Paren::Square), ('{', '}', Paren::Curly)];
#[derive(Clone, Debug)]
pub struct OwnedPh {
pub name: Tok<String>,
pub kind: api::PlaceholderKind,
}
impl OwnedPh {
pub fn to_api(&self) -> api::Placeholder {
api::Placeholder { name: self.name.marker(), kind: self.kind.clone() }
}
pub fn from_api(ph: api::Placeholder) -> Self { Self { name: deintern(ph.name), kind: ph.kind } }
}
impl Display for OwnedPh {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.kind {
api::PlaceholderKind::Name => write!(f, "$_{}", self.name),
api::PlaceholderKind::Scalar => write!(f, "${}", self.name),
api::PlaceholderKind::Vector { nz: false, prio: 0 } => write!(f, "..${}", self.name),
api::PlaceholderKind::Vector { nz: true, prio: 0 } => write!(f, "...${}", self.name),
api::PlaceholderKind::Vector { nz: false, prio } => write!(f, "..${}:{prio}", self.name),
api::PlaceholderKind::Vector { nz: true, prio } => write!(f, "...${}:{prio}", self.name),
}
}
}

View File

@@ -12,9 +12,9 @@ use trait_set::trait_set;
use crate::api;
use crate::error::OrcErr;
use crate::interner::{deintern, intern, Tok};
use crate::interner::{deintern, Tok};
use crate::name::{NameLike, VName};
use crate::tokens::{OwnedPh, PARENS};
use crate::tokens::PARENS;
trait_set! {
pub trait RecurCB<'a, A: AtomInTok, X> = Fn(TokTree<'a, A, X>) -> TokTree<'a, A, X>;
@@ -27,7 +27,7 @@ pub fn recur<'a, A: AtomInTok, X>(
f(tt, &|TokTree { range, tok }| {
let tok = match tok {
tok @ (Token::Atom(_) | Token::BR | Token::Bottom(_) | Token::Comment(_) | Token::NS) => tok,
tok @ (Token::Name(_) | Token::Ph(_) | Token::Slot(_) | Token::X(_)) => tok,
tok @ (Token::Name(_) | Token::Slot(_) | Token::X(_)) => tok,
Token::LambdaHead(arg) =>
Token::LambdaHead(arg.into_iter().map(|tt| recur(tt, f)).collect_vec()),
Token::S(p, b) => Token::S(p, b.into_iter().map(|tt| recur(tt, f)).collect_vec()),
@@ -73,7 +73,6 @@ impl<'a, A: AtomInTok, X> TokTree<'a, A, X> {
api::Token::Bottom(e) => Token::Bottom(e.iter().map(OrcErr::from_api).collect()),
api::Token::Lambda(arg) => Token::LambdaHead(ttv_from_api(arg, ctx)),
api::Token::Name(name) => Token::Name(deintern(*name)),
api::Token::Ph(ph) => Token::Ph(OwnedPh::from_api(ph.clone())),
api::Token::S(par, b) => Token::S(par.clone(), ttv_from_api(b, ctx)),
api::Token::Comment(c) => Token::Comment(c.clone()),
api::Token::Slot(id) => Token::Slot(TreeHandle::new(*id)),
@@ -94,7 +93,6 @@ impl<'a, A: AtomInTok, X> TokTree<'a, A, X> {
Token::LambdaHead(arg) =>
api::Token::Lambda(arg.iter().map(|t| t.to_api(do_extra)).collect_vec()),
Token::Name(n) => api::Token::Name(n.marker()),
Token::Ph(ph) => api::Token::Ph(ph.to_api()),
Token::Slot(tt) => api::Token::Slot(tt.ticket()),
Token::S(p, b) => api::Token::S(p.clone(), b.iter().map(|t| t.to_api(do_extra)).collect()),
Token::X(x) => return do_extra(x, self.range.clone()),
@@ -146,35 +144,6 @@ pub fn wrap_tokv<'a, A: AtomInTok + 'a, X: 'a>(
}
}
pub fn ph(s: &str) -> OwnedPh {
match s.strip_prefix("..") {
Some(v_tail) => {
let (mid, priority) = match v_tail.split_once(':') {
Some((h, t)) => (h, t.parse().expect("priority not an u8")),
None => (v_tail, 0),
};
let (name, nonzero) = match mid.strip_prefix(".$") {
Some(name) => (name, true),
None => (mid.strip_prefix('$').expect("Invalid placeholder"), false),
};
if name.starts_with("_") {
panic!("Names starting with an underscore indicate a single-name scalar placeholder")
}
OwnedPh {
name: intern(name),
kind: api::PlaceholderKind::Vector { nz: nonzero, prio: priority },
}
},
None => match s.strip_prefix("$_") {
Some(name) => OwnedPh { name: intern(name), kind: api::PlaceholderKind::Name },
None => match s.strip_prefix("$") {
None => panic!("Invalid placeholder"),
Some(name) => OwnedPh { name: intern(name), kind: api::PlaceholderKind::Scalar },
},
},
}
}
pub use api::Paren;
#[derive(Clone, Debug)]
@@ -186,7 +155,6 @@ pub enum Token<'a, A: AtomInTok, X> {
BR,
S(Paren, Vec<TokTree<'a, A, X>>),
Atom(A),
Ph(OwnedPh),
Bottom(Vec<OrcErr>),
Slot(TreeHandle<'a>),
X(X),
@@ -218,7 +186,6 @@ impl<'a, A: AtomInTok + Display, X: Display> Display for Token<'a, A, X> {
Self::LambdaHead(arg) => with_indent(|| write!(f, "\\ {} .", ttv_fmt(arg))),
Self::NS => f.write_str("::"),
Self::Name(n) => f.write_str(n),
Self::Ph(ph) => write!(f, "{ph}"),
Self::Slot(th) => write!(f, "{th}"),
Self::S(p, b) => {
let (lp, rp, _) = PARENS.iter().find(|(_, _, par)| par == p).unwrap();