wip: reenable dynamic dispatch

This commit is contained in:
🪞👃🪞 2025-01-04 10:44:20 +01:00
parent 600d0b3aca
commit ac3827b8f3
11 changed files with 997 additions and 194 deletions

View file

@ -2,27 +2,6 @@ use std::sync::{Arc, RwLock};
use std::collections::BTreeMap;
pub use clojure_reader::edn::Edn;
#[cfg(test)] #[test] fn test_edn () -> Result<(), ParseError> {
use Item::*;
assert_eq!(Item::read_all("")?,
vec![]);
assert_eq!(Item::read_all(" ")?,
vec![]);
assert_eq!(Item::read_all("1234")?,
vec![Num(1234)]);
assert_eq!(Item::read_all("1234 5 67")?,
vec![Num(1234), Num(5), Num(67)]);
assert_eq!(Item::read_all("foo/bar")?,
vec![Key("foo/bar".into())]);
assert_eq!(Item::read_all(":symbol")?,
vec![Sym(":symbol".into())]);
assert_eq!(Item::read_all(" foo/bar :baz 456")?,
vec![Key("foo/bar".into()), Sym(":baz".into()), Num(456)]);
assert_eq!(Item::read_all(" (foo/bar :baz 456) ")?,
vec![Exp(vec![Key("foo/bar".into()), Sym(":baz".into()), Num(456)])]);
Ok(())
}
fn number (digits: &str) -> usize {
let mut value = 0;
for c in digits.chars() {
@ -44,15 +23,15 @@ pub enum ParseError {
}
#[derive(Debug, Clone, Default, PartialEq)]
pub enum Item {
pub enum Item<T: AsRef<str>> {
#[default] Nil,
Num(usize),
Sym(String),
Key(String),
Exp(Vec<Item>),
Sym(T),
Key(T),
Exp(Vec<Item<T>>),
}
impl Item {
impl Item<String> {
pub fn read_all <'a> (mut source: &'a str) -> Result<Vec<Self>, ParseError> {
let mut items = vec![];
loop {