Most files suffered major changes

- Less ambiguous syntax
- Better parser (Chumsky only does tokenization now)
- Tidy(|ier) error handling
- Facade for simplified embedding
- External code grouped in (fairly) self-contained Systems
- Dynamic action dispatch
- Many STL additions
This commit is contained in:
2023-08-17 20:47:08 +01:00
parent 751a02a1ec
commit 3fdabc29da
139 changed files with 4269 additions and 1783 deletions

View File

@@ -14,6 +14,7 @@ use crate::utils::{pushed, Substack};
/// A lightweight module tree that can be built declaratively by hand to
/// describe libraries of external functions in Rust. It implements [Add] for
/// added convenience
#[derive(Clone, Debug)]
pub enum ConstTree {
/// A function or constant
Const(Expr<VName>),
@@ -40,6 +41,29 @@ impl ConstTree {
pub fn tree(arr: impl IntoIterator<Item = (Tok<String>, Self)>) -> Self {
Self::Tree(arr.into_iter().collect())
}
/// Namespace the tree with the list of names
pub fn namespace(
pref: impl IntoIterator<Item = Tok<String>>,
data: Self,
) -> Self {
let mut iter = pref.into_iter();
if let Some(ns) = iter.next() {
Self::tree([(ns, Self::namespace(iter, data))])
} else {
data
}
}
/// Unwrap the table of subtrees from a tree
///
/// # Panics
///
/// If this is a leaf node aka. constant and not a namespace
pub fn unwrap_tree(self) -> HashMap<Tok<String>, Self> {
match self {
Self::Tree(map) => map,
_ => panic!("Attempted to unwrap leaf as tree"),
}
}
}
impl Add for ConstTree {
type Output = ConstTree;